sumlyzer 1.0.1 → 1.2.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 +6 -68
- package/package.json +4 -1
- package/src/reporter.mjs +23 -12
- package/src/run.mjs +116 -71
- package/src/runners/nodeTest.mjs +38 -0
package/README.md
CHANGED
|
@@ -85,31 +85,7 @@ This also applies when `--junit` can't write its report.
|
|
|
85
85
|
|
|
86
86
|
## Example
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
running contact
|
|
90
|
-
✓ contact 2.6s (35/35 tests)
|
|
91
|
-
running scanner
|
|
92
|
-
✓ scanner 10.1s (161/162 tests)
|
|
93
|
-
running tarball
|
|
94
|
-
✓ tarball 1.8s (77/77 tests)
|
|
95
|
-
running tree-walker
|
|
96
|
-
✓ tree-walker 3.0s (26/26 tests)
|
|
97
|
-
running flags
|
|
98
|
-
✓ flags 1.1s (9/9 tests)
|
|
99
|
-
|
|
100
|
-
Summary
|
|
101
|
-
┌─────────────┬────────┬──────────┬───────────────┬───────┬───────┬──────┬──────┬──────┬───────────┐
|
|
102
|
-
│ (index) │ status │ duration │ testsDuration │ tests │ pass │ fail │ skip │ todo │ cancelled │
|
|
103
|
-
├─────────────┼────────┼──────────┼───────────────┼───────┼───────┼──────┼──────┼──────┼───────────┤
|
|
104
|
-
│ contact │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │ '0' │ '0' │ '0' │
|
|
105
|
-
│ scanner │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │ '1' │ '0' │ '0' │
|
|
106
|
-
│ tarball │ 'PASS' │ '1.8s' │ '0.7s' │ '77' │ '77' │ '0' │ '0' │ '0' │ '0' │
|
|
107
|
-
│ tree-walker │ 'PASS' │ '3.0s' │ '2.0s' │ '26' │ '26' │ '0' │ '0' │ '0' │ '0' │
|
|
108
|
-
│ flags │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │ '0' │ '0' │ '0' │
|
|
109
|
-
└─────────────┴────────┴──────────┴───────────────┴───────┴───────┴──────┴──────┴──────┴───────────┘
|
|
110
|
-
|
|
111
|
-
5/5 workspaces passed.
|
|
112
|
-
```
|
|
88
|
+

|
|
113
89
|
|
|
114
90
|
### Summary columns
|
|
115
91
|
|
|
@@ -118,54 +94,16 @@ Summary
|
|
|
118
94
|
| `(index)` | Workspace name |
|
|
119
95
|
| `status` | `PASS`, `FAIL`, or `SKIPPED` (reached when `--ff` stopped scheduling before this workspace ran) |
|
|
120
96
|
| `duration` | Wall-clock time for the whole `npm run <script> --workspace=<path>` process, including npm/spawn overhead |
|
|
121
|
-
| `testsDuration` | `duration_ms` as reported by node's own test runner |
|
|
122
97
|
| `tests` | Total number of tests node:test ran in that workspace |
|
|
123
98
|
| `pass` | Number of passing tests |
|
|
124
99
|
| `fail` | Number of failing tests |
|
|
125
|
-
| `skip` | Tests reported as skipped (`ℹ skipped`), e.g. `t.skip()` or `{ skip: true }` |
|
|
126
|
-
| `todo` | Tests reported as todo (`ℹ todo`), e.g. `t.todo()` |
|
|
127
|
-
| `cancelled` | Tests reported as cancelled (`ℹ cancelled`), unlike `skip`/`todo` this usually signals a real problem |
|
|
128
|
-
|
|
129
100
|
|
|
130
|
-
|
|
101
|
+
Skipped (`t.skip()`), todo (`t.todo()`), and cancelled tests are rare enough
|
|
102
|
+
that a column of zeros for every workspace would just bury the one row that
|
|
103
|
+
has a nonzero count. Instead, sumlyzer prints a footnote below the table,
|
|
104
|
+
naming only the workspaces that actually have some, e.g. `skipped tests:
|
|
105
|
+
flags (2)`.
|
|
131
106
|
|
|
132
|
-
Only the failing workspace prints its detail and passing ones stay collapsed to a single line.
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
running contact
|
|
136
|
-
✓ contact 2.6s (35/35 tests)
|
|
137
|
-
running scanner
|
|
138
|
-
✓ scanner 10.1s (161/162 tests)
|
|
139
|
-
running utils
|
|
140
|
-
|
|
141
|
-
✗ utils failed
|
|
142
|
-
test at test/format.spec.mjs:12:3
|
|
143
|
-
✖ formats negative numbers (3ms)
|
|
144
|
-
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal
|
|
145
|
-
+ actual - expected
|
|
146
|
-
|
|
147
|
-
+ '-1'
|
|
148
|
-
- '(1)'
|
|
149
|
-
|
|
150
|
-
✗ utils 1.3s, exit code 1
|
|
151
|
-
|
|
152
|
-
running flags
|
|
153
|
-
✓ flags 1.1s (9/9 tests)
|
|
154
|
-
|
|
155
|
-
Summary
|
|
156
|
-
┌─────────┬────────┬──────────┬───────────────┬───────┬───────┬──────┬──────┬──────┬───────────┐
|
|
157
|
-
│ (index) │ status │ duration │ testsDuration │ tests │ pass │ fail │ skip │ todo │ cancelled │
|
|
158
|
-
├─────────┼────────┼──────────┼───────────────┼───────┼───────┼──────┼──────┼──────┼───────────┤
|
|
159
|
-
│ contact │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │ '0' │ '0' │ '0' │
|
|
160
|
-
│ scanner │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │ '1' │ '0' │ '0' │
|
|
161
|
-
│ utils │ 'FAIL' │ '1.3s' │ '0.1s' │ '30' │ '29' │ '1' │ '0' │ '0' │ '0' │
|
|
162
|
-
│ flags │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │ '0' │ '0' │ '0' │
|
|
163
|
-
└─────────┴────────┴──────────┴───────────────┴───────┴───────┴──────┴──────┴──────┴───────────┘
|
|
164
|
-
|
|
165
|
-
1/4 workspace(s) failed:
|
|
166
|
-
utils
|
|
167
|
-
✖ formats negative numbers
|
|
168
|
-
```
|
|
169
107
|
|
|
170
108
|
### JUnit report
|
|
171
109
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumlyzer",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Run every npm workspace's test script, only show output for the ones that fail, and finish with an aggregated pass/fail summary.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -56,5 +56,8 @@
|
|
|
56
56
|
"@types/node": "^26.1.1",
|
|
57
57
|
"c8": "^12.0.0",
|
|
58
58
|
"fast-xml-parser": "^5.10.1"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"glob": "^13.0.6"
|
|
59
62
|
}
|
|
60
63
|
}
|
package/src/reporter.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { styleText } from "node:util";
|
|
|
2
2
|
|
|
3
3
|
export const green = (str) => styleText("green", str);
|
|
4
4
|
export const red = (str) => styleText("red", str);
|
|
5
|
+
export const blue = (str) => styleText("blue", str);
|
|
5
6
|
export const dim = (str) => styleText("dim", str);
|
|
6
7
|
export const bold = (str) => styleText("bold", str);
|
|
7
8
|
|
|
@@ -44,33 +45,36 @@ export function printWorkspaceResult(name, result, ciGroup) {
|
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
const seconds = formatSeconds(result.durationMs);
|
|
48
|
-
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
49
|
-
|
|
50
48
|
if (result.exitCode === 0) {
|
|
51
|
-
process.stdout.write(green(`✓ ${name}
|
|
49
|
+
process.stdout.write(green(`✓ ${name}\n`));
|
|
52
50
|
return;
|
|
53
51
|
}
|
|
54
52
|
|
|
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`));
|
|
53
|
+
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))} ${dim(`(exit code ${result.exitCode})`)}\n`);
|
|
54
|
+
process.stdout.write(result.failureDetails + "\n\n");
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
function summaryRow(status, duration, counts) {
|
|
61
58
|
return {
|
|
62
59
|
status,
|
|
63
60
|
duration,
|
|
64
|
-
testsDuration: counts?.durationMs ? formatSeconds(Number(counts.durationMs)) : "-",
|
|
65
61
|
tests: counts?.tests ?? "-",
|
|
66
62
|
pass: counts?.pass ?? "-",
|
|
67
|
-
fail: counts?.fail ?? "-"
|
|
68
|
-
skip: counts?.skip ?? "-",
|
|
69
|
-
todo: counts?.todo ?? "-",
|
|
70
|
-
cancelled: counts?.cancelled ?? "-"
|
|
63
|
+
fail: counts?.fail ?? "-"
|
|
71
64
|
};
|
|
72
65
|
}
|
|
73
66
|
|
|
67
|
+
// skip/todo/cancelled are rare in practice: a full column of zeros for every
|
|
68
|
+
// workspace buries the one row that actually has a nonzero count, so they're
|
|
69
|
+
// called out as a footnote instead of living in the table.
|
|
70
|
+
function extraCountsFootnote(results, key, label) {
|
|
71
|
+
const entries = results
|
|
72
|
+
.filter(({ counts }) => Number(counts?.[key]) > 0)
|
|
73
|
+
.map(({ wsPath, counts }) => `${workspaceName(wsPath)} (${counts[key]})`);
|
|
74
|
+
|
|
75
|
+
return entries.length > 0 ? `${label}: ${entries.join(", ")}` : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
74
78
|
export function printSummary(results, skipped) {
|
|
75
79
|
console.log(bold("\nSummary"));
|
|
76
80
|
|
|
@@ -84,6 +88,13 @@ export function printSummary(results, skipped) {
|
|
|
84
88
|
|
|
85
89
|
console.table(rows);
|
|
86
90
|
|
|
91
|
+
for (const [key, label] of [["skip", "skipped tests"], ["todo", "todo tests"], ["cancelled", "cancelled tests"]]) {
|
|
92
|
+
const footnote = extraCountsFootnote(results, key, label);
|
|
93
|
+
if (footnote) {
|
|
94
|
+
console.log(blue(`ℹ ${footnote}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
87
98
|
if (skipped.length > 0) {
|
|
88
99
|
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
|
89
100
|
}
|
package/src/run.mjs
CHANGED
|
@@ -2,37 +2,76 @@ import { spawn, spawnSync } 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 { fileURLToPath } from "node:url";
|
|
6
5
|
import path from "node:path";
|
|
7
6
|
|
|
7
|
+
import { glob } from "glob";
|
|
8
|
+
|
|
8
9
|
import { buildJunitReport } from "./junit.mjs";
|
|
9
|
-
import { stripNpmNoise } from "./parseOutput.mjs";
|
|
10
|
-
import { parseReporterEvents, renderFailureRecap, renderSummaryText } from "./testEventReporter.mjs";
|
|
11
10
|
import { red, dim, workspaceName, githubGroupSyntax, printWorkspaceResult, printSummary, reportOutcome } from "./reporter.mjs";
|
|
12
11
|
import { NoWorkspacesError, InvalidPackageJsonError, WorkspaceLaunchError } from "./errors.mjs";
|
|
12
|
+
import { hasOwnReporter, prepareEnv, parseResult } from "./runners/nodeTest.mjs";
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
export function envWithTestReporter(env, junitDestPath) {
|
|
17
|
-
const existing = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} ` : "";
|
|
18
|
-
const testReporterFlags = `--test-reporter=${TEST_EVENT_REPORTER_PATH} --test-reporter-destination=stdout`;
|
|
19
|
-
const junitFlags = junitDestPath ? ` --test-reporter=junit --test-reporter-destination=${junitDestPath}` : "";
|
|
20
|
-
// Drop NODE_TEST_CONTEXT: if sumlyzer itself is invoked from inside a node:test run, this var would otherwise leak.
|
|
21
|
-
const rest = { ...env };
|
|
22
|
-
delete rest.NODE_TEST_CONTEXT;
|
|
23
|
-
return { ...rest, NODE_OPTIONS: `${existing}${testReporterFlags}${junitFlags}` };
|
|
24
|
-
}
|
|
14
|
+
const runner = { hasOwnReporter, prepareEnv, parseResult };
|
|
25
15
|
|
|
26
|
-
// Rethink this synchronous approach in case of very large package.json files, or huge amount of workspaces,
|
|
16
|
+
// Rethink this synchronous approach in case of very large package.json files, or huge amount of workspaces,
|
|
27
17
|
// but for now it's simpler than async and should be fine in practice.
|
|
28
18
|
function readJson(file) {
|
|
29
19
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
30
20
|
}
|
|
31
21
|
|
|
32
|
-
|
|
22
|
+
// Splits "workspaces" entries into directory-only glob patterns to include and
|
|
23
|
+
// (from any leading "!") patterns to exclude, matching npm's own interpretation
|
|
24
|
+
// of the field.
|
|
25
|
+
function splitWorkspacePatterns(workspaces) {
|
|
26
|
+
const patterns = [];
|
|
27
|
+
const ignore = ["**/node_modules/**"];
|
|
28
|
+
|
|
29
|
+
for (const entry of workspaces) {
|
|
30
|
+
if (entry.startsWith("!")) {
|
|
31
|
+
ignore.push(entry.slice(1));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
patterns.push(entry.endsWith("/") ? entry : `${entry}/`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { patterns, ignore };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The "workspaces" field holds glob patterns (e.g. "packages/*"), not necessarily
|
|
42
|
+
// concrete paths. Resolve it the same way npm itself does: glob each pattern
|
|
43
|
+
// against directories only, in declaration order.
|
|
44
|
+
async function resolveWorkspacePaths(root, workspaces) {
|
|
45
|
+
const { patterns, ignore } = splitWorkspacePatterns(workspaces);
|
|
46
|
+
const resolved = new Set();
|
|
47
|
+
|
|
48
|
+
for (const pattern of patterns) {
|
|
49
|
+
const matches = await glob(pattern, { cwd: root, ignore });
|
|
50
|
+
|
|
51
|
+
for (const match of matches.sort((a, b) => a.localeCompare(b, "en"))) {
|
|
52
|
+
resolved.add(match);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [...resolved];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function classifyWorkspace(root, wsPath, scriptName) {
|
|
60
|
+
const pkgFile = path.join(root, wsPath, "package.json");
|
|
61
|
+
let pkg;
|
|
62
|
+
try {
|
|
63
|
+
pkg = readJson(pkgFile);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return error.code === "ENOENT" ? { kind: "absent" } : { kind: "invalid", message: error.message };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const script = pkg.scripts?.[scriptName];
|
|
70
|
+
if (!script) {
|
|
71
|
+
return { kind: "absent" };
|
|
72
|
+
}
|
|
33
73
|
|
|
34
|
-
|
|
35
|
-
return OWN_TEST_REPORTER_FLAG.test(scriptCommand);
|
|
74
|
+
return runner.hasOwnReporter(script) ? { kind: "ownReporterConflict" } : { kind: "eligible" };
|
|
36
75
|
}
|
|
37
76
|
|
|
38
77
|
function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
@@ -41,28 +80,17 @@ function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
|
41
80
|
const invalidPackageJson = [];
|
|
42
81
|
|
|
43
82
|
for (const wsPath of workspaces) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const script = pkg.scripts?.[scriptName];
|
|
58
|
-
if (!script) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (hasOwnTestReporter(script)) {
|
|
62
|
-
ownReporterConflicts.push(wsPath);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
eligible.push(wsPath);
|
|
83
|
+
const classification = classifyWorkspace(root, wsPath, scriptName);
|
|
84
|
+
switch (classification.kind) {
|
|
85
|
+
case "invalid":
|
|
86
|
+
invalidPackageJson.push({ wsPath, message: classification.message });
|
|
87
|
+
break;
|
|
88
|
+
case "ownReporterConflict":
|
|
89
|
+
ownReporterConflicts.push(wsPath);
|
|
90
|
+
break;
|
|
91
|
+
case "eligible":
|
|
92
|
+
eligible.push(wsPath);
|
|
93
|
+
break;
|
|
66
94
|
}
|
|
67
95
|
}
|
|
68
96
|
|
|
@@ -86,12 +114,19 @@ function killWorkspaceChild(child) {
|
|
|
86
114
|
}
|
|
87
115
|
}
|
|
88
116
|
|
|
117
|
+
function waitForExit(child) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
child.on("error", reject);
|
|
120
|
+
child.on("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
89
124
|
async function captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
90
125
|
const options = {
|
|
91
126
|
cwd: root,
|
|
92
127
|
shell: process.platform === "win32",
|
|
93
128
|
detached: process.platform !== "win32",
|
|
94
|
-
env:
|
|
129
|
+
env: runner.prepareEnv(process.env, junitDestPath)
|
|
95
130
|
};
|
|
96
131
|
|
|
97
132
|
const child = spawn("npm", ["run", scriptName, "--workspace=" + wsPath], options);
|
|
@@ -103,10 +138,7 @@ async function captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath,
|
|
|
103
138
|
child.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
104
139
|
|
|
105
140
|
try {
|
|
106
|
-
const exitCode = await
|
|
107
|
-
child.on("error", reject);
|
|
108
|
-
child.on("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
109
|
-
});
|
|
141
|
+
const exitCode = await waitForExit(child);
|
|
110
142
|
|
|
111
143
|
return {
|
|
112
144
|
exitCode,
|
|
@@ -143,32 +175,19 @@ async function withInterruptHandling(activeChildren, run) {
|
|
|
143
175
|
}
|
|
144
176
|
}
|
|
145
177
|
|
|
146
|
-
function
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
// Workspaces that don't run through node:test never emit our JSON events; fall
|
|
150
|
-
// back to their raw (npm-noise-stripped) output so failures are still visible.
|
|
151
|
-
const fallbackOutput = stripNpmNoise(stdout + stderr).trim();
|
|
152
|
-
const failureRecap = failures.length > 0 ? renderFailureRecap(failures) : null;
|
|
178
|
+
async function runWorkspaceScript({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
179
|
+
const start = Date.now();
|
|
180
|
+
const captured = await captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren });
|
|
153
181
|
|
|
154
182
|
return {
|
|
155
183
|
wsPath,
|
|
156
|
-
exitCode,
|
|
157
|
-
|
|
158
|
-
durationMs,
|
|
159
|
-
counts,
|
|
160
|
-
failingTests,
|
|
184
|
+
exitCode: captured.exitCode,
|
|
185
|
+
durationMs: Date.now() - start,
|
|
161
186
|
junitDestPath,
|
|
162
|
-
|
|
187
|
+
...runner.parseResult(captured)
|
|
163
188
|
};
|
|
164
189
|
}
|
|
165
190
|
|
|
166
|
-
async function runWorkspaceScript({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
167
|
-
const start = Date.now();
|
|
168
|
-
const captured = await captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren });
|
|
169
|
-
return buildWorkspaceResult(wsPath, junitDestPath, Date.now() - start, captured);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
191
|
async function collectJunitEntries(results) {
|
|
173
192
|
const entries = [];
|
|
174
193
|
const missing = [];
|
|
@@ -188,6 +207,23 @@ async function collectJunitEntries(results) {
|
|
|
188
207
|
return { entries, missing };
|
|
189
208
|
}
|
|
190
209
|
|
|
210
|
+
// A worker leaves its slot in `results` undefined when it never got to start
|
|
211
|
+
// (--ff stopped scheduling first); that's the signal to bucket it as skipped.
|
|
212
|
+
function partitionResults(results, workspacesToRun) {
|
|
213
|
+
const completed = [];
|
|
214
|
+
const skipped = [];
|
|
215
|
+
for (const [index, result] of results.entries()) {
|
|
216
|
+
if (result === undefined) {
|
|
217
|
+
skipped.push(workspacesToRun[index]);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
completed.push(result);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return { completed, skipped };
|
|
225
|
+
}
|
|
226
|
+
|
|
191
227
|
async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }) {
|
|
192
228
|
const results = new Array(workspacesToRun.length);
|
|
193
229
|
const ciGroup = githubGroupSyntax(process.env);
|
|
@@ -226,7 +262,7 @@ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir,
|
|
|
226
262
|
const workerCount = Math.max(1, Math.min(concurrency, workspacesToRun.length));
|
|
227
263
|
await withInterruptHandling(activeChildren, () => Promise.all(Array.from({ length: workerCount }, worker)));
|
|
228
264
|
|
|
229
|
-
return results
|
|
265
|
+
return partitionResults(results, workspacesToRun);
|
|
230
266
|
}
|
|
231
267
|
|
|
232
268
|
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
@@ -263,7 +299,9 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 })
|
|
|
263
299
|
throw new NoWorkspacesError();
|
|
264
300
|
}
|
|
265
301
|
|
|
266
|
-
const
|
|
302
|
+
const resolvedWorkspaces = await resolveWorkspacePaths(root, workspaces);
|
|
303
|
+
|
|
304
|
+
const { eligible: workspacesToRun, ownReporterConflicts, invalidPackageJson } = listEligibleWorkspaces(root, resolvedWorkspaces, scriptName);
|
|
267
305
|
|
|
268
306
|
if (invalidPackageJson.length > 0) {
|
|
269
307
|
throw new InvalidPackageJsonError(invalidPackageJson);
|
|
@@ -273,14 +311,21 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 })
|
|
|
273
311
|
console.log(dim(`⊘ ${workspaceName(wsPath)}: skipped, own --test-reporter detected in its "${scriptName}" script`));
|
|
274
312
|
}
|
|
275
313
|
|
|
314
|
+
if (workspacesToRun.length === 0) {
|
|
315
|
+
console.log(dim(ownReporterConflicts.length > 0
|
|
316
|
+
? `All workspaces with a "${scriptName}" script were skipped (own --test-reporter detected).`
|
|
317
|
+
: `No workspace has a "${scriptName}" script.`));
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
|
|
276
321
|
const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
|
|
277
322
|
|
|
278
|
-
let
|
|
323
|
+
let completed, skipped;
|
|
279
324
|
try {
|
|
280
|
-
|
|
325
|
+
({ completed, skipped } = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }));
|
|
281
326
|
|
|
282
327
|
if (junitDir) {
|
|
283
|
-
await writeJunitReport(root, junitPath,
|
|
328
|
+
await writeJunitReport(root, junitPath, completed);
|
|
284
329
|
}
|
|
285
330
|
}
|
|
286
331
|
finally {
|
|
@@ -289,6 +334,6 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 })
|
|
|
289
334
|
}
|
|
290
335
|
}
|
|
291
336
|
|
|
292
|
-
printSummary(
|
|
293
|
-
reportOutcome(
|
|
337
|
+
printSummary(completed, skipped);
|
|
338
|
+
reportOutcome(completed);
|
|
294
339
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
|
|
3
|
+
import { stripNpmNoise } from "../parseOutput.mjs";
|
|
4
|
+
import { parseReporterEvents, renderFailureRecap, renderSummaryText } from "../testEventReporter.mjs";
|
|
5
|
+
|
|
6
|
+
const TEST_EVENT_REPORTER_PATH = fileURLToPath(new URL("../testEventReporter.mjs", import.meta.url));
|
|
7
|
+
|
|
8
|
+
const OWN_TEST_REPORTER_FLAG = /--test-reporter(?!-destination)\b/;
|
|
9
|
+
|
|
10
|
+
export function hasOwnReporter(scriptCommand) {
|
|
11
|
+
return OWN_TEST_REPORTER_FLAG.test(scriptCommand);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function prepareEnv(env, junitDestPath) {
|
|
15
|
+
const existing = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} ` : "";
|
|
16
|
+
const testReporterFlags = `--test-reporter="${TEST_EVENT_REPORTER_PATH}" --test-reporter-destination=stdout`;
|
|
17
|
+
const junitFlags = junitDestPath ? ` --test-reporter=junit --test-reporter-destination="${junitDestPath}"` : "";
|
|
18
|
+
|
|
19
|
+
// Drop NODE_TEST_CONTEXT: if sumlyzer itself is invoked from inside a node:test run, this var would otherwise leak.
|
|
20
|
+
const rest = { ...env };
|
|
21
|
+
delete rest.NODE_TEST_CONTEXT;
|
|
22
|
+
return { ...rest, NODE_OPTIONS: `${existing}${testReporterFlags}${junitFlags}` };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Workspaces that don't run through node:test never emit our JSON events; fall
|
|
26
|
+
// back to their raw (npm-noise-stripped) output so failures are still visible.
|
|
27
|
+
export function parseResult({ exitCode, stdout, stderr }) {
|
|
28
|
+
const { counts, failingTests, failures } = parseReporterEvents(stdout);
|
|
29
|
+
const fallbackOutput = stripNpmNoise(stdout + stderr).trim();
|
|
30
|
+
const failureRecap = failures.length > 0 ? renderFailureRecap(failures) : null;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
counts,
|
|
34
|
+
failingTests,
|
|
35
|
+
failureDetails: exitCode === 0 ? null : (failureRecap ?? fallbackOutput),
|
|
36
|
+
rawOutput: counts ? [renderSummaryText(counts), failureRecap].filter(Boolean).join("\n\n") : fallbackOutput
|
|
37
|
+
};
|
|
38
|
+
}
|