sumlyzer 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/bin/sumlyzer.mjs +20 -6
- package/package.json +1 -1
- package/src/parseOutput.mjs +41 -0
- package/src/reporter.mjs +108 -0
- package/src/run.mjs +39 -180
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ Options:
|
|
|
50
50
|
| `--script <name>` | `test` | npm script to run per workspace |
|
|
51
51
|
| `--ff` | off | fail fast: stop at the first failing workspace |
|
|
52
52
|
| `--junit <path>` | off | write an aggregated JUnit XML report to `<path>` |
|
|
53
|
+
| `-c, --concurrency <n>` | `1` | run up to `<n>` workspaces at once |
|
|
53
54
|
| `-h, --help` | | print usage |
|
|
54
55
|
|
|
55
56
|
Exit code is `1` if any workspace fails (or if the project has no
|
|
@@ -57,6 +58,16 @@ workspaces), `0` otherwise, wire it straight into CI without extra parsing.
|
|
|
57
58
|
This also applies when `--junit` can't write its report (e.g. an invalid
|
|
58
59
|
`<path>`): the exit code is `1` even if every workspace's tests passed.
|
|
59
60
|
|
|
61
|
+
## Features
|
|
62
|
+
|
|
63
|
+
- Aggregated pass/fail summary table, so nothing scrolls out of the terminal
|
|
64
|
+
- Fail-fast (`--ff`): stop at the first failing workspace
|
|
65
|
+
- Aggregated JUnit XML report (`--junit`), merging every workspace's own results
|
|
66
|
+
- GitHub Actions log folding: each workspace's output collapsed into an
|
|
67
|
+
expandable group, automatically, no flag needed
|
|
68
|
+
- Concurrent runs (`--concurrency <n>`): run several workspaces' test scripts
|
|
69
|
+
at once instead of one by one
|
|
70
|
+
|
|
60
71
|
## Example
|
|
61
72
|
|
|
62
73
|
```
|
|
@@ -188,6 +199,22 @@ full suite output.
|
|
|
188
199
|
No other CI provider is currently supported: GitHub is the
|
|
189
200
|
only one whose log folding sumlyzer has actually verified end-to-end.
|
|
190
201
|
|
|
202
|
+
### Concurrency
|
|
203
|
+
|
|
204
|
+
`--concurrency <n>` runs up to `<n>` workspaces' scripts at the same time
|
|
205
|
+
instead of one after another, which can noticeably cut wall-clock time on
|
|
206
|
+
projects with many workspaces. There is no ordering dependency to worry about
|
|
207
|
+
here: unlike a `build` script, one workspace's `node:test` run never depends
|
|
208
|
+
on another workspace's test run, so nothing needs to be sequenced.
|
|
209
|
+
|
|
210
|
+
Since workspaces can now finish in any order, their output interleaves in
|
|
211
|
+
whatever order they complete, rather than following the `workspaces` list
|
|
212
|
+
order.
|
|
213
|
+
|
|
214
|
+
With `--ff`, a failure only stops workspaces that haven't started yet; any
|
|
215
|
+
workspace already running when the failure is detected runs to completion
|
|
216
|
+
(sumlyzer doesn't kill in-flight processes).
|
|
217
|
+
|
|
191
218
|
## Why
|
|
192
219
|
|
|
193
220
|
`npm run test --workspaces --if-present` runs every workspace but gives you
|
|
@@ -195,6 +222,14 @@ no aggregated summary and no way to fail fast early. An early failure just
|
|
|
195
222
|
scrolls off screen once later workspaces print their own output. sumlyzer is
|
|
196
223
|
a small, dependency-free tool that solves just this.
|
|
197
224
|
|
|
225
|
+
This exact fail-fast behavior at the `--workspaces` level has been requested
|
|
226
|
+
from npm more than once:
|
|
227
|
+
[npm/rfcs#575](https://github.com/npm/rfcs/issues/575) (open) and
|
|
228
|
+
[npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed). Until it
|
|
229
|
+
lands (if it ever does), sumlyzer's `--ff` flag gets you there — see also
|
|
230
|
+
this [Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284)
|
|
231
|
+
on the same problem.
|
|
232
|
+
|
|
198
233
|
## Contributing
|
|
199
234
|
|
|
200
235
|
See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup, conventions, and how to submit changes.
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -11,6 +11,7 @@ try {
|
|
|
11
11
|
ff: { type: "boolean", default: false },
|
|
12
12
|
script: { type: "string", default: "test" },
|
|
13
13
|
junit: { type: "string" },
|
|
14
|
+
concurrency: { type: "string", short: "c", default: "1" },
|
|
14
15
|
help: { type: "boolean", short: "h", default: false }
|
|
15
16
|
}
|
|
16
17
|
}));
|
|
@@ -22,20 +23,33 @@ catch (error) {
|
|
|
22
23
|
process.exit(1);
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
const concurrency = Number.parseInt(values.concurrency, 10);
|
|
27
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || String(concurrency) !== values.concurrency) {
|
|
28
|
+
console.info(`--concurrency must be a positive integer, got "${values.concurrency}". Run "sumlyzer --help" for usage.`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
if (values.help) {
|
|
26
33
|
console.log(`sumlyzer [options]
|
|
27
34
|
|
|
28
|
-
Runs each npm workspace's "${values.script}" script one by one. Passing
|
|
35
|
+
Runs each npm workspace's "${values.script}" script, ${concurrency > 1 ? `${concurrency} at a time` : "one by one"}. Passing
|
|
29
36
|
workspaces collapse to a single line; failing ones print only the relevant
|
|
30
37
|
failure detail. Ends with an aggregated pass/fail summary table.
|
|
31
38
|
|
|
32
39
|
Options:
|
|
33
|
-
--script <name>
|
|
34
|
-
--ff
|
|
35
|
-
--junit <path>
|
|
36
|
-
-
|
|
40
|
+
--script <name> npm script to run per workspace (default: "test")
|
|
41
|
+
--ff fail fast: stop at the first failing workspace
|
|
42
|
+
--junit <path> write an aggregated JUnit XML report to <path>
|
|
43
|
+
-c, --concurrency <n> run up to <n> workspaces at once (default: 1)
|
|
44
|
+
-h, --help show this help
|
|
37
45
|
`);
|
|
38
46
|
process.exit(0);
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
await main({
|
|
49
|
+
await main({
|
|
50
|
+
root: path.resolve(process.cwd()),
|
|
51
|
+
scriptName: values.script,
|
|
52
|
+
ff: values.ff,
|
|
53
|
+
junitPath: values.junit,
|
|
54
|
+
concurrency
|
|
55
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const COUNT_INDEX = 1;
|
|
2
|
+
const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).exec(output)?.[COUNT_INDEX];
|
|
3
|
+
|
|
4
|
+
export function parseTestCounts(output) {
|
|
5
|
+
const tests = count("tests", output);
|
|
6
|
+
|
|
7
|
+
if (!tests) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
tests,
|
|
13
|
+
pass: count("pass", output) ?? "?",
|
|
14
|
+
fail: count("fail", output) ?? "?",
|
|
15
|
+
durationMs: count("duration_ms", output)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function parseFailingTests(output) {
|
|
20
|
+
const [, section] = output.split("✖ failing tests:");
|
|
21
|
+
if (!section) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [...section.matchAll(/^✖ (.+) \([\d.]+ms\)$/gm)].map((match) => match[1]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function stripNpmNoise(output) {
|
|
29
|
+
return output.replace(/^npm warn .*\n?/gm, "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function extractFailureDetails(output) {
|
|
33
|
+
const [, section] = output.split("✖ failing tests:");
|
|
34
|
+
if (!section) {
|
|
35
|
+
return output.trim();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const details = section.split(/\n(?=npm )/)[0].trim();
|
|
39
|
+
|
|
40
|
+
return details.includes("'test failed'") ? output.trim() : details;
|
|
41
|
+
}
|
package/src/reporter.mjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
|
|
3
|
+
export const green = (str) => styleText("green", str);
|
|
4
|
+
export const red = (str) => styleText("red", str);
|
|
5
|
+
export const dim = (str) => styleText("dim", str);
|
|
6
|
+
export const bold = (str) => styleText("bold", str);
|
|
7
|
+
|
|
8
|
+
export function formatSeconds(ms) {
|
|
9
|
+
const seconds = Number.isFinite(ms) ? ms / 1000 : 0;
|
|
10
|
+
return `${seconds.toFixed(1)}s`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// GitHub Actions: https://docs.github.com/actions/how-tos/write-workflows/choose-what-workflows-do/workflow-commands#grouping-log-lines
|
|
14
|
+
export function githubGroupSyntax(env) {
|
|
15
|
+
if (env.GITHUB_ACTIONS === "true") {
|
|
16
|
+
return {
|
|
17
|
+
start: (title) => `::group::${title}`,
|
|
18
|
+
end: () => "::endgroup::"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function workspaceName(wsPath) {
|
|
25
|
+
return (wsPath ?? "").replace(/^workspaces[\\/]/, "");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function ciGroupTitle(name, result) {
|
|
29
|
+
const seconds = formatSeconds(result.durationMs);
|
|
30
|
+
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
31
|
+
const icon = result.exitCode === 0 ? "✓" : "✗";
|
|
32
|
+
return `${icon} ${name} ${seconds}${countsLabel}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function printWorkspaceResultCi(name, result, ciGroup) {
|
|
36
|
+
process.stdout.write(`${ciGroup.start(ciGroupTitle(name, result))}\n`);
|
|
37
|
+
process.stdout.write(`${result.rawOutput || "(no output captured)"}\n`);
|
|
38
|
+
process.stdout.write(`${ciGroup.end()}\n`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function printWorkspaceResult(name, result, ciGroup) {
|
|
42
|
+
if (ciGroup) {
|
|
43
|
+
printWorkspaceResultCi(name, result, ciGroup);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const seconds = formatSeconds(result.durationMs);
|
|
48
|
+
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
49
|
+
|
|
50
|
+
if (result.exitCode === 0) {
|
|
51
|
+
process.stdout.write(green(`✓ ${name}`) + dim(` ${seconds}${countsLabel}\n`));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
|
|
56
|
+
process.stdout.write(result.failureDetails + "\n");
|
|
57
|
+
process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function summaryRow(workspace, status, duration, counts) {
|
|
61
|
+
return {
|
|
62
|
+
workspace,
|
|
63
|
+
status,
|
|
64
|
+
duration,
|
|
65
|
+
testsDuration: counts?.durationMs ? formatSeconds(Number(counts.durationMs)) : "-",
|
|
66
|
+
tests: counts?.tests ?? "-",
|
|
67
|
+
pass: counts?.pass ?? "-",
|
|
68
|
+
fail: counts?.fail ?? "-"
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function printSummary(results, skipped) {
|
|
73
|
+
console.log(bold("\nSummary"));
|
|
74
|
+
console.table([
|
|
75
|
+
...results.map(({ wsPath, exitCode, durationMs, counts }) => {
|
|
76
|
+
|
|
77
|
+
return summaryRow(
|
|
78
|
+
workspaceName(wsPath),
|
|
79
|
+
exitCode === 0 ? "PASS" : "FAIL",
|
|
80
|
+
formatSeconds(durationMs),
|
|
81
|
+
counts
|
|
82
|
+
);
|
|
83
|
+
}),
|
|
84
|
+
...skipped.map((wsPath) => summaryRow(workspaceName(wsPath), "SKIPPED", "-", null))
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
if (skipped.length > 0) {
|
|
88
|
+
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function reportOutcome(results) {
|
|
93
|
+
const failed = results.filter((result) => result.exitCode !== 0);
|
|
94
|
+
|
|
95
|
+
if (failed.length === 0) {
|
|
96
|
+
console.log(green(`${results.length}/${results.length} workspaces passed.`));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
|
|
101
|
+
for (const result of failed) {
|
|
102
|
+
console.log(red(` ${workspaceName(result.wsPath)}`));
|
|
103
|
+
for (const testName of result.failingTests) {
|
|
104
|
+
console.log(dim(` ✖ ${testName}`));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
process.exitCode = 1;
|
|
108
|
+
}
|
package/src/run.mjs
CHANGED
|
@@ -2,29 +2,21 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
|
-
import { promisify
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
|
|
8
8
|
import { buildJunitReport } from "./junit.mjs";
|
|
9
|
+
import { parseTestCounts, parseFailingTests, stripNpmNoise, extractFailureDetails } from "./parseOutput.mjs";
|
|
10
|
+
import { red, dim, workspaceName, githubGroupSyntax, printWorkspaceResult, printSummary, reportOutcome } from "./reporter.mjs";
|
|
9
11
|
|
|
10
12
|
const execFileAsync = promisify(execFile);
|
|
11
13
|
|
|
12
|
-
const green = (str) => styleText("green", str);
|
|
13
|
-
const red = (str) => styleText("red", str);
|
|
14
|
-
const dim = (str) => styleText("dim", str);
|
|
15
|
-
const bold = (str) => styleText("bold", str);
|
|
16
|
-
|
|
17
|
-
const COUNT_INDEX = 1;
|
|
18
|
-
const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).exec(output)?.[COUNT_INDEX];
|
|
19
|
-
|
|
20
14
|
const SPEC_REPORTER_FLAGS = "--test-reporter=spec --test-reporter-destination=stdout";
|
|
21
15
|
|
|
22
16
|
export function envWithSpecReporter(env, junitDestPath) {
|
|
23
17
|
const existing = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} ` : "";
|
|
24
18
|
const junitFlags = junitDestPath ? ` --test-reporter=junit --test-reporter-destination=${junitDestPath}` : "";
|
|
25
|
-
// Drop NODE_TEST_CONTEXT: if sumlyzer itself is invoked from inside a node:test run
|
|
26
|
-
// its own test suite), this var would otherwise leak into the workspace's own `node --test`
|
|
27
|
-
// process, which then silently treats itself as a nested child and stops reporting normally.
|
|
19
|
+
// Drop NODE_TEST_CONTEXT: if sumlyzer itself is invoked from inside a node:test run, this var would otherwise leak.
|
|
28
20
|
const rest = { ...env };
|
|
29
21
|
delete rest.NODE_TEST_CONTEXT;
|
|
30
22
|
return { ...rest, NODE_OPTIONS: `${existing}${SPEC_REPORTER_FLAGS}${junitFlags}` };
|
|
@@ -34,10 +26,6 @@ function readJson(file) {
|
|
|
34
26
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
export function workspaceName(wsPath) {
|
|
38
|
-
return (wsPath ?? "").replace(/^workspaces[\\/]/, "");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
29
|
function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
42
30
|
return workspaces.filter((wsPath) => {
|
|
43
31
|
const pkgFile = path.join(root, wsPath, "package.json");
|
|
@@ -50,50 +38,6 @@ function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
|
50
38
|
});
|
|
51
39
|
}
|
|
52
40
|
|
|
53
|
-
export function parseTestCounts(output) {
|
|
54
|
-
const tests = count("tests", output);
|
|
55
|
-
|
|
56
|
-
if (!tests) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
tests,
|
|
62
|
-
pass: count("pass", output) ?? "?",
|
|
63
|
-
fail: count("fail", output) ?? "?",
|
|
64
|
-
durationMs: count("duration_ms", output)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function parseFailingTests(output) {
|
|
69
|
-
const [, section] = output.split("✖ failing tests:");
|
|
70
|
-
if (!section) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return [...section.matchAll(/^✖ (.+) \([\d.]+ms\)$/gm)].map((match) => match[1]);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function stripNpmNoise(output) {
|
|
78
|
-
return output.replace(/^npm warn .*\n?/gm, "");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function extractFailureDetails(output) {
|
|
82
|
-
const [, section] = output.split("✖ failing tests:");
|
|
83
|
-
if (!section) {
|
|
84
|
-
return output.trim();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const details = section.split(/\n(?=npm )/)[0].trim();
|
|
88
|
-
|
|
89
|
-
return details.includes("'test failed'") ? output.trim() : details;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function formatSeconds(ms) {
|
|
93
|
-
const seconds = Number.isFinite(ms) ? ms / 1000 : 0;
|
|
94
|
-
return `${seconds.toFixed(1)}s`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
41
|
async function runWorkspaceScript(root, wsPath, scriptName, junitDestPath) {
|
|
98
42
|
const start = Date.now();
|
|
99
43
|
const options = {
|
|
@@ -129,30 +73,6 @@ async function runWorkspaceScript(root, wsPath, scriptName, junitDestPath) {
|
|
|
129
73
|
};
|
|
130
74
|
}
|
|
131
75
|
|
|
132
|
-
// GitHub Actions: https://docs.github.com/actions/how-tos/write-workflows/choose-what-workflows-do/workflow-commands#grouping-log-lines
|
|
133
|
-
export function ciGroupSyntax(env) {
|
|
134
|
-
if (env.GITHUB_ACTIONS === "true") {
|
|
135
|
-
return {
|
|
136
|
-
start: (title) => `::group::${title}`,
|
|
137
|
-
end: () => "::endgroup::"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function ciGroupTitle(name, result) {
|
|
144
|
-
const seconds = formatSeconds(result.durationMs);
|
|
145
|
-
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
146
|
-
const icon = result.exitCode === 0 ? "✓" : "✗";
|
|
147
|
-
return `${icon} ${name} ${seconds}${countsLabel}`;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function printWorkspaceResultCi(name, result, ciGroup) {
|
|
151
|
-
process.stdout.write(`${ciGroup.start(ciGroupTitle(name, result))}\n`);
|
|
152
|
-
process.stdout.write(`${result.rawOutput || "(no output captured)"}\n`);
|
|
153
|
-
process.stdout.write(`${ciGroup.end()}\n`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
76
|
async function collectJunitEntries(results) {
|
|
157
77
|
const entries = [];
|
|
158
78
|
const missing = [];
|
|
@@ -165,9 +85,6 @@ async function collectJunitEntries(results) {
|
|
|
165
85
|
entries.push({ name: workspaceName(result.wsPath), xml: await readFile(result.junitDestPath, "utf8") });
|
|
166
86
|
}
|
|
167
87
|
catch {
|
|
168
|
-
// Either the workspace crashed before node:test's own junit reporter could write its
|
|
169
|
-
// file, or --script points at something that isn't node:test at all; skip it, but the
|
|
170
|
-
// caller still needs to know so it can tell the user the report is missing an entry.
|
|
171
88
|
missing.push(workspaceName(result.wsPath));
|
|
172
89
|
}
|
|
173
90
|
}
|
|
@@ -175,65 +92,42 @@ async function collectJunitEntries(results) {
|
|
|
175
92
|
return { entries, missing };
|
|
176
93
|
}
|
|
177
94
|
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
for (const [index, wsPath] of workspacesToRun.entries()) {
|
|
209
|
-
const name = workspaceName(wsPath);
|
|
210
|
-
process.stdout.write(dim(`running ${name}\n`));
|
|
211
|
-
|
|
212
|
-
const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
|
|
213
|
-
|
|
214
|
-
let result;
|
|
215
|
-
try {
|
|
216
|
-
result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath);
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
|
|
220
|
-
process.exit(1);
|
|
221
|
-
}
|
|
222
|
-
results.push(result);
|
|
223
|
-
|
|
224
|
-
if (ciGroup) {
|
|
225
|
-
printWorkspaceResultCi(name, result, ciGroup);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
printWorkspaceResult(name, result);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (result.exitCode !== 0 && ff) {
|
|
232
|
-
break;
|
|
95
|
+
async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }) {
|
|
96
|
+
const results = new Array(workspacesToRun.length);
|
|
97
|
+
const ciGroup = githubGroupSyntax(process.env);
|
|
98
|
+
let stopScheduling = false;
|
|
99
|
+
let nextIndex = 0;
|
|
100
|
+
|
|
101
|
+
async function worker() {
|
|
102
|
+
while (!stopScheduling && nextIndex < workspacesToRun.length) {
|
|
103
|
+
const index = nextIndex++;
|
|
104
|
+
const wsPath = workspacesToRun[index];
|
|
105
|
+
const name = workspaceName(wsPath);
|
|
106
|
+
process.stdout.write(dim(`running ${name}\n`));
|
|
107
|
+
|
|
108
|
+
const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
|
|
109
|
+
|
|
110
|
+
let result;
|
|
111
|
+
try {
|
|
112
|
+
result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
results[index] = result;
|
|
119
|
+
printWorkspaceResult(name, result, ciGroup);
|
|
120
|
+
|
|
121
|
+
if (result.exitCode !== 0 && ff) {
|
|
122
|
+
stopScheduling = true;
|
|
123
|
+
}
|
|
233
124
|
}
|
|
234
125
|
}
|
|
235
126
|
|
|
236
|
-
|
|
127
|
+
const workerCount = Math.max(1, Math.min(concurrency, workspacesToRun.length));
|
|
128
|
+
await Promise.all(Array.from({ length: workerCount }, worker));
|
|
129
|
+
|
|
130
|
+
return results.filter((result) => result !== undefined);
|
|
237
131
|
}
|
|
238
132
|
|
|
239
133
|
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
@@ -262,42 +156,7 @@ async function writeJunitReport(root, junitPath, results) {
|
|
|
262
156
|
}
|
|
263
157
|
}
|
|
264
158
|
|
|
265
|
-
function
|
|
266
|
-
console.log(bold("\nSummary"));
|
|
267
|
-
console.table([
|
|
268
|
-
...results.map((result) => summaryRow(
|
|
269
|
-
workspaceName(result.wsPath),
|
|
270
|
-
result.exitCode === 0 ? "PASS" : "FAIL",
|
|
271
|
-
formatSeconds(result.durationMs),
|
|
272
|
-
result.counts
|
|
273
|
-
)),
|
|
274
|
-
...skipped.map((wsPath) => summaryRow(workspaceName(wsPath), "SKIPPED", "-", null))
|
|
275
|
-
]);
|
|
276
|
-
|
|
277
|
-
if (skipped.length > 0) {
|
|
278
|
-
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function reportOutcome(results) {
|
|
283
|
-
const failed = results.filter((result) => result.exitCode !== 0);
|
|
284
|
-
|
|
285
|
-
if (failed.length === 0) {
|
|
286
|
-
console.log(green(`${results.length}/${results.length} workspaces passed.`));
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
|
|
291
|
-
for (const result of failed) {
|
|
292
|
-
console.log(red(` ${workspaceName(result.wsPath)}`));
|
|
293
|
-
for (const testName of result.failingTests) {
|
|
294
|
-
console.log(dim(` ✖ ${testName}`));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
process.exitCode = 1;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export async function main({ root, scriptName, ff, junitPath }) {
|
|
159
|
+
export async function main({ root, scriptName, ff, junitPath, concurrency = 1 }) {
|
|
301
160
|
|
|
302
161
|
const { workspaces } = readJson(path.join(root, "package.json"));
|
|
303
162
|
|
|
@@ -311,7 +170,7 @@ export async function main({ root, scriptName, ff, junitPath }) {
|
|
|
311
170
|
|
|
312
171
|
let results;
|
|
313
172
|
try {
|
|
314
|
-
results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir });
|
|
173
|
+
results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency });
|
|
315
174
|
|
|
316
175
|
if (junitDir) {
|
|
317
176
|
await writeJunitReport(root, junitPath, results);
|