mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 14:16:28 +03:00
67 lines
2.7 KiB
JavaScript
67 lines
2.7 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import path from 'node:path';
|
|
import {
|
|
assembleLiveBrowserScript,
|
|
assertLiveBrowserScriptParts,
|
|
readLiveBrowserScriptParts,
|
|
resolveLiveBrowserScriptParts,
|
|
} from '../skill/scripts/live/browser-script-parts.mjs';
|
|
|
|
describe('live browser script parts', () => {
|
|
it('resolves the canonical browser script order', () => {
|
|
const parts = resolveLiveBrowserScriptParts('/repo/skill/scripts');
|
|
|
|
assert.deepEqual(parts.map((part) => part.name), ['session-state', 'browser-ui']);
|
|
assert.equal(parts[0].file, 'live-browser-session.js');
|
|
assert.equal(parts[1].file, 'live-browser.js');
|
|
assert.equal(parts[0].path, path.join('/repo/skill/scripts', 'live-browser-session.js'));
|
|
assert.equal(parts[1].path, path.join('/repo/skill/scripts', 'live-browser.js'));
|
|
});
|
|
|
|
it('asserts missing script parts by name', () => {
|
|
const parts = resolveLiveBrowserScriptParts('/repo/skill/scripts');
|
|
|
|
assert.throws(
|
|
() => assertLiveBrowserScriptParts(parts, (filePath) => !filePath.endsWith('live-browser.js')),
|
|
/Live browser script part missing: browser-ui/,
|
|
);
|
|
});
|
|
|
|
it('reads each part with an injected reader', () => {
|
|
const parts = resolveLiveBrowserScriptParts('/repo/skill/scripts');
|
|
const loaded = readLiveBrowserScriptParts(parts, (filePath) => `source:${path.basename(filePath)}`);
|
|
|
|
assert.deepEqual(loaded.map((part) => part.source), [
|
|
'source:live-browser-session.js',
|
|
'source:live-browser.js',
|
|
]);
|
|
});
|
|
|
|
it('assembles prelude, session helper, and browser UI in order', () => {
|
|
const script = assembleLiveBrowserScript({
|
|
token: 'token-a',
|
|
port: 8421,
|
|
vocabulary: [{ value: 'shape', label: 'Shape' }],
|
|
parts: [
|
|
{ name: 'session-state', file: 'live-browser-session.js', source: 'window.__SESSION_PART__ = true;' },
|
|
{ name: 'browser-ui', file: 'live-browser.js', source: 'window.__BROWSER_PART__ = true;' },
|
|
],
|
|
});
|
|
|
|
const tokenIndex = script.indexOf('window.__IMPECCABLE_TOKEN__');
|
|
const portIndex = script.indexOf('window.__IMPECCABLE_PORT__');
|
|
const vocabIndex = script.indexOf('window.__IMPECCABLE_VOCAB__');
|
|
const sessionIndex = script.indexOf('window.__SESSION_PART__');
|
|
const browserIndex = script.indexOf('window.__BROWSER_PART__');
|
|
|
|
assert.ok(tokenIndex !== -1);
|
|
assert.ok(tokenIndex < portIndex);
|
|
assert.ok(portIndex < vocabIndex);
|
|
assert.ok(vocabIndex < sessionIndex);
|
|
assert.ok(sessionIndex < browserIndex);
|
|
assert.match(script, /impeccable live script part: session-state \(live-browser-session\.js\)/);
|
|
assert.match(script, /impeccable live script part: browser-ui \(live-browser\.js\)/);
|
|
});
|
|
});
|