Make synthetic browser checks independent of private files and timing (#45)
Checks / web (push) Successful in 2m0s
Checks / web (push) Successful in 2m0s
This commit is contained in:
1 parent
ad68ca87ce
commit
a33ffa3a15
2 files changed
+26
-12
No files matched your search
@@ -90,11 +90,9 @@ test("actual WASM executes an original cartridge, reads input and round-trips st
|
|||||||
const emulator = new BinjgbEmulator((error) => {
|
const emulator = new BinjgbEmulator((error) => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
const wait = () => new Promise((resolve) => setTimeout(resolve, 180));
|
|
||||||
await emulator.load(new Uint8Array(bytes), canvas);
|
await emulator.load(new Uint8Array(bytes), canvas);
|
||||||
emulator.play();
|
// Advance emulated frames independently of the CI browser's animation rate.
|
||||||
await wait();
|
emulator.advanceFrames(12);
|
||||||
emulator.pause();
|
|
||||||
const before = emulator.exportBattery();
|
const before = emulator.exportBattery();
|
||||||
const state = emulator.captureState();
|
const state = emulator.captureState();
|
||||||
const pixels = canvas.getContext("2d")!.getImageData(0, 0, 160, 144).data;
|
const pixels = canvas.getContext("2d")!.getImageData(0, 0, 160, 144).data;
|
||||||
@@ -102,9 +100,7 @@ test("actual WASM executes an original cartridge, reads input and round-trips st
|
|||||||
for (let i = 0; i < pixels.length; i += 4)
|
for (let i = 0; i < pixels.length; i += 4)
|
||||||
colors.add(`${pixels[i]},${pixels[i + 1]},${pixels[i + 2]}`);
|
colors.add(`${pixels[i]},${pixels[i + 1]},${pixels[i + 2]}`);
|
||||||
emulator.setButton("a", true);
|
emulator.setButton("a", true);
|
||||||
emulator.play();
|
emulator.advanceFrames(12);
|
||||||
await wait();
|
|
||||||
emulator.pause();
|
|
||||||
const pressed = emulator.exportBattery()[0];
|
const pressed = emulator.exportBattery()[0];
|
||||||
emulator.restoreState(state);
|
emulator.restoreState(state);
|
||||||
const restored = emulator.exportBattery()[0];
|
const restored = emulator.exportBattery()[0];
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "@playwright/test";
|
||||||
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
import {
|
||||||
|
existsSync,
|
||||||
|
mkdirSync,
|
||||||
|
mkdtempSync,
|
||||||
|
readFileSync,
|
||||||
|
rmSync,
|
||||||
|
writeFileSync,
|
||||||
|
} from "node:fs";
|
||||||
import { createHash } from "node:crypto";
|
import { createHash } from "node:crypto";
|
||||||
import { resolve } from "node:path";
|
import { basename, join, resolve } from "node:path";
|
||||||
import { CrystalAssets } from "../src/game/rom/assets";
|
import { CrystalAssets } from "../src/game/rom/assets";
|
||||||
import { generatePartyMon } from "../src/game/party/pokemon";
|
import { generatePartyMon } from "../src/game/party/pokemon";
|
||||||
import { GameWorld } from "../src/game/world/world";
|
import { GameWorld } from "../src/game/world/world";
|
||||||
@@ -420,12 +427,23 @@ test("walks from New Bark Town onto Route 29 after receiving a starter", async (
|
|||||||
test("development server does not serve ROMs or the private reference checkout", async ({
|
test("development server does not serve ROMs or the private reference checkout", async ({
|
||||||
request,
|
request,
|
||||||
}) => {
|
}) => {
|
||||||
|
// Missing paths can return Vite's HTML fallback. Exercise real files using
|
||||||
|
// disposable synthetic content, without depending on a private checkout.
|
||||||
|
const directory = mkdtempSync(resolve(".ci-private-"));
|
||||||
|
try {
|
||||||
|
mkdirSync(join(directory, ".reference"));
|
||||||
|
for (const file of ["fixture.gbc", ".reference/README.md"]) {
|
||||||
|
writeFileSync(join(directory, file), "Synthetic private-file test fixture");
|
||||||
for (const path of [
|
for (const path of [
|
||||||
"/Pokemon%20-%20Crystal%20Version%20(UE)%20(V1.1)%20%5BC%5D%5B!%5D.gbc",
|
`/${basename(directory)}/${file}`,
|
||||||
"/.reference/pokecrystal/README.md",
|
`/@fs/${join(directory, file)}`,
|
||||||
]) {
|
]) {
|
||||||
const response = await request.get(path);
|
const response = await request.get(path);
|
||||||
expect([403, 404]).toContain(response.status());
|
expect(response.status(), path).toBe(403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
rmSync(directory, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user