sumlyzer 0.3.2 → 0.5.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 +82 -28
- package/bin/sumlyzer.mjs +20 -6
- package/package.json +1 -1
- package/src/parseOutput.mjs +5 -0
- package/src/reporter.mjs +15 -15
- package/src/run.mjs +34 -25
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/sumlyzer.svg" alt="license" /></a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
Run every npm workspace's test script, one by one. Passing workspaces output
|
|
14
|
+
Run every npm workspace's test script, one by one or in concurrence. Passing workspaces output
|
|
15
15
|
to a single line; failing ones print only the relevant failure detail.
|
|
16
16
|
Ends with an aggregated pass/fail summary table, so nothing scrolls out of the terminal.
|
|
17
17
|
|
|
@@ -50,12 +50,23 @@ 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
|
|
56
57
|
workspaces), `0` otherwise, wire it straight into CI without extra parsing.
|
|
57
|
-
This also applies when `--junit` can't write its report
|
|
58
|
-
|
|
58
|
+
This also applies when `--junit` can't write its report.
|
|
59
|
+
The exit code is `1` even if every workspace's tests passed.
|
|
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
|
|
59
70
|
|
|
60
71
|
## Example
|
|
61
72
|
|
|
@@ -88,27 +99,44 @@ running gitlab
|
|
|
88
99
|
✓ gitlab 4.3s (8/8 tests)
|
|
89
100
|
|
|
90
101
|
Summary
|
|
91
|
-
|
|
92
|
-
│ (index)
|
|
93
|
-
|
|
94
|
-
│
|
|
95
|
-
│
|
|
96
|
-
│
|
|
97
|
-
│
|
|
98
|
-
│
|
|
99
|
-
│
|
|
100
|
-
│
|
|
101
|
-
│
|
|
102
|
-
│
|
|
103
|
-
│
|
|
104
|
-
│
|
|
105
|
-
│
|
|
106
|
-
│
|
|
107
|
-
|
|
102
|
+
┌─────────────┬────────┬──────────┬───────────────┬───────┬───────┬──────┬──────┬──────┬───────────┐
|
|
103
|
+
│ (index) │ status │ duration │ testsDuration │ tests │ pass │ fail │ skip │ todo │ cancelled │
|
|
104
|
+
├─────────────┼────────┼──────────┼───────────────┼───────┼───────┼──────┼──────┼──────┼───────────┤
|
|
105
|
+
│ contact │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │ '0' │ '0' │ '0' │
|
|
106
|
+
│ scanner │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │ '1' │ '0' │ '0' │
|
|
107
|
+
│ tarball │ 'PASS' │ '1.8s' │ '0.7s' │ '77' │ '77' │ '0' │ '0' │ '0' │ '0' │
|
|
108
|
+
│ mama │ 'PASS' │ '1.2s' │ '0.1s' │ '85' │ '85' │ '0' │ '0' │ '0' │ '0' │
|
|
109
|
+
│ tree-walker │ 'PASS' │ '3.0s' │ '2.0s' │ '26' │ '26' │ '0' │ '0' │ '0' │ '0' │
|
|
110
|
+
│ conformance │ 'PASS' │ '1.1s' │ '0.1s' │ '35' │ '35' │ '0' │ '0' │ '0' │ '0' │
|
|
111
|
+
│ i18n │ 'PASS' │ '1.1s' │ '0.2s' │ '19' │ '19' │ '0' │ '0' │ '0' │ '0' │
|
|
112
|
+
│ rc │ 'PASS' │ '4.1s' │ '0.6s' │ '28' │ '28' │ '0' │ '0' │ '0' │ '0' │
|
|
113
|
+
│ utils │ 'PASS' │ '1.1s' │ '0.1s' │ '30' │ '30' │ '0' │ '0' │ '0' │ '0' │
|
|
114
|
+
│ flags │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │ '0' │ '0' │ '0' │
|
|
115
|
+
│ fs-walk │ 'PASS' │ '1.1s' │ '0.1s' │ '3' │ '3' │ '0' │ '0' │ '0' │ '0' │
|
|
116
|
+
│ github │ 'PASS' │ '2.9s' │ '2.0s' │ '8' │ '8' │ '0' │ '0' │ '0' │ '0' │
|
|
117
|
+
│ gitlab │ 'PASS' │ '4.3s' │ '3.3s' │ '8' │ '8' │ '0' │ '0' │ '0' │ '0' │
|
|
118
|
+
└─────────────┴────────┴──────────┴───────────────┴───────┴───────┴──────┴──────┴──────┴───────────┘
|
|
108
119
|
|
|
109
120
|
13/13 workspaces passed.
|
|
110
121
|
```
|
|
111
122
|
|
|
123
|
+
### Summary columns
|
|
124
|
+
|
|
125
|
+
| Column | Meaning |
|
|
126
|
+
| --------------- | ------------------------------------------------------------------------------------------------ |
|
|
127
|
+
| `(index)` | Workspace name — `console.table` is fed an object keyed by workspace name (via `workspaceName` in [reporter.mjs](./src/reporter.mjs)) instead of an array, so this column carries the name instead of a meaningless row number |
|
|
128
|
+
| `status` | `PASS`, `FAIL`, or `SKIPPED` (only reached when `--ff` stopped scheduling before this workspace ran) |
|
|
129
|
+
| `duration` | Wall-clock time for the whole `npm run <script> --workspace=<path>` process, including npm/spawn overhead |
|
|
130
|
+
| `testsDuration` | `duration_ms` as reported by node's own test runner — the actual test execution time, without the npm overhead |
|
|
131
|
+
| `tests` | Total number of tests node:test ran in that workspace |
|
|
132
|
+
| `pass` | Number of passing tests |
|
|
133
|
+
| `fail` | Number of failing tests |
|
|
134
|
+
| `skip` | Tests reported as skipped (`ℹ skipped`), e.g. `t.skip()` or `{ skip: true }` |
|
|
135
|
+
| `todo` | Tests reported as todo (`ℹ todo`), e.g. `t.todo()` — intentionally not implemented yet, distinct from `skip` |
|
|
136
|
+
| `cancelled` | Tests reported as cancelled (`ℹ cancelled`), e.g. a timeout or a parent suite/hook failure that aborted them — unlike `skip`/`todo` this usually signals a real problem |
|
|
137
|
+
|
|
138
|
+
`duration` and `testsDuration` are deliberately both shown: a gap between them usually means npm/process startup overhead rather than slow tests. `tests` always equals `pass + fail + skip + todo + cancelled`; the last three columns exist so none of those buckets can hide silently behind an all-green `pass`/`fail` pair.
|
|
139
|
+
|
|
112
140
|
### On failure
|
|
113
141
|
|
|
114
142
|
Only the failing workspace prints its detail and passing ones stay collapsed to a single line.
|
|
@@ -135,14 +163,14 @@ running flags
|
|
|
135
163
|
✓ flags 1.1s (9/9 tests)
|
|
136
164
|
|
|
137
165
|
Summary
|
|
138
|
-
|
|
139
|
-
│ (index) │
|
|
140
|
-
|
|
141
|
-
│
|
|
142
|
-
│
|
|
143
|
-
│
|
|
144
|
-
│
|
|
145
|
-
|
|
166
|
+
┌─────────┬────────┬──────────┬───────────────┬───────┬───────┬──────┬──────┬──────┬───────────┐
|
|
167
|
+
│ (index) │ status │ duration │ testsDuration │ tests │ pass │ fail │ skip │ todo │ cancelled │
|
|
168
|
+
├─────────┼────────┼──────────┼───────────────┼───────┼───────┼──────┼──────┼──────┼───────────┤
|
|
169
|
+
│ contact │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │ '0' │ '0' │ '0' │
|
|
170
|
+
│ scanner │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │ '1' │ '0' │ '0' │
|
|
171
|
+
│ utils │ 'FAIL' │ '1.3s' │ '0.1s' │ '30' │ '29' │ '1' │ '0' │ '0' │ '0' │
|
|
172
|
+
│ flags │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │ '0' │ '0' │ '0' │
|
|
173
|
+
└─────────┴────────┴──────────┴───────────────┴───────┴───────┴──────┴──────┴──────┴───────────┘
|
|
146
174
|
|
|
147
175
|
1/4 workspace(s) failed:
|
|
148
176
|
utils
|
|
@@ -188,6 +216,24 @@ full suite output.
|
|
|
188
216
|
No other CI provider is currently supported: GitHub is the
|
|
189
217
|
only one whose log folding sumlyzer has actually verified end-to-end.
|
|
190
218
|
|
|
219
|
+
### Concurrency
|
|
220
|
+
|
|
221
|
+
`--concurrency <n>` runs up to `<n>` workspaces' scripts at the same time
|
|
222
|
+
instead of one after another, which can noticeably cut wall-clock time on
|
|
223
|
+
projects with many workspaces. There is no ordering dependency to worry about
|
|
224
|
+
here: unlike a `build` script, one workspace's `node:test` run never depends
|
|
225
|
+
on another workspace's test run, so nothing needs to be sequenced.
|
|
226
|
+
|
|
227
|
+
Since workspaces can now finish in any order, their output interleaves in
|
|
228
|
+
whatever order they complete, rather than following the `workspaces` list
|
|
229
|
+
order.
|
|
230
|
+
|
|
231
|
+
With `--ff`, a failure only stops workspaces that haven't started yet; any
|
|
232
|
+
workspace already running when the failure is detected runs to completion
|
|
233
|
+
(sumlyzer doesn't kill in-flight processes).
|
|
234
|
+
|
|
235
|
+

|
|
236
|
+
|
|
191
237
|
## Why
|
|
192
238
|
|
|
193
239
|
`npm run test --workspaces --if-present` runs every workspace but gives you
|
|
@@ -195,6 +241,14 @@ no aggregated summary and no way to fail fast early. An early failure just
|
|
|
195
241
|
scrolls off screen once later workspaces print their own output. sumlyzer is
|
|
196
242
|
a small, dependency-free tool that solves just this.
|
|
197
243
|
|
|
244
|
+
This exact fail-fast behavior at the `--workspaces` level has been requested
|
|
245
|
+
from npm more than once:
|
|
246
|
+
[npm/rfcs#575](https://github.com/npm/rfcs/issues/575) (open) and
|
|
247
|
+
[npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed). Until it
|
|
248
|
+
lands (if it ever does), sumlyzer's `--ff` flag gets you there — see also
|
|
249
|
+
this [Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284)
|
|
250
|
+
on the same problem.
|
|
251
|
+
|
|
198
252
|
## Contributing
|
|
199
253
|
|
|
200
254
|
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
package/src/parseOutput.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const COUNT_INDEX = 1;
|
|
2
2
|
const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).exec(output)?.[COUNT_INDEX];
|
|
3
3
|
|
|
4
|
+
// skip/todo/cancelled fall back to "0" rather than "?": unlike pass/fail, a missing
|
|
5
|
+
// line here is far more likely to mean "zero" than "parsing went wrong somehow".
|
|
4
6
|
export function parseTestCounts(output) {
|
|
5
7
|
const tests = count("tests", output);
|
|
6
8
|
|
|
@@ -12,6 +14,9 @@ export function parseTestCounts(output) {
|
|
|
12
14
|
tests,
|
|
13
15
|
pass: count("pass", output) ?? "?",
|
|
14
16
|
fail: count("fail", output) ?? "?",
|
|
17
|
+
skip: count("skipped", output) ?? "0",
|
|
18
|
+
todo: count("todo", output) ?? "0",
|
|
19
|
+
cancelled: count("cancelled", output) ?? "0",
|
|
15
20
|
durationMs: count("duration_ms", output)
|
|
16
21
|
};
|
|
17
22
|
}
|
package/src/reporter.mjs
CHANGED
|
@@ -57,32 +57,32 @@ export function printWorkspaceResult(name, result, ciGroup) {
|
|
|
57
57
|
process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function summaryRow(
|
|
60
|
+
function summaryRow(status, duration, counts) {
|
|
61
61
|
return {
|
|
62
|
-
workspace,
|
|
63
62
|
status,
|
|
64
63
|
duration,
|
|
65
64
|
testsDuration: counts?.durationMs ? formatSeconds(Number(counts.durationMs)) : "-",
|
|
66
65
|
tests: counts?.tests ?? "-",
|
|
67
66
|
pass: counts?.pass ?? "-",
|
|
68
|
-
fail: counts?.fail ?? "-"
|
|
67
|
+
fail: counts?.fail ?? "-",
|
|
68
|
+
skip: counts?.skip ?? "-",
|
|
69
|
+
todo: counts?.todo ?? "-",
|
|
70
|
+
cancelled: counts?.cancelled ?? "-"
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export function printSummary(results, skipped) {
|
|
73
75
|
console.log(bold("\nSummary"));
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
...skipped.map((wsPath) => summaryRow(workspaceName(wsPath), "SKIPPED", "-", null))
|
|
85
|
-
]);
|
|
76
|
+
|
|
77
|
+
const rows = {};
|
|
78
|
+
for (const { wsPath, exitCode, durationMs, counts } of results) {
|
|
79
|
+
rows[workspaceName(wsPath)] = summaryRow(exitCode === 0 ? "PASS" : "FAIL", formatSeconds(durationMs), counts);
|
|
80
|
+
}
|
|
81
|
+
for (const wsPath of skipped) {
|
|
82
|
+
rows[workspaceName(wsPath)] = summaryRow("SKIPPED", "-", null);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
console.table(rows);
|
|
86
86
|
|
|
87
87
|
if (skipped.length > 0) {
|
|
88
88
|
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
package/src/run.mjs
CHANGED
|
@@ -92,33 +92,42 @@ async function collectJunitEntries(results) {
|
|
|
92
92
|
return { entries, missing };
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir }) {
|
|
96
|
-
const results =
|
|
95
|
+
async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }) {
|
|
96
|
+
const results = new Array(workspacesToRun.length);
|
|
97
97
|
const ciGroup = githubGroupSyntax(process.env);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
+
}
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
|
|
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);
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
@@ -147,7 +156,7 @@ async function writeJunitReport(root, junitPath, results) {
|
|
|
147
156
|
}
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
export async function main({ root, scriptName, ff, junitPath }) {
|
|
159
|
+
export async function main({ root, scriptName, ff, junitPath, concurrency = 1 }) {
|
|
151
160
|
|
|
152
161
|
const { workspaces } = readJson(path.join(root, "package.json"));
|
|
153
162
|
|
|
@@ -161,7 +170,7 @@ export async function main({ root, scriptName, ff, junitPath }) {
|
|
|
161
170
|
|
|
162
171
|
let results;
|
|
163
172
|
try {
|
|
164
|
-
results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir });
|
|
173
|
+
results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency });
|
|
165
174
|
|
|
166
175
|
if (junitDir) {
|
|
167
176
|
await writeJunitReport(root, junitPath, results);
|