sumlyzer 1.0.1 → 1.1.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 +1 -65
- package/package.json +4 -1
- package/src/run.mjs +74 -46
- 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
|
|
|
@@ -127,46 +103,6 @@ Summary
|
|
|
127
103
|
| `cancelled` | Tests reported as cancelled (`ℹ cancelled`), unlike `skip`/`todo` this usually signals a real problem |
|
|
128
104
|
|
|
129
105
|
|
|
130
|
-
### On failure
|
|
131
|
-
|
|
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
|
-
|
|
170
106
|
### JUnit report
|
|
171
107
|
|
|
172
108
|
`--junit <path>` writes a single aggregated JUnit XML report to `<path>`, merging
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumlyzer",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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/run.mjs
CHANGED
|
@@ -2,37 +2,58 @@ 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/**"];
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
|
|
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];
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
@@ -58,7 +79,7 @@ function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
|
58
79
|
if (!script) {
|
|
59
80
|
continue;
|
|
60
81
|
}
|
|
61
|
-
if (
|
|
82
|
+
if (runner.hasOwnReporter(script)) {
|
|
62
83
|
ownReporterConflicts.push(wsPath);
|
|
63
84
|
}
|
|
64
85
|
else {
|
|
@@ -91,7 +112,7 @@ async function captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath,
|
|
|
91
112
|
cwd: root,
|
|
92
113
|
shell: process.platform === "win32",
|
|
93
114
|
detached: process.platform !== "win32",
|
|
94
|
-
env:
|
|
115
|
+
env: runner.prepareEnv(process.env, junitDestPath)
|
|
95
116
|
};
|
|
96
117
|
|
|
97
118
|
const child = spawn("npm", ["run", scriptName, "--workspace=" + wsPath], options);
|
|
@@ -143,32 +164,19 @@ async function withInterruptHandling(activeChildren, run) {
|
|
|
143
164
|
}
|
|
144
165
|
}
|
|
145
166
|
|
|
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;
|
|
167
|
+
async function runWorkspaceScript({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
168
|
+
const start = Date.now();
|
|
169
|
+
const captured = await captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren });
|
|
153
170
|
|
|
154
171
|
return {
|
|
155
172
|
wsPath,
|
|
156
|
-
exitCode,
|
|
157
|
-
|
|
158
|
-
durationMs,
|
|
159
|
-
counts,
|
|
160
|
-
failingTests,
|
|
173
|
+
exitCode: captured.exitCode,
|
|
174
|
+
durationMs: Date.now() - start,
|
|
161
175
|
junitDestPath,
|
|
162
|
-
|
|
176
|
+
...runner.parseResult(captured)
|
|
163
177
|
};
|
|
164
178
|
}
|
|
165
179
|
|
|
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
180
|
async function collectJunitEntries(results) {
|
|
173
181
|
const entries = [];
|
|
174
182
|
const missing = [];
|
|
@@ -226,7 +234,18 @@ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir,
|
|
|
226
234
|
const workerCount = Math.max(1, Math.min(concurrency, workspacesToRun.length));
|
|
227
235
|
await withInterruptHandling(activeChildren, () => Promise.all(Array.from({ length: workerCount }, worker)));
|
|
228
236
|
|
|
229
|
-
|
|
237
|
+
const completed = [];
|
|
238
|
+
const skipped = [];
|
|
239
|
+
for (const [index, result] of results.entries()) {
|
|
240
|
+
if (result === undefined) {
|
|
241
|
+
skipped.push(workspacesToRun[index]);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
completed.push(result);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return { completed, skipped };
|
|
230
249
|
}
|
|
231
250
|
|
|
232
251
|
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
@@ -263,7 +282,9 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 })
|
|
|
263
282
|
throw new NoWorkspacesError();
|
|
264
283
|
}
|
|
265
284
|
|
|
266
|
-
const
|
|
285
|
+
const resolvedWorkspaces = await resolveWorkspacePaths(root, workspaces);
|
|
286
|
+
|
|
287
|
+
const { eligible: workspacesToRun, ownReporterConflicts, invalidPackageJson } = listEligibleWorkspaces(root, resolvedWorkspaces, scriptName);
|
|
267
288
|
|
|
268
289
|
if (invalidPackageJson.length > 0) {
|
|
269
290
|
throw new InvalidPackageJsonError(invalidPackageJson);
|
|
@@ -273,14 +294,21 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 })
|
|
|
273
294
|
console.log(dim(`⊘ ${workspaceName(wsPath)}: skipped, own --test-reporter detected in its "${scriptName}" script`));
|
|
274
295
|
}
|
|
275
296
|
|
|
297
|
+
if (workspacesToRun.length === 0) {
|
|
298
|
+
console.log(dim(ownReporterConflicts.length > 0
|
|
299
|
+
? `All workspaces with a "${scriptName}" script were skipped (own --test-reporter detected).`
|
|
300
|
+
: `No workspace has a "${scriptName}" script.`));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
276
304
|
const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
|
|
277
305
|
|
|
278
|
-
let
|
|
306
|
+
let completed, skipped;
|
|
279
307
|
try {
|
|
280
|
-
|
|
308
|
+
({ completed, skipped } = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }));
|
|
281
309
|
|
|
282
310
|
if (junitDir) {
|
|
283
|
-
await writeJunitReport(root, junitPath,
|
|
311
|
+
await writeJunitReport(root, junitPath, completed);
|
|
284
312
|
}
|
|
285
313
|
}
|
|
286
314
|
finally {
|
|
@@ -289,6 +317,6 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1 })
|
|
|
289
317
|
}
|
|
290
318
|
}
|
|
291
319
|
|
|
292
|
-
printSummary(
|
|
293
|
-
reportOutcome(
|
|
320
|
+
printSummary(completed, skipped);
|
|
321
|
+
reportOutcome(completed);
|
|
294
322
|
}
|
|
@@ -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
|
+
}
|