Skip to content

Commit

Permalink
fix: fix config merging
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Feb 7, 2024
1 parent 50a3318 commit e1346da
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
20 changes: 14 additions & 6 deletions src/nostalgist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ export class Nostalgist {
private emulator: Emulator | undefined

private constructor(options: NostalgistLaunchOptions) {
const mergedOptions = { ...Nostalgist.globalOptions, ...options }
merge(mergedOptions, Nostalgist.globalOptions, options)
this.options = mergedOptions
const globalOptions = { ...Nostalgist.globalOptions }
const localOptions = { ...options }
const rom = globalOptions.rom || localOptions.rom
const bios = globalOptions.bios || localOptions.bios
const mergedOptions = { rom, bios }
delete globalOptions.rom
delete globalOptions.bios
delete localOptions.rom
delete localOptions.bios
merge(mergedOptions, globalOptions, localOptions)
this.options = mergedOptions as NostalgistOptions
}

/**
Expand Down Expand Up @@ -601,15 +609,15 @@ export class Nostalgist {
}

private getRetroarchOption() {
const options = { ...Nostalgist.globalOptions.retroarchConfig, ...this.options.retroarchConfig }
const options = {}
merge(options, Nostalgist.globalOptions.retroarchConfig, this.options.retroarchConfig)
return options as typeof this.options.retroarchConfig
}

private getRetroarchCoreOption() {
const options = { ...Nostalgist.globalOptions.retroarchCoreConfig, ...this.options.retroarchCoreConfig }
const options = {}
merge(options, Nostalgist.globalOptions.retroarchCoreConfig, this.options.retroarchCoreConfig)
return options
return options as typeof this.options.retroarchCoreConfig
}

private loadEmulator() {
Expand Down
32 changes: 29 additions & 3 deletions tests/integration/nostalgist.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('nostalgist', () => {
const nostalgist = await Nostalgist.launch({ rom: testNesRomUrl, core })

const options = nostalgist.getOptions()
expect(options.core).toBe(core)
expect(options.core).toStrictEqual(core)

const emulatorOptions = nostalgist.getEmulatorOptions()
expect(emulatorOptions.core.name).toBe('fceumm')
Expand All @@ -136,7 +136,7 @@ describe('nostalgist', () => {
const nostalgist = await Nostalgist.launch({ rom, core, resolveRom })

const options = nostalgist.getOptions()
expect(options.core).toBe(core)
expect(options.core).toStrictEqual(core)

const emulatorOptions = nostalgist.getEmulatorOptions()
expect(emulatorOptions.core.name).toBe('fceumm')
Expand All @@ -160,7 +160,7 @@ describe('nostalgist', () => {
const nostalgist = await Nostalgist.launch({ core, rom, bios, resolveRom, resolveBios })

const options = nostalgist.getOptions()
expect(options.core).toBe(core)
expect(options.core).toStrictEqual(core)

const emulatorOptions = nostalgist.getEmulatorOptions()
expect(emulatorOptions.core.name).toBe('fceumm')
Expand Down Expand Up @@ -228,4 +228,30 @@ describe('nostalgist', () => {
input_audio_mute: 'b',
})
})

test('Nostalgist.launch overwrites the configured core', async () => {
Nostalgist.configure({ core: 'nestopia' })
const core = {
name: 'fceumm',
js: 'https://web.libretro.com/fceumm_libretro.js',
wasm: 'https://web.libretro.com/fceumm_libretro.wasm',
}
const nostalgist = await Nostalgist.launch({ core, rom: testNesRomUrl })

const options = nostalgist.getOptions()
expect(options.core).toStrictEqual(core)
})

test('Nostalgist.launch overwrites the configured custom emscripten core', async () => {
const core = {
name: 'fceumm',
js: 'https://web.libretro.com/fceumm_libretro.js',
wasm: 'https://web.libretro.com/fceumm_libretro.wasm',
}
Nostalgist.configure({ core })
const nostalgist = await Nostalgist.launch({ core: 'nestopia', rom: testNesRomUrl })

const options = nostalgist.getOptions()
expect(options.core).toStrictEqual('nestopia')
})
})

0 comments on commit e1346da

Please sign in to comment.