一键导入
backend-tests
Guide for writing AssemblyScript backend tests in assembly/tests/ — patterns, helpers, ROM setup, and wiring
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for writing AssemblyScript backend tests in assembly/tests/ — patterns, helpers, ROM setup, and wiring
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Prime context for working on the Svelte 5 frontend in /src/ — components, stores, WASM bridge, audio, canvas rendering
Profile-driven performance optimization for SvelteBoy AssemblyScript/WASM backend. Use when asked to optimize emulator performance, profile hotspots, or reduce CPU usage.
Prime context for working on the SvelteBoy APU — architecture, channel implementations, register layout, event queue, render pipeline, and test patterns
Prime context for working on the AssemblyScript/WASM GameBoy emulator backend in /assembly/
Complete Game Boy DMG hardware reference — all registers, timing, opcodes, PPU modes, APU circuits, MBC banking. Authoritative inline spec for emulator implementation.
Prime context for architectural discussions about SvelteBoy's design patterns, component interactions, timing model, and trade-offs vs. general emulator approaches
| name | backend-tests |
| description | Guide for writing AssemblyScript backend tests in assembly/tests/ — patterns, helpers, ROM setup, and wiring |
| argument-hint | optional: what you're testing, e.g. timer, interrupt, new opcode |
Always consult Pan Docs (pandocs/src/, via gameboy-docs skill) for expected flag effects, cycle counts, and register behavior. Never guess hardware behavior.
assembly/tests/framework.ts ← assert helpers
assembly/tests/cpuTests.ts ← setTestRom, register lambdas
assembly/tests/instructions/ ← per-opcode suites → index.ts → testInstructions()
assembly/tests/<feature>Tests.ts ← other suites
assembly/index.ts ← re-export all test functions
tests/index.js ← JS harness
Each suite exports one testXxx(): boolean. Uses describe/it blocks. Returns true; a failed assert aborts immediately.
the js harness calls all test functions based on name (starts with 'test'), reports pass/fail, and tracks opcode coverage via setTestRom.
assembly/tests/framework.ts)describe(name, fn), beforeEach(fn), it(name, fn)
assertEquals<T>(actual, expected, label)
assertReg(actual: u8, expected: u8, name)
assertMem(addr: u16, expected: u8) // GBload check
assertFlags(z, n, h, c: bool) // all four flags
assertCycles(expected: u64) // Cpu.CycleCount since last setTestRom
ctx() // "[suite › case] " for manual asserts
import { setTestRom } from "../cpuTests"; // or "./cpuTests" from tests/ root
setTestRom([0x04]); // resets emulator, tracks opcode coverage, Emulator.Init(true)
setTestRom([0xCB, 0x40]); // prefixed
Register lambda helpers from cpuTests.ts: BC, DE, HL, SP, SetBC, SetDE, SetHL, SetSP.
Cpu.Tick(); // CPU only — use for opcode tests
Emulator.Tick(); // CPU + Timer + PPU + DMA — use when timing/interrupts matter
// Read: Cpu.A()…Cpu.L(), Cpu.F(), Cpu.AF/BC/DE/HL (fields), Cpu.ProgramCounter, Cpu.StackPointer, Cpu.CycleCount
// Write: Cpu.SetA(v)…, Cpu.AF=v…, Cpu.SetF(flags), Cpu.SetFlag(Flag.Z_Zero)
// Flags: Cpu.FlagZ(), Cpu.FlagN(), Cpu.FlagH(), Cpu.FlagC()
MemoryMap.GBstore<u8>(addr, val); MemoryMap.GBload<u8>(addr); // through MMU
store<u8>(ptr, val); load<u8>(ptr); memory.copy/fill(…); // raw WASM (rare)
Use 0xFF82 as scratch HRAM in tests.
memory.fill(CARTRIDGE_ROM_START, 0, 0x100);
memory.copy(CARTRIDGE_ROM_START + 0x100, instructions.dataStart, instructions.length);
MemoryMap.loadedCartridgeRomSize = instructions.length;
Emulator.Init(false);
// guard runaway: assert(i < 10000, "Runaway") inside loop
assembly/tests/myFeatureTests.ts — export testMyFeature(): booleanassembly/index.ts — export { testMyFeature } from "./tests/myFeatureTests"tests/index.js — call it following existing patternpnpm run asbuild:debug && pnpm testNew instruction suites go in assembly/tests/instructions/, imported in index.ts → called from testInstructions() (already wired).
setTestRom resets all state. Cartridge-mode tests call Emulator.Init(false) manually.Cpu.Tick() doesn't advance Timer/PPU. Use Emulator.Tick() for timing-sensitive tests.assertCycles will catch mismatches.$ARGUMENTS