Skip to content

Commit cf899d7

Browse files
committed
chore: split the A/B script's functions (1920)
1 parent ae2e071 commit cf899d7

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎.github/experiment-1920-ab.mjs‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ const report = (file) => {
1818
}
1919
};
2020

21-
const brief = (t) => `${t.status} ${Math.round(t.duration ?? -1)}ms`;
22-
const why = (t) => ((t.failureMessages ?? [])[0] ?? "").split("\n")[0].slice(0, 200);
21+
const brief = (t) => `${t.status} ${Math.round(t.duration)}ms`;
22+
const why = (t) => String(t.failureMessages).split("\n")[0].slice(0, 200);
23+
const isFailed = (t) => t.status === "failed";
2324

24-
function one(label, arm, args) {
25+
function one([label, arm, args]) {
2526
count += 1;
2627
const out = join(root, `ab-${count}.json`);
2728
const t0 = Date.now();
2829
const r = spawnSync(
2930
`pnpm exec vitest run --project unit ${FILE} ${args} --reporter=json --outputFile="${out}"`,
3031
{ cwd: join(root, arm), shell: true, encoding: "utf8", timeout: 400_000 },
3132
);
32-
const wall = Date.now() - t0;
33-
const tests = report(out).filter((t) => t.status === "passed" || t.status === "failed");
34-
const target = tests.find((t) => t.title.startsWith(TEST));
35-
const failed = tests.filter((t) => t.status === "failed");
36-
console.log(`${label} ${arm} exit=${r.status} wall=${wall}ms target ${target && brief(target)}`);
33+
const tests = report(out);
34+
const target = tests.filter((t) => t.title.startsWith(TEST)).map(brief)[0];
35+
console.log(`${label} ${arm} exit=${r.status} wall=${Date.now() - t0}ms target ${target}`);
3736
if (target === undefined) console.log(` no result: ${`${r.stdout}${r.stderr}`.slice(-600)}`);
37+
const failed = tests.filter(isFailed);
3838
for (const t of failed) console.log(` FAILED ${t.title} ${brief(t)} ${why(t)}`);
39-
results.push({ label, arm, target: target && brief(target), failed: failed.length });
39+
results.push({ label, arm, target, failed: failed.length });
4040
left();
4141
}
4242

@@ -55,12 +55,14 @@ function summary() {
5555
}
5656
}
5757

58+
const times = (n, runs) => Array.from({ length: n }, () => runs).flat();
59+
5860
function main() {
5961
for (const arm of ARMS)
6062
console.log(run("git", ["-C", join(root, arm), "log", "-1", "--oneline"]));
61-
for (let i = 1; i <= 20; i += 1) for (const arm of ARMS) one("one test", arm, `-t "${TEST}"`);
62-
const whole = [ARMS[0], ARMS[2]];
63-
for (let i = 1; i <= 5; i += 1) for (const arm of whole) one("whole file", arm, "");
63+
const single = ARMS.map((arm) => ["one test", arm, `-t "${TEST}"`]);
64+
const whole = ["10d4e2e49", "cc0abbb5e"].map((arm) => ["whole file", arm, ""]);
65+
for (const spec of [...times(20, single), ...times(5, whole)]) one(spec);
6466
summary();
6567
}
6668

0 commit comments

Comments
 (0)