Skip to content

Commit

Permalink
test: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arianrhodsandlot committed Jan 29, 2025
1 parent edc1c30 commit 985bdbf
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/src/content/docs/apis/resolvable-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ Each resolvable file has an internal `name` property, which will be inferred aut
+ If it's a `File` object, the `name` property will be inferred as the `name` of the resolvable file.
+ If it's an object with a `fileName` property and a `fileContent` property is passed as the resolvable file, the `fileName` property will be used as its name.

This property is required when using the file as a [`rom`](/apis/launch#rom) or [`bios`](/apis/launch#bios) passed to [`Nostalgist.launch`](/apis/launch).
This property is required when using the file as a [`bios`](/apis/launch#bios) passed to [`Nostalgist.launch`](/apis/launch) or files returned by [`resolveBios`](/apis/launch#resolvebios) and [`resolveShader`](/apis/launch#resolveshader).
75 changes: 69 additions & 6 deletions playground/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ let nostalgist: Nostalgist_
let state: { state: Blob }
let sram: Blob

const cdnBaseUrl = 'https://cdn.jsdelivr.net/gh'
const useLegacyCore = location.search.includes('legacy')
const coreRepo = 'arianrhodsandlot/retroarch-emscripten-build'
const nesRomRepo = 'retrobrews/nes-games'
const coreVersion = useLegacyCore ? 'v1.16.0' : 'v1.20.0'
const coreDirectory = 'retroarch'

const handlers = {
static: {
async nes() {
Expand Down Expand Up @@ -72,6 +79,63 @@ const handlers = {
async launchROMSupportsSRAM() {
nostalgist = await Nostalgist.nes({ rom: testSRAMRomUrl })
},

async launchURLStrings() {
nostalgist = await Nostalgist.launch({
core: 'fceumm',
resolveCoreJs: (core) => `${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.js`,
resolveCoreWasm: (core) => `${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.wasm`,
resolveRom: (rom) => `${cdnBaseUrl}/${nesRomRepo}@master/${rom}`,
rom: 'pong1k.nes',
})
},

async launchURLs() {
nostalgist = await Nostalgist.launch({
core: 'fceumm',
resolveCoreJs: (core) =>
new URL(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.js`),
resolveCoreWasm: (core) =>
new URL(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.wasm`),
resolveRom: (rom) => new URL(`${cdnBaseUrl}/${nesRomRepo}@master/${rom}`),
rom: 'pong1k.nes',
})
},

async launchRequests() {
nostalgist = await Nostalgist.launch({
core: 'fceumm',
resolveCoreJs: (core) =>
new Request(new URL(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.js`)),
resolveCoreWasm: (core) =>
new Request(new URL(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.wasm`)),
resolveRom: (rom) => new Request(new URL(`${cdnBaseUrl}/${nesRomRepo}@master/${rom}`)),
rom: 'pong1k.nes',
})
},

async launchResponses() {
nostalgist = await Nostalgist.launch({
core: 'fceumm',
resolveCoreJs: (core) => fetch(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.js`),
resolveCoreWasm: (core) =>
fetch(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.wasm`),
resolveRom: (rom) => fetch(`${cdnBaseUrl}/${nesRomRepo}@master/${rom}`),
rom: 'pong1k.nes',
})
},

async launchArrayBuffers() {
nostalgist = await Nostalgist.launch({
core: 'fceumm',
resolveCoreJs: (core) =>
fetchArrayBuffer(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.js`),
resolveCoreWasm: (core) =>
fetchArrayBuffer(`${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.wasm`),
resolveRom: (rom) => fetchArrayBuffer(`${cdnBaseUrl}/${nesRomRepo}@master/${rom}`),
rom: 'pong1k.nes',
})
},
},

instance: {
Expand Down Expand Up @@ -135,6 +199,11 @@ const handlers = {
},
}

async function fetchArrayBuffer(input) {
const response = await fetch(input)
return await response.arrayBuffer()
}

function renderButtons() {
const [staticTitle, instanceTitle] = document.querySelectorAll('h3')
staticTitle.insertAdjacentHTML(
Expand Down Expand Up @@ -165,12 +234,6 @@ export function activate(mod: typeof Nostalgist_) {
}

if (location.search.includes('legacy')) {
const cdnBaseUrl = 'https://cdn.jsdelivr.net/gh'

const coreRepo = 'arianrhodsandlot/retroarch-emscripten-build'
const coreVersion = 'v1.16.0'
const coreDirectory = 'retroarch'

Object.assign(nostalgistConfig, {
resolveCoreJs(core) {
return `${cdnBaseUrl}/${coreRepo}@${coreVersion}/${coreDirectory}/${core}_libretro.js`
Expand Down
6 changes: 6 additions & 0 deletions playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
margin: 32px auto 0 auto;
}

div {
max-width: 1280px;
width: 96%;
margin: auto;
}

h3 {
margin: 10px auto;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions tests/e2e/static.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ function tests() {
await page.waitForTimeout(500)
await expect(canvas).toHaveScreenshot('launch-sram.png')
})

test('launch with resolvable files', async ({ page }) => {
const canvas = page.locator('#canvas')
await expect(canvas).not.toBeAttached()

const buttons = ['launchURLStrings', 'launchURLs', 'launchRequests', 'launchResponses', 'launchArrayBuffers']
for (const button of buttons) {
await page.getByText(button, { exact: true }).click()
await page.waitForLoadState('networkidle')
await page.waitForTimeout(1000)
await expect(canvas).toHaveScreenshot('launch-nes.png')

await page.getByText('exit', { exact: true }).click()
await expect(canvas).not.toBeAttached()
}
})
}

test.describe('static methods with retroarch esm', () => {
Expand Down

0 comments on commit 985bdbf

Please sign in to comment.