-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest.ts
More file actions
executable file
·89 lines (74 loc) · 2.7 KB
/
Copy pathtest.ts
File metadata and controls
executable file
·89 lines (74 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as os from "node:os";
import { inParallel } from "./lib/multicore";
import { execAsync, type Sample } from "./utils";
import { allFixtures } from "./fixtures";
import { affectedFixtures, divideParallelJobs } from "./buildkite";
const exit = require("exit");
const CPUs = Number.parseInt(process.env.CPUs || "0", 10) || os.cpus().length;
//////////////////////////////////////
// Test driver
/////////////////////////////////////
export type WorkItem = { sample: Sample; fixtureName: string };
async function main(sources: string[]) {
let fixtures = affectedFixtures();
const fixturesFromCmdline = process.env.FIXTURE;
if (fixturesFromCmdline) {
const fixtureNames = fixturesFromCmdline.split(",");
fixtures = fixtures.filter((fixture) =>
fixtureNames.some(fixture.runForName),
);
}
if (allFixtures.length !== fixtures.length) {
console.error(
`* Running a subset of fixtures: ${fixtures.map((f) => f.name).join(", ")}`,
);
}
// Get an array of all { sample, fixtureName } objects we'll run.
// We can't just put the fixture in there because these WorkItems
// will be sent in a message, removing all code.
const samples = fixtures.map((fixture) => ({
fixtureName: fixture.name,
samples: fixture.getSamples(sources),
}));
const priority = samples.flatMap((sample) =>
sample.samples.priority.map((prioritySample) => ({
fixtureName: sample.fixtureName,
sample: prioritySample,
})),
);
const others = samples.flatMap((sample) =>
sample.samples.others.map((otherSample) => ({
fixtureName: sample.fixtureName,
sample: otherSample,
})),
);
const tests = divideParallelJobs(priority.concat(others));
await inParallel({
queue: tests,
workers: CPUs,
setup: async () => {
console.error(
`* Running ${tests.length} tests between ${fixtures.length} fixtures`,
);
for (const fixture of fixtures) {
await execAsync("rm -rf test/runs");
await execAsync("mkdir -p test/runs");
await fixture.setup();
}
},
map: async ({ sample, fixtureName }: WorkItem, index) => {
const fixture = fixtures.find(({ name }) => name === fixtureName);
try {
await fixture?.runWithSample(sample, index, tests.length);
} catch (e) {
console.trace(e);
exit(1);
}
},
});
}
// skip 2 `node` args
main(process.argv.slice(2)).catch((reason) => {
console.error(reason);
process.exit(1);
});