Skip to content

Commit 268833f

Browse files
authored
fix(ci): record complete native UI file timings (#134283)
* fix(ci): record complete native UI file timings * test(ci): recognize UI file timing reporter contract
1 parent e339ce2 commit 268833f

4 files changed

Lines changed: 99 additions & 8 deletions

File tree

‎scripts/lib/ci-test-timings-refit.mts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,27 @@ function seconds(value: string, unit: string): number {
2929
}
3030

3131
function readUiLog(text: string, samples: Samples, overhead: number[]) {
32-
let fileCount = 0;
32+
const files = new Map<string, number>();
3333
for (const line of text.split("\n")) {
34-
const file = /ui-e2e\s+(\S+\.e2e\.test\.ts)\s+\((\d+) tests?\)\s+([\d.]+)(m?s)/u.exec(line);
34+
const file =
35+
/^\s*(?:\d{4}-\d\d-\d\dT[\d:.]+Z\s+)?✓\s+(?:\|ui-e2e\||ui-e2e)\s+(\S+\.e2e\.test\.ts)\s+\((\d+) tests?(?: \| \d+ (?:skipped|todo))*\)\s+([\d.]+)(m?s)(?:\s|$)/u.exec(
36+
line,
37+
);
3538
if (file) {
36-
recordSample(samples, file[1]!, seconds(file[3]!, file[4]!));
37-
fileCount += 1;
39+
files.set(file[1]!, seconds(file[3]!, file[4]!));
3840
}
3941
const summary = /\bDuration\s+([\d.]+)(m?s)\s+\([^)]*\btests\s+([\d.]+)(m?s)/u.exec(line);
40-
if (summary && fileCount > 0) {
42+
if (summary && files.size > 0) {
43+
// Commit complete native file times, including suite hooks, once per invocation.
44+
for (const [name, duration] of files) {
45+
recordSample(samples, name, duration);
46+
}
4147
const value =
42-
(seconds(summary[1]!, summary[2]!) - seconds(summary[3]!, summary[4]!)) / fileCount;
48+
(seconds(summary[1]!, summary[2]!) - seconds(summary[3]!, summary[4]!)) / files.size;
4349
if (Number.isFinite(value)) {
4450
overhead.push(value);
4551
}
46-
fileCount = 0;
52+
files.clear();
4753
}
4854
}
4955
}

‎test/scripts/ci-test-timings.test.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { syncBuiltinESMExports } from "node:module";
55
import { tmpdir } from "node:os";
66
import path from "node:path";
77
import { fileURLToPath } from "node:url";
8+
import { stripVTControlCharacters } from "node:util";
89
import { afterEach, describe, expect, it, vi } from "vitest";
910
import { refitTestTimings, type CiTimingRun } from "../../scripts/lib/ci-test-timings-refit.mts";
1011
import {
@@ -69,6 +70,86 @@ it("rejects non-plain timing objects even when their fields are valid", () => {
6970
});
7071

7172
describe("CI test timing refit", () => {
73+
it("ingests the native UI reporters without losing case progress or suite hooks", async () => {
74+
const { default: config } = await import("../vitest/vitest.ui-e2e.config.ts");
75+
const root = fileURLToPath(new URL("../../", import.meta.url));
76+
const artifacts = path.join(root, ".artifacts");
77+
fs.mkdirSync(artifacts, { recursive: true });
78+
const directory = mkdtempSync(path.join(artifacts, "ci-ui-timings-"));
79+
const files = ["ui/src/e2e/first.e2e.test.ts", "ui/src/e2e/second.e2e.test.ts"];
80+
const configFile = path.join(directory, "vitest.config.mjs");
81+
try {
82+
for (const file of files) {
83+
fs.mkdirSync(path.dirname(path.join(directory, file)), { recursive: true });
84+
writeFileSync(
85+
path.join(directory, file),
86+
`import { setTimeout } from "node:timers/promises";
87+
import { beforeAll, afterAll, it } from "vitest";
88+
beforeAll(() => setTimeout(50));
89+
afterAll(() => setTimeout(50));
90+
it("reports completed case progress", () => {});
91+
it.skip("retains skipped coverage", () => {});
92+
it.todo("retains todo coverage");
93+
`,
94+
);
95+
}
96+
writeFileSync(
97+
configFile,
98+
`export default ${JSON.stringify({
99+
root: directory,
100+
test: {
101+
name: "ui-e2e",
102+
include: files,
103+
reporters: config.test?.reporters,
104+
fileParallelism: false,
105+
},
106+
})};\n`,
107+
);
108+
const runs = [1, 2].map((id) => {
109+
const result = spawnSync(
110+
process.execPath,
111+
["scripts/run-vitest.mjs", "run", "--config", configFile, "--configLoader", "runner"],
112+
{
113+
cwd: root,
114+
encoding: "utf8",
115+
timeout: 30_000,
116+
env: { ...process.env, GITHUB_STEP_SUMMARY: path.join(directory, "summary.md") },
117+
},
118+
);
119+
expect(result.status, result.stderr || result.stdout).toBe(0);
120+
const text = stripVTControlCharacters(result.stdout);
121+
expect(text).toContain("> reports completed case progress");
122+
const nativeFileDurations = [...text.matchAll(/\.e2e\.test\.ts[^\n]*\)\s+(\d+)ms/gu)];
123+
expect(nativeFileDurations, text).toHaveLength(files.length);
124+
// Native file time includes both suite hooks, unlike the case-only verbose rows.
125+
expect(nativeFileDurations.every((match) => Number(match[1]) >= 90)).toBe(true);
126+
return timingRun(id, [{ kind: "uiE2e", text: result.stdout }]);
127+
});
128+
expect(refitTestTimings(runs).timings.uiE2e.fileSeconds).toEqual(
129+
Object.fromEntries(files.map((file) => [file, 1])),
130+
);
131+
} finally {
132+
rmSync(directory, { recursive: true, force: true });
133+
}
134+
});
135+
136+
it("accepts completed passed file summaries once, excluding failed, skipped and unfinished files", () => {
137+
const log = [
138+
`✓ |ui-e2e| ${measuredFile} (3 tests | 1 skipped | 1 todo) 4000ms`,
139+
`✓ \u001b[32mui-e2e\u001b[0m ${measuredFile} (3 tests | 1 skipped | 1 todo) 4000ms`,
140+
"❯ ui-e2e ui/src/e2e/failed.e2e.test.ts (1 test | 1 failed) 20s",
141+
"❯ ui-e2e ui/src/e2e/timeout.e2e.test.ts (0 test) 30s",
142+
"↓ ui-e2e ui/src/e2e/skipped.e2e.test.ts (1 test | 1 skipped) 0ms",
143+
"Duration 56s (transform 1s, setup 1s, tests 54s, environment 0ms)",
144+
"✓ ui-e2e ui/src/e2e/unfinished.e2e.test.ts (1 test) 5s",
145+
].join("\n");
146+
const runs = [1, 2].map((id) => timingRun(id, [{ kind: "uiE2e", text: log }]));
147+
expect(refitTestTimings(runs).timings.uiE2e).toEqual({
148+
fileSeconds: { [measuredFile]: 4 },
149+
perFileOverheadSeconds: 2,
150+
});
151+
});
152+
72153
it("records per-file medians without outliers or one-run weights and measures excluded overhead", () => {
73154
const pageFile = "ui/src/pages/settings/measured.e2e.test.ts";
74155
const singleFile = "ui/src/e2e/single.e2e.test.ts";

‎test/vitest-reporters-config.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ describe("Vitest reporter contracts", () => {
101101
expect(
102102
reporters.map(([name]) => name),
103103
config,
104-
).toEqual(expected);
104+
).toEqual(
105+
config === "test/vitest/vitest.ui-e2e.config.ts" ? [...expected, "default"] : expected,
106+
);
105107
expect(cli, `${config} CLI override`).toEqual([["json", {}]]);
106108
}
107109
expect(resolved.defaults).toHaveLength(reporterConfigs.length);

‎test/vitest/vitest.ui-e2e.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function createUiE2eVitestConfig(
4747
isolate: true,
4848
name: "ui-e2e",
4949
pool: "forks",
50+
// Refit needs native file totals; verbose still reports cases to the output watchdog.
51+
reporters: [...baseTest.reporters, "default"],
5052
runner: undefined,
5153
sequence: { ...baseSequence, sequencer: UiE2eSequencer },
5254
setupFiles: ["test/vitest/vitest.ui-e2e.setup.ts"],

0 commit comments

Comments
 (0)