42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
// Test bootstrap (run via `node --import ./setup.mjs --test ...`):
|
|
// - installs the resolve hook that stubs "/scripts/app.js"
|
|
// - shims the few browser globals the DOM-free model touches
|
|
// (window, CustomEvent, requestAnimationFrame).
|
|
import { register } from 'node:module';
|
|
|
|
register('./hooks.mjs', import.meta.url);
|
|
|
|
globalThis.window = globalThis;
|
|
|
|
if (typeof globalThis.document === 'undefined') {
|
|
const headChildren = [];
|
|
globalThis.document = {
|
|
head: {
|
|
querySelector(selector) {
|
|
const id = selector.startsWith('#') ? selector.slice(1) : null;
|
|
return id ? headChildren.find((item) => item.id === id) ?? null : null;
|
|
},
|
|
appendChild(item) { headChildren.push(item); },
|
|
},
|
|
createElement(tagName) {
|
|
return { tagName: String(tagName).toUpperCase(), id: '', textContent: '' };
|
|
},
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.CustomEvent === 'undefined') {
|
|
globalThis.CustomEvent = class CustomEvent extends Event {
|
|
constructor(type, opts = {}) {
|
|
super(type, opts);
|
|
this.detail = opts ? opts.detail : undefined;
|
|
}
|
|
};
|
|
}
|
|
|
|
if (typeof globalThis.requestAnimationFrame === 'undefined') {
|
|
// Tests drive _tick(ts) manually, so rAF need only be a no-op the
|
|
// model's play()/loop can call without throwing.
|
|
globalThis.requestAnimationFrame = () => 0;
|
|
globalThis.cancelAnimationFrame = () => {};
|
|
}
|