// A Playwright reporter that RECORDS each run's timings the moment the run's // json report is written (release 23 F5 — plans/e2e-speed.md S2's gap). // // Every suite writes Playwright's `json` report to `/timings.json` // (one file per run directory: the editor's, umtool's, the homepage's and each // of the export's four configs), and `scripts/e2e-timings.mjs` turns one into a // per-spec record in the branch's history (`<.git>/e2e-timings/…`). Recording // was a step somebody ran by hand, after the run — and Playwright empties // `test-results*/` when the next run starts, so a solo re-run made between the // two erased a full run's report before it was ever recorded (the overnight // 2026-10-10 start-mode run). Listed AFTER the json reporter, this records at // `onExit`, once every reporter's `onEnd` has written its file. // // A REPORTER, NOT A globalTeardown: Playwright (1.59, runner/tasks.js) runs // every globalTeardown before any reporter's `onEnd`, so a teardown never sees // its own run's json. // // It never fails a run: a report it cannot read or a history it cannot write // is one line on stderr. A run where no test ran (`--list`, whose report lists // tests with no results, or a filter that matched nothing) records nothing. // // reporter: [["list"], ["json", { outputFile: "test-results/timings.json" }], // ["../scripts/e2e-timings-reporter.mjs", { outputFile: "test-results/timings.json" }]] // // `outputFile` is resolved against the config's directory, as the json // reporter resolves its own. `historyDir` (tests) overrides the history root. import path from "node:path"; import { recordReport } from "./e2e-timings.mjs"; export default class E2eTimingsReporter { /** @param {{ outputFile?: string, historyDir?: string, top?: number }} [options] */ constructor(options = {}) { this.options = options; this.base = process.cwd(); } printsToStdio() { return false; } /** @param {{ configFile?: string, rootDir: string }} config */ onBegin(config) { this.base = config.configFile ? path.dirname(config.configFile) : config.rootDir; } async onExit() { const file = path.resolve(this.base, this.options.outputFile ?? "test-results/timings.json"); try { const out = recordReport(file, { historyDir: this.options.historyDir ?? null, top: this.options.top ?? 10, skipEmpty: true, }); if (!out.lines.length) return; // nothing ran (`--list`, an empty filter) process.stdout.write(`\n${out.lines.join("\n")}\n${out.note ? `${out.note}\n` : ""}`); } catch (err) { process.stderr.write(`e2e-timings: not recorded (${err?.code ?? err?.message ?? err})\n`); } } }