memlnaut-nisps/tests/e2e/helpers.js
w1n5t0n 44fc974425 feat(tests): add Playwright e2e suite + debug probe for a-immersive
- Add window.__nisps debug probe (gated on ?debug=1) exposing iml state,
  getOutputs/getLoss/getWeights/getExampleCount, and action triggers
  (thumbsUp/thumbsDown/train/randomise/clearExamples/saveState)
- Fix WasmIML bug: this.dataset was a plain object; import Dataset and
  use new Dataset(100) so computeWeights() is available for training
- Fix WasmIML.addExample/clearDataset to use Dataset API methods
- 44 Playwright e2e tests across 4 spec files:
  - ml-engine.spec.js: WASM inference bounds, training loss, thumbs
    up/down behavior, async training, example capture semantics
  - ui-interactions.spec.js: drawer open/close, mode switching,
    heatmap bar counts, preset chips, keyboard shortcuts (1/2/Z)
  - input-pipeline.spec.js: input→output variation, clamping, joystick
    drag, post-training output bounds across the full input space
  - persistence.spec.js: URL params (?preset, ?spread), localStorage
    round-trip, saveState probe
2026-04-03 16:38:04 +01:00

32 lines
1.1 KiB
JavaScript

/**
* Shared helpers for e2e tests.
*/
const { expect } = require('@playwright/test');
/**
* Navigate to a-immersive with ?debug=1 and wait for the WASM engine to
* initialise and expose window.__nisps.
*
* @param {import('@playwright/test').Page} page
* @param {string} extraParams - additional query string, e.g. '&preset=beginner-1'
*/
async function loadApp(page, extraParams = '') {
// Clear app state but mark help as seen so the overlay doesn't block clicks.
await page.addInitScript(() => {
localStorage.removeItem('nisps-a-immersive');
localStorage.setItem('nisps-help-seen', '1');
});
await page.goto(`/a-immersive.html?debug=1${extraParams}`);
// Wait until the debug probe is ready (WASM init is async).
await page.waitForFunction(() => window.__nisps !== undefined, { timeout: 20_000 });
}
/**
* Returns the current text content of the status line.
* @param {import('@playwright/test').Page} page
*/
async function statusText(page) {
return page.locator('#status-text').textContent();
}
module.exports = { loadApp, statusText };