Files
moli/moli-protocol-server/tests/fixtures/auxiliary-module-completion.js
ldm0 804223799d test(modules): cover CSS imports in unattached auxiliary Pages
Extend the opener-only popup completion regression to CSS synthetic modules alongside the existing JavaScript graphs and JSON. Exercise both initial about:blank and committed popup Documents without attaching a frontend to the auxiliary target, verify CSSStyleSheet identity and its rule, and assert both CSS requests reach the fixture. Preserve main's rejection of unsupported text module types.

Extracted from development commit 54189266c08bd7f23eb750d8b4a4f43566b0f2ae.
Base: main (b30f39c580).

Validation (32 build jobs and test threads): cargo fmt --all; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo nextest run --no-fail-fast.
     Summary [ 146.470s] 22169 tests run: 22169 passed (9 slow), 20 skipped
2026-11-02 22:29:28 +08:00

48 lines
2.2 KiB
JavaScript

function startAuxiliaryModuleProbe(base, mode) {
globalThis.auxiliaryModuleResult = {done: false};
(async () => {
const popup = open(mode === 'blank' ? 'about:blank' : base + '/popup-' + mode);
const originalFunction = popup.Function;
try {
if (mode !== 'blank') {
await new Promise(resolve => popup.addEventListener('load', resolve, {once: true}));
}
const retainedWindow = popup.Function === originalFunction;
const checks = await popup.Function('base', 'mode', `
return (async () => {
const checks = [];
const check = (name, value) => {
if (!value) throw Error(name);
checks.push(name);
};
check('parser', mode === 'blank' || globalThis.parserModuleAnswer === 42);
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.type = 'module';
script.src = base + '/runtime.js';
script.onload = resolve;
script.onerror = () => reject(Error('runtime module failed'));
document.body.appendChild(script);
});
check('runtime', globalThis.runtimeModuleAnswer === 42);
check('javascript', (await import(base + '/module.js')).default === 42);
check('graph', (await import(base + '/graph.js')).default === 42);
check('json', (await import(base + '/module.json', {with: {type: 'json'}})).default.answer === 42);
const sheet = (await import(base + '/module.css', {with: {type: 'css'}})).default;
check('css', sheet instanceof CSSStyleSheet && sheet.cssRules[0].style.color === 'green');
let failure;
try { await import(base + '/missing.js'); } catch (error) { failure = error; }
check('fetch-error', failure instanceof TypeError);
return checks;
})();
`)(base, mode);
return {retainedWindow, checks};
} finally {
popup.close();
}
})().then(
value => { globalThis.auxiliaryModuleResult = {done: true, ...value}; },
error => { globalThis.auxiliaryModuleResult = {done: true, error: String(error.stack || error)}; }
);
}