Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ these entries stays in the GitHub releases and the Git history.
- The test helpers, `webfront_add_jasmine_test` included, export the real `XDG_DATA_HOME` and `XDG_CACHE_HOME` as `WEBFRONT_TEST_REAL_XDG_DATA_HOME` and `WEBFRONT_TEST_REAL_XDG_CACHE_HOME`, so an application under test can keep the throwaway WebKitGTK profile away from the programs it starts ([#664](https://github.com/ambroise-leclerc/WebFront/issues/664), `docs/CONSUMER_TESTING.md`).

### Changed
- `wf test` stopped at its time limit or by Ctrl+C says how far its runner got, in its message and in the report's new `stage`: the last step reached, the spec in progress, and the runner files that never finished loading (#690, `docs/DEVELOPER_ENVIRONMENT.md`).
- Destroying the handle of a watch (`inspect::Watch`) waits for an operation of the inspectors in progress on another thread: destroy it outside every lock its source takes, or declare the watch with the state it owns (#682, ADR-027, `docs/WATCHES.md`).
- `cppFunction` and `Space::cppFunction` take a last, defaulted `std::source_location`, which the inspectors show; existing calls compile unchanged, the explicit `cppFunction<R, Args...>` form included (#681, ADR-027).
- Document the security contract of the application's callbacks: one that writes the project or what the server serves, starts a process or exposes a sensitive state takes the calling `UI` and checks `ui.isLocalClient()`, since WebFront guards only its own functions (#686, ADR-027, `docs/DEVELOPING_WITH_AGENTS.md`).
Expand Down
6 changes: 6 additions & 0 deletions docs/DEVELOPER_ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,12 @@ The result sent to C++ is cut to 60,000 bytes when it is larger (a bridge string
The report is structured: `{status, exitCode, total, passed, failed, pending, excluded, durationMs, jasmine, failures:
[{name, messages: [{message, stack}]}], pendingSpecs, suites, global, incomplete}`, bounded (100 failures, 8 messages of 16 KiB
each per spec). `status` is `passed`, `failed`, `incomplete`, `error` (the specs did not load), `timeout` or `interrupted`.
A run stopped at the time limit or by Ctrl+C once its frame was in the page also has `stage: {reached, specs, current, suite,
loaded, missing}`, which its message repeats: the last step the runner reached (`page requested` when it never started,
`runner started`, `bridge settled`, `specs loaded`, `specs running`, `between specs` in a suite's hook or after a spec),
the specs it finished, the spec in progress or the innermost suite whose hooks run, and
the runner's files (`index.html`, `specs.css`, `WebFront.js`, `jasmine.js`, `runner.js`, `specs.js`) whose response the
frame received in full or not: a file that is missing was never requested or never completely received.

### Without a terminal

Expand Down
2 changes: 1 addition & 1 deletion js/developer/environment/bundles.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"js/developer/environment/runtime.mjs": "1b5f0bfc5964b902725a4c765d83db0644cdad91a8f07d8bf6a3bbd0f550c1eb",
"js/developer/environment/automation.mjs": "773dcca7b8847c11670995f759c218c86af95a29ea46b44f350f79c4b71a143c",
"js/developer/environment/development.mjs": "1f32f911610c72ad3e935de1c2b138fa275ce9eda04bb63c824d5e09923305a6",
"js/developer/environment/testing.mjs": "aeb584505fab5957b9c02e78536e12f7d7f3d12f8adb2e17f1a1a6e395e43f3c",
"js/developer/environment/testing.mjs": "48695dc7c368d5f0671a0549a61d06c732e10604c56e98f7254f3c4dd21a792c",
"js/developer/environment/terminal.mjs": "e7c3ca8f9833f10e07939277996eb01fb989c986420c96052271ff469fa59062",
"js/developer/environment/workspace.mjs": "e82ec4df21ffb2b112550e0212504aba05af4f924b5645c0712f40f8466257fc",
"js/developer/environment/menu.mjs": "b4fe4c38e6b8cc6c1101df842e282ab85e6c6e029b2225738b9d27bc5efbc88d",
Expand Down
89 changes: 83 additions & 6 deletions js/developer/environment/testing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,32 @@ function boot() {
for (const name in members) globalThis[name] = members[name];
}
try {
post({type: 'stage', stage: 'runner started'});
try { await webFront.ready; } catch { /* the specs that need the bridge fail on their own */ }
post({type: 'stage', stage: 'bridge settled'});
boot();
const env = jasmine.getEnv();
env.configure({random: false, specFilter: spec => spec.getFullName().includes(pattern)});
// The suites entered, innermost last: outside a spec, the run is in the hooks of the innermost one (beforeAll, afterAll).
const open = [];
const between = () => post({type: 'stage', stage: 'between specs', suite: open.at(-1) ?? ''});
env.addReporter({
suiteStarted(result) {
open.push(clip(result.fullName, 256));
between();
},
specStarted(result) {
post({type: 'stage', stage: 'specs running', spec: clip(result.fullName, 256), suite: open.at(-1) ?? ''});
},
specDone(result) {
specs.push({name: clip(result.fullName, 1024), status: result.status, reason: clip(result.pendingReason, 1024),
failures: problems(result.failedExpectations)});
post({type: 'spec', status: result.status});
between();
},
suiteDone(result) {
open.pop();
between();
// An afterAll that throws is reported here, not by any spec.
if (result.failedExpectations?.length) suites.push({name: clip(result.fullName, 1024), failures: problems(result.failedExpectations)});
},
Expand All @@ -80,6 +95,7 @@ try {
},
});
await import('./specs.js');
post({type: 'stage', stage: 'specs loaded'});
await env.execute();
} catch (error) {
// WebKit's stack lacks the message, so it is always put first.
Expand Down Expand Up @@ -158,11 +174,58 @@ export function abortable(promise, signal) {
});
}

export const stoppedRun = (reason, pattern) => {
const [message, exitCode] = reason === 'timeout' ? ['Tests stopped at their time limit', 124] : ['Tests stopped by Ctrl+C', 130];
return Object.assign(new ScriptExit(message, exitCode), {report: emptyReport(reason, exitCode, {pattern, error: message})});
/**
* A run stopped before its report: 'timeout' (124) or 'interrupted' (130). `stage`, when the runner frame was started,
* says how far it got (frameStage) and is added to the message and to the report.
*/
export const stoppedRun = (reason, pattern, stage) => {
const [stopped, exitCode] = reason === 'timeout' ? ['Tests stopped at their time limit', 124] : ['Tests stopped by Ctrl+C', 130];
const message = stage ? `${stopped} (${describeStage(stage)})` : stopped;
return Object.assign(new ScriptExit(message, exitCode), {report: emptyReport(reason, exitCode, {pattern, error: message, ...(stage ? {stage} : {})})});
};

/** The files of the runner, in the order the page loads them; specs.css only when the specs built one. */
export const runnerResources = ['index.html', 'specs.css', 'WebFront.js', 'jasmine.js', 'runner.js', 'specs.js'];

/**
* How far the runner frame got, for a run stopped before its report (#690): `reached` is the last stage the runner
* posted ('page requested' when it posted none: it did not start; 'between specs' after a spec finished, in a suite's
* hook or before the next spec), `specs` the specs it finished, `current` the spec in progress (the one that hangs when
* the stage is 'specs running'), `suite` the innermost suite entered (whose beforeAll or afterAll hangs when the stage is
* 'between specs'), `loaded` the runner's
* files whose response the frame received completely, and `missing` those it did not (never requested, or a response
* still incomplete). A frame that cannot be read leaves both lists empty.
*/
export function frameStage(frameWindow, {reached = 'page requested', specs = 0, current = '', suite = '', resources = runnerResources} = {}) {
let loaded = [];
let missing = [];
try {
const names = new Set();
const entries = [...frameWindow.performance.getEntriesByType('navigation'), ...frameWindow.performance.getEntriesByType('resource')];
for (const entry of entries) {
if (!(entry.responseEnd > 0)) continue;
const file = new URL(entry.name).pathname.split('/').at(-1);
names.add(file === '' ? 'index.html' : file);
}
// The page links specs.css only when the specs built one: unknown while the page itself did not load.
const styled = names.has('specs.css') || Boolean(frameWindow.document.querySelector('link[href="./specs.css"]'));
const expected = resources.filter(file => file !== 'specs.css' || styled);
loaded = expected.filter(file => names.has(file));
missing = expected.filter(file => !names.has(file));
} catch { /* a frame that navigated away or was never attached: only the stage is known */ }
return {reached, specs, current, suite, loaded, missing};
}

/** The stage of a stopped run in words: "stage: specs running, 3 specs done, in suite spec" or "stage: page requested; not loaded: runner.js, specs.js". */
export function describeStage({reached, specs, current, suite, missing}) {
const parts = [`stage: ${reached}`];
if (specs) parts[0] += `, ${plural(specs, 'spec')} done`;
if (current && reached === 'specs running') parts[0] += `, in ${current}`;
else if (suite && reached === 'between specs') parts[0] += `, in suite ${suite}`;
if (missing.length) parts.push(`not loaded: ${missing.join(', ')}`);
return parts.join('; ');
}

// Out of sight but laid out like a page: specs that measure the DOM need a real viewport.
function defaultFrame() {
const frame = document.createElement('iframe');
Expand All @@ -181,6 +244,12 @@ export function runInFrame({pattern, timeout, runId, signal, write = () => {}, c
return new Promise((resolve, reject) => {
const frame = createFrame();
let timer;
let reached;
let specs = 0;
let current = '';
let suite = '';
// Known once the frame is in the page; a run stopped before that has no stage to give.
const stage = () => frame.isConnected ? frameStage(frame.contentWindow, {reached, specs, current, suite}) : undefined;
const finish = (error, report) => {
clearTimeout(timer);
removeEventListener('message', receive);
Expand All @@ -191,13 +260,21 @@ export function runInFrame({pattern, timeout, runId, signal, write = () => {}, c
const receive = ({source, origin, data}) => {
if (source !== frame.contentWindow || origin !== location.origin) return;
const message = data?.webfrontTest;
if (message?.type === 'spec') write(progress[message.status] ?? '');
if (message?.type === 'stage' && typeof message.stage === 'string') {
// A stage replaces the spec and the suite of the previous one: between specs, no spec is running.
reached = message.stage.slice(0, 64);
current = typeof message.spec === 'string' ? message.spec.slice(0, 256) : '';
suite = typeof message.suite === 'string' ? message.suite.slice(0, 256) : '';
} else if (message?.type === 'spec') {
if (message.status !== 'excluded') specs += 1; // like the report's total: a spec filtered out did not run
write(progress[message.status] ?? '');
}
else if (message?.type === 'done' || message?.type === 'error') finish(null, buildReport(message, {pattern}));
};
const interrupt = () => finish(stoppedRun('interrupted', pattern));
const interrupt = () => finish(stoppedRun('interrupted', pattern, stage()));
addEventListener('message', receive);
signal?.addEventListener('abort', interrupt, {once: true});
timer = setTimeout(() => finish(stoppedRun('timeout', pattern)), timeout * 1000);
timer = setTimeout(() => finish(stoppedRun('timeout', pattern, stage())), timeout * 1000);
if (signal?.aborted) return interrupt();
frame.src = `/webfront/developer/test/${runId}/index.html?pattern=${encodeURIComponent(pattern)}&run=${Date.now()}`;
document.body.append(frame);
Expand Down
53 changes: 52 additions & 1 deletion test/developer/specs/testing-specs.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Specs of wf test's host side, which supplement the real-browser regression in test/web/developer-specs.mjs.
import {parseTestOptions, specFiles, jasmineCore, buildReport, formatReport, reportResult, runnerFiles, fitResult, abortable} from '../../../js/developer/environment/testing.mjs';
import {parseTestOptions, specFiles, jasmineCore, buildReport, formatReport, reportResult, runnerFiles, fitResult, abortable, frameStage, describeStage, stoppedRun} from '../../../js/developer/environment/testing.mjs';
import {execute} from '../../../js/developer/environment/runtime.mjs';
import {bundleTests} from '../../../js/developer/environment/bundler.mjs';
import {rejects, throws, esbuild, reportSpecStarted, reportSpecDone} from '../support.mjs';
Expand Down Expand Up @@ -329,3 +329,54 @@ describe('wf test', () => {
await rejects(bundleTests(await esbuild(), {specs: ['absent.spec.js'], lock, readProject}), /absent\.spec\.js/);
}, 60000);
});

// A run stopped at its time limit names how far the runner frame got (#690): the last stage the runner posted, the spec
// it was running, and the runner's files whose response never completed.
describe('the stage of a stopped wf test run', () => {
const at = (file, end = 3) => ({name: `http://127.0.0.1:9002/webfront/developer/test/run/${file}`, responseEnd: end});
const frame = ({page = true, resources = [], styled = false}) => ({
performance: {
getEntriesByType: type => type === 'navigation'
? (page ? [at('index.html?pattern=&run=1', 5)] : [])
: resources.map(file => file === 'WebFront.js' ? {name: 'http://127.0.0.1:9002/WebFront.js', responseEnd: 4} : at(file)),
},
document: {querySelector: selector => styled && selector === 'link[href="./specs.css"]' ? {} : null},
});

it('lists the runner files the frame did not receive, specs.css only when the page links it', () => {
expect(frameStage(frame({resources: ['specs.css', 'WebFront.js', 'jasmine.js'], styled: true}), {reached: 'bridge settled'})).toEqual({
reached: 'bridge settled', specs: 0, current: '', suite: '',
loaded: ['index.html', 'specs.css', 'WebFront.js', 'jasmine.js'], missing: ['runner.js', 'specs.js']});
expect(frameStage(frame({resources: ['WebFront.js', 'jasmine.js', 'runner.js', 'specs.js']})).missing).toEqual([]);
// Nothing posted and no page: the runner never started.
expect(frameStage(frame({page: false}))).toEqual({reached: 'page requested', specs: 0, current: '', suite: '', loaded: [],
missing: ['index.html', 'WebFront.js', 'jasmine.js', 'runner.js', 'specs.js']});
});

it('counts a resource only once its response ended', () => {
const stalled = frame({resources: ['WebFront.js']});
const entries = stalled.performance.getEntriesByType;
stalled.performance.getEntriesByType = type => type === 'resource' ? [...entries(type), at('jasmine.js', 0)] : entries(type);
expect(frameStage(stalled).missing).toEqual(['jasmine.js', 'runner.js', 'specs.js']);
});

it('keeps the stage of a frame it cannot read', () => {
expect(frameStage(null, {reached: 'specs loaded', specs: 2})).toEqual({reached: 'specs loaded', specs: 2, current: '', suite: '', loaded: [], missing: []});
});

it('says the stage in the message and keeps it in the report', () => {
const stage = {reached: 'specs running', specs: 3, current: 'suite never ends', suite: 'suite', loaded: [], missing: []};
const stopped = stoppedRun('timeout', 'suite', stage);
expect([stopped.exitCode, stopped.message]).toEqual([124, 'Tests stopped at their time limit (stage: specs running, 3 specs done, in suite never ends)']);
expect([stopped.report.status, stopped.report.stage, stopped.report.error]).toEqual(['timeout', stage, stopped.message]);
expect(describeStage({reached: 'page requested', specs: 0, current: '', loaded: ['index.html'], missing: ['runner.js', 'specs.js']}))
.toBe('stage: page requested; not loaded: runner.js, specs.js');
// A run stopped in a suite's hook or between specs names no spec as running, but the suite whose hooks run.
expect(describeStage({reached: 'between specs', specs: 2, current: '', suite: '', loaded: [], missing: []})).toBe('stage: between specs, 2 specs done');
expect(describeStage({reached: 'between specs', specs: 0, current: '', suite: 'slow setup', loaded: [], missing: []}))
.toBe('stage: between specs, in suite slow setup');
// Stopped before the frame existed: no stage, and the message stays the plain one.
const early = stoppedRun('interrupted', '');
expect([early.exitCode, early.message, 'stage' in early.report]).toEqual([130, 'Tests stopped by Ctrl+C', false]);
});
});
4 changes: 4 additions & 0 deletions test/web/developer-specs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,10 @@ try {
clock.fire(60000);
const hung = await hanging;
assert(hung.error?.exitCode === 124 && hung.report?.status === 'timeout' && /time limit/.test(hung.error.message), `A hanging run must stop at its time limit: ${hung.error}`);
// It names how far the runner got (#690): every runner file loaded, and the spec that hangs.
const stage = hung.report.stage;
assert(stage?.reached === 'specs running' && stage.current === 'hanging never ends' && stage.specs === 0 && stage.missing.length === 0 &&
/stage: specs running, in hanging never ends/.test(hung.error.message), `A hanging run must name its stage: ${JSON.stringify(stage)}`);
assert(!document.querySelector('iframe[title="WebFront tests"]'), 'A timed out run must remove its frame');
} finally { started.dispose(); }
});
Expand Down
Loading