sumlyzer 0.1.1 → 0.2.1
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 +144 -5
- package/bin/sumlyzer.mjs +3 -1
- package/package.json +23 -5
- package/src/junit.mjs +81 -0
- package/src/run.mjs +130 -40
package/README.md
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/ErwanRaulo/sumlyzer/blob/main/logo.png?raw=true" alt="Sumlyzer logo" width="140" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Sumlyzer</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/v/sumlyzer.svg" alt="npm version" /></a>
|
|
9
|
+
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/dm/sumlyzer.svg" alt="npm downloads" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/node/v/sumlyzer.svg" alt="node engine" /></a>
|
|
11
|
+
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/sumlyzer.svg" alt="license" /></a>
|
|
12
|
+
</p>
|
|
2
13
|
|
|
3
14
|
Run every npm workspace's test script, one by one. Passing workspaces output
|
|
4
15
|
to a single line; failing ones print only the relevant failure detail.
|
|
5
16
|
Ends with an aggregated pass/fail summary table, so nothing scrolls out of the terminal.
|
|
6
17
|
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- Node.js >= 22.0.0
|
|
21
|
+
- An npm workspaces project (`package.json` with a `workspaces` field)
|
|
22
|
+
|
|
7
23
|
## Scope
|
|
8
24
|
|
|
9
25
|
This tool is intentionally narrow: **npm workspaces** running **`node:test`**.
|
|
@@ -33,20 +49,143 @@ Options:
|
|
|
33
49
|
| --- | --- | --- |
|
|
34
50
|
| `--script <name>` | `test` | npm script to run per workspace |
|
|
35
51
|
| `--ff` | off | fail fast: stop at the first failing workspace |
|
|
52
|
+
| `--junit <path>` | off | write an aggregated JUnit XML report to `<path>` |
|
|
36
53
|
| `-h, --help` | | print usage |
|
|
37
54
|
|
|
55
|
+
Exit code is `1` if any workspace fails (or if the project has no
|
|
56
|
+
workspaces), `0` otherwise — wire it straight into CI without extra parsing.
|
|
57
|
+
This also applies when `--junit` can't write its report (e.g. an invalid
|
|
58
|
+
`<path>`): the exit code is `1` even if every workspace's tests passed.
|
|
59
|
+
|
|
38
60
|
## Example
|
|
39
61
|
|
|
40
|
-
|
|
62
|
+
```
|
|
63
|
+
running contact
|
|
64
|
+
✓ contact 2.6s (35/35 tests)
|
|
65
|
+
running scanner
|
|
66
|
+
✓ scanner 10.1s (161/162 tests)
|
|
67
|
+
running tarball
|
|
68
|
+
✓ tarball 1.8s (77/77 tests)
|
|
69
|
+
running mama
|
|
70
|
+
✓ mama 1.2s (85/85 tests)
|
|
71
|
+
running tree-walker
|
|
72
|
+
✓ tree-walker 3.0s (26/26 tests)
|
|
73
|
+
running conformance
|
|
74
|
+
✓ conformance 1.1s (35/35 tests)
|
|
75
|
+
running i18n
|
|
76
|
+
✓ i18n 1.1s (19/19 tests)
|
|
77
|
+
running rc
|
|
78
|
+
✓ rc 4.1s (28/28 tests)
|
|
79
|
+
running utils
|
|
80
|
+
✓ utils 1.1s (30/30 tests)
|
|
81
|
+
running flags
|
|
82
|
+
✓ flags 1.1s (9/9 tests)
|
|
83
|
+
running fs-walk
|
|
84
|
+
✓ fs-walk 1.1s (3/3 tests)
|
|
85
|
+
running github
|
|
86
|
+
✓ github 2.9s (8/8 tests)
|
|
87
|
+
running gitlab
|
|
88
|
+
✓ gitlab 4.3s (8/8 tests)
|
|
89
|
+
|
|
90
|
+
Summary
|
|
91
|
+
┌─────────┬────────────────┬──────────┬────────────┬────────────────┬─────────┬────────┬────────┐
|
|
92
|
+
│ (index) │ workspace │ status │ duration │ testsDuration │ tests │ pass │ fail │
|
|
93
|
+
├─────────┼────────────────┼──────────┼────────────┼────────────────┼─────────┼────────┼────────┤
|
|
94
|
+
│ 0 │ 'contact' │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │
|
|
95
|
+
│ 1 │ 'scanner' │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │
|
|
96
|
+
│ 2 │ 'tarball' │ 'PASS' │ '1.8s' │ '0.7s' │ '77' │ '77' │ '0' │
|
|
97
|
+
│ 3 │ 'mama' │ 'PASS' │ '1.2s' │ '0.1s' │ '85' │ '85' │ '0' │
|
|
98
|
+
│ 4 │ 'tree-walker' │ 'PASS' │ '3.0s' │ '2.0s' │ '26' │ '26' │ '0' │
|
|
99
|
+
│ 5 │ 'conformance' │ 'PASS' │ '1.1s' │ '0.1s' │ '35' │ '35' │ '0' │
|
|
100
|
+
│ 6 │ 'i18n' │ 'PASS' │ '1.1s' │ '0.2s' │ '19' │ '19' │ '0' │
|
|
101
|
+
│ 7 │ 'rc' │ 'PASS' │ '4.1s' │ '0.6s' │ '28' │ '28' │ '0' │
|
|
102
|
+
│ 8 │ 'utils' │ 'PASS' │ '1.1s' │ '0.1s' │ '30' │ '30' │ '0' │
|
|
103
|
+
│ 9 │ 'flags' │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │
|
|
104
|
+
│ 10 │ 'fs-walk' │ 'PASS' │ '1.1s' │ '0.1s' │ '3' │ '3' │ '0' │
|
|
105
|
+
│ 11 │ 'github' │ 'PASS' │ '2.9s' │ '2.0s' │ '8' │ '8' │ '0' │
|
|
106
|
+
│ 12 │ 'gitlab' │ 'PASS' │ '4.3s' │ '3.3s' │ '8' │ '8' │ '0' │
|
|
107
|
+
└─────────┴────────────────┴──────────┴────────────┴────────────────┴─────────┴────────┴────────┘
|
|
108
|
+
|
|
109
|
+
13/13 workspaces passed.
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### On failure
|
|
113
|
+
|
|
114
|
+
Only the failing workspace prints its detail and passing ones stay collapsed to a single line.
|
|
41
115
|
|
|
116
|
+
```
|
|
117
|
+
running contact
|
|
118
|
+
✓ contact 2.6s (35/35 tests)
|
|
119
|
+
running scanner
|
|
120
|
+
✓ scanner 10.1s (161/162 tests)
|
|
121
|
+
running utils
|
|
122
|
+
|
|
123
|
+
✗ utils failed
|
|
124
|
+
test at test/format.spec.mjs:12:3
|
|
125
|
+
✖ formats negative numbers (3ms)
|
|
126
|
+
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal
|
|
127
|
+
+ actual - expected
|
|
128
|
+
|
|
129
|
+
+ '-1'
|
|
130
|
+
- '(1)'
|
|
131
|
+
|
|
132
|
+
✗ utils 1.3s, exit code 1
|
|
133
|
+
|
|
134
|
+
running flags
|
|
135
|
+
✓ flags 1.1s (9/9 tests)
|
|
136
|
+
|
|
137
|
+
Summary
|
|
138
|
+
┌─────────┬────────────┬──────────┬────────────┬────────────────┬─────────┬────────┬────────┐
|
|
139
|
+
│ (index) │ workspace │ status │ duration │ testsDuration │ tests │ pass │ fail │
|
|
140
|
+
├─────────┼────────────┼──────────┼────────────┼────────────────┼─────────┼────────┼────────┤
|
|
141
|
+
│ 0 │ 'contact' │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │
|
|
142
|
+
│ 1 │ 'scanner' │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │
|
|
143
|
+
│ 2 │ 'utils' │ 'FAIL' │ '1.3s' │ '0.1s' │ '30' │ '29' │ '1' │
|
|
144
|
+
│ 3 │ 'flags' │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │
|
|
145
|
+
└─────────┴────────────┴──────────┴────────────┴────────────────┴─────────┴────────┴────────┘
|
|
146
|
+
|
|
147
|
+
1/4 workspace(s) failed:
|
|
148
|
+
utils
|
|
149
|
+
✖ formats negative numbers
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### JUnit report
|
|
153
|
+
|
|
154
|
+
`--junit <path>` writes a single aggregated JUnit XML report to `<path>`, merging
|
|
155
|
+
every workspace's own `node:test` results. Each workspace runs with `node:test`'s
|
|
156
|
+
built-in `junit` reporter enabled alongside the terminal one, and sumlyzer combines
|
|
157
|
+
the resulting files into one document, prefixing every `<testsuite>` name with the
|
|
158
|
+
workspace it came from so CI test-report UIs (GitLab, Jenkins, Azure DevOps, ...)
|
|
159
|
+
can tell them apart. If `<path>` is an existing directory, the report is written
|
|
160
|
+
to `<path>/junit.xml`:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
npx sumlyzer --junit reports/junit.xml
|
|
164
|
+
npx sumlyzer --junit reports/ # writes reports/junit.xml
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```xml
|
|
168
|
+
<testsuites>
|
|
169
|
+
<testsuite name="contact › contact tests">...</testsuite>
|
|
170
|
+
<testsuite name="scanner">...</testsuite>
|
|
171
|
+
</testsuites>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
A workspace whose script never produces a junit file (for example,
|
|
175
|
+
`--script` points at something that isn't `node:test`, or the workspace crashed
|
|
176
|
+
before it could write one) is left out of the aggregated report and sumlyzer
|
|
177
|
+
prints a warning naming it.
|
|
42
178
|
|
|
43
179
|
## Why
|
|
44
180
|
|
|
45
181
|
`npm run test --workspaces --if-present` runs every workspace but gives you
|
|
46
182
|
no aggregated summary and no way to fail fast early. An early failure just
|
|
47
|
-
scrolls off screen once later workspaces print their own output.
|
|
48
|
-
|
|
49
|
-
|
|
183
|
+
scrolls off screen once later workspaces print their own output. sumlyzer is
|
|
184
|
+
a small, dependency-free tool that solves just this.
|
|
185
|
+
|
|
186
|
+
## Contributing
|
|
187
|
+
|
|
188
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup, conventions, and how to submit changes.
|
|
50
189
|
|
|
51
190
|
## License
|
|
52
191
|
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -10,6 +10,7 @@ try {
|
|
|
10
10
|
options: {
|
|
11
11
|
ff: { type: "boolean", default: false },
|
|
12
12
|
script: { type: "string", default: "test" },
|
|
13
|
+
junit: { type: "string" },
|
|
13
14
|
help: { type: "boolean", short: "h", default: false }
|
|
14
15
|
}
|
|
15
16
|
}));
|
|
@@ -31,9 +32,10 @@ failure detail. Ends with an aggregated pass/fail summary table.
|
|
|
31
32
|
Options:
|
|
32
33
|
--script <name> npm script to run per workspace (default: "test")
|
|
33
34
|
--ff fail fast: stop at the first failing workspace
|
|
35
|
+
--junit <path> write an aggregated JUnit XML report to <path>
|
|
34
36
|
-h, --help show this help
|
|
35
37
|
`);
|
|
36
38
|
process.exit(0);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
await main({ root: path.resolve(process.cwd()), scriptName: values.script, ff: values.ff });
|
|
41
|
+
await main({ root: path.resolve(process.cwd()), scriptName: values.script, ff: values.ff, junitPath: values.junit });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumlyzer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
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": {
|
|
@@ -16,7 +16,12 @@
|
|
|
16
16
|
"node": ">=22.0.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"test": "node --test \"./test/*.spec.mjs\""
|
|
19
|
+
"test": "node --test \"./test/*.spec.mjs\"",
|
|
20
|
+
"test:coverage": "c8 --reporter=text --reporter=lcov --check-coverage --lines 95 --functions 95 --statements 95 --branches 85 node --test \"./test/*.spec.mjs\"",
|
|
21
|
+
"security-scan": "node scripts/security-scan.mjs",
|
|
22
|
+
"postversion": "git push && git push --tags",
|
|
23
|
+
"prepublishOnly": "npm test",
|
|
24
|
+
"release": "npm publish --dry-run"
|
|
20
25
|
},
|
|
21
26
|
"keywords": [
|
|
22
27
|
"npm",
|
|
@@ -27,9 +32,19 @@
|
|
|
27
32
|
"test-runner",
|
|
28
33
|
"cli",
|
|
29
34
|
"fail-fast",
|
|
30
|
-
"summary"
|
|
35
|
+
"summary",
|
|
36
|
+
"npm-workspaces",
|
|
37
|
+
"monorepo",
|
|
38
|
+
"test-reporter",
|
|
39
|
+
"node-test",
|
|
40
|
+
"node:test",
|
|
41
|
+
"test-summary",
|
|
42
|
+
"ci"
|
|
31
43
|
],
|
|
32
|
-
"author":
|
|
44
|
+
"author": {
|
|
45
|
+
"name": "Erwan Raulo",
|
|
46
|
+
"url": "https://github.com/ErwanRaulo"
|
|
47
|
+
},
|
|
33
48
|
"license": "MIT",
|
|
34
49
|
"repository": {
|
|
35
50
|
"type": "git",
|
|
@@ -40,6 +55,9 @@
|
|
|
40
55
|
},
|
|
41
56
|
"homepage": "https://github.com/ErwanRaulo/sumlyzer#readme",
|
|
42
57
|
"devDependencies": {
|
|
43
|
-
"@
|
|
58
|
+
"@nodesecure/js-x-ray": "^16.0.0",
|
|
59
|
+
"@types/node": "^26.1.1",
|
|
60
|
+
"c8": "^12.0.0",
|
|
61
|
+
"fast-xml-parser": "^5.10.1"
|
|
44
62
|
}
|
|
45
63
|
}
|
package/src/junit.mjs
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const XML_BLOCK = /<testsuite\b[^>]*>|<\/testsuite>|<testcase\b[^>]*\/>|<testcase\b[^>]*>[\s\S]*?<\/testcase>/g;
|
|
2
|
+
const TESTSUITE_NAME_ATTR = /(<testsuite\b[^>]*\sname=")([^"]*)(")/;
|
|
3
|
+
const COMMENT = /<!--[\s\S]*?-->/g;
|
|
4
|
+
|
|
5
|
+
export function escapeXmlAttr(value) {
|
|
6
|
+
return String(value)
|
|
7
|
+
.replace(/&/g, "&")
|
|
8
|
+
.replace(/"/g, """)
|
|
9
|
+
.replace(/</g, "<")
|
|
10
|
+
.replace(/>/g, ">");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// describe() blocks can nest, and node:test's own junit reporter mirrors that by nesting
|
|
14
|
+
// <testsuite> inside <testsuite>; a flat top-level test() instead produces a bare <testcase>
|
|
15
|
+
// directly under <testsuites>, with no enclosing suite at all (called orphanTestcases).
|
|
16
|
+
function scanWorkspaceXml(xml) {
|
|
17
|
+
const suiteRanges = [];
|
|
18
|
+
const orphanTestcases = [];
|
|
19
|
+
let depth = 0;
|
|
20
|
+
let blockStart = null;
|
|
21
|
+
let match;
|
|
22
|
+
|
|
23
|
+
XML_BLOCK.lastIndex = 0;
|
|
24
|
+
while ((match = XML_BLOCK.exec(xml)) !== null) {
|
|
25
|
+
const token = match[0];
|
|
26
|
+
|
|
27
|
+
if (token === "</testsuite>") {
|
|
28
|
+
if (depth === 0) {
|
|
29
|
+
continue; // stray closing tag with no matching open; ignore defensively.
|
|
30
|
+
}
|
|
31
|
+
depth -= 1;
|
|
32
|
+
if (depth === 0) {
|
|
33
|
+
suiteRanges.push({ start: blockStart, end: match.index + token.length });
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (token.startsWith("<testsuite")) {
|
|
39
|
+
if (depth === 0) {
|
|
40
|
+
blockStart = match.index;
|
|
41
|
+
}
|
|
42
|
+
depth += 1;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// otherwise token is a <testcase> block (self-closing or with a <failure> child).
|
|
47
|
+
if (depth === 0) {
|
|
48
|
+
orphanTestcases.push(token);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { suiteRanges, orphanTestcases };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function extractTestsuites(xml, ranges = scanWorkspaceXml(xml).suiteRanges) {
|
|
56
|
+
return ranges.map(({ start, end }) => xml.slice(start, end));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function prefixTestsuiteName(block, prefix) {
|
|
60
|
+
if (!TESTSUITE_NAME_ATTR.test(block)) {
|
|
61
|
+
return block;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return block.replace(TESTSUITE_NAME_ATTR, (_match, open, name, close) => `${open}${escapeXmlAttr(prefix)} › ${name}${close}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function buildJunitReport(workspaces) {
|
|
68
|
+
const suites = workspaces.flatMap(({ name, xml }) => {
|
|
69
|
+
const cleaned = xml.replace(COMMENT, "");
|
|
70
|
+
const { suiteRanges, orphanTestcases } = scanWorkspaceXml(cleaned);
|
|
71
|
+
const namedSuites = extractTestsuites(cleaned, suiteRanges).map((block) => prefixTestsuiteName(block, name));
|
|
72
|
+
|
|
73
|
+
if (orphanTestcases.length === 0) {
|
|
74
|
+
return namedSuites;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return [...namedSuites, `<testsuite name="${escapeXmlAttr(name)}">\n${orphanTestcases.join("\n")}\n</testsuite>`];
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuites>\n${suites.join("\n")}\n</testsuites>\n`;
|
|
81
|
+
}
|
package/src/run.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
+
import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
3
5
|
import { promisify, styleText } from "node:util";
|
|
4
6
|
import path from "node:path";
|
|
5
7
|
|
|
8
|
+
import { buildJunitReport } from "./junit.mjs";
|
|
9
|
+
|
|
6
10
|
const execFileAsync = promisify(execFile);
|
|
7
11
|
|
|
8
12
|
const green = (str) => styleText("green", str);
|
|
@@ -15,9 +19,15 @@ const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).ex
|
|
|
15
19
|
|
|
16
20
|
const SPEC_REPORTER_FLAGS = "--test-reporter=spec --test-reporter-destination=stdout";
|
|
17
21
|
|
|
18
|
-
export function envWithSpecReporter(env) {
|
|
22
|
+
export function envWithSpecReporter(env, junitDestPath) {
|
|
19
23
|
const existing = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} ` : "";
|
|
20
|
-
|
|
24
|
+
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 (e.g.
|
|
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.
|
|
28
|
+
const rest = { ...env };
|
|
29
|
+
delete rest.NODE_TEST_CONTEXT;
|
|
30
|
+
return { ...rest, NODE_OPTIONS: `${existing}${SPEC_REPORTER_FLAGS}${junitFlags}` };
|
|
21
31
|
}
|
|
22
32
|
|
|
23
33
|
function readJson(file) {
|
|
@@ -84,13 +94,13 @@ export function formatSeconds(ms) {
|
|
|
84
94
|
return `${seconds.toFixed(1)}s`;
|
|
85
95
|
}
|
|
86
96
|
|
|
87
|
-
async function runWorkspaceScript(root, wsPath, scriptName) {
|
|
97
|
+
async function runWorkspaceScript(root, wsPath, scriptName, junitDestPath) {
|
|
88
98
|
const start = Date.now();
|
|
89
99
|
const options = {
|
|
90
100
|
cwd: root,
|
|
91
101
|
shell: process.platform === "win32",
|
|
92
102
|
maxBuffer: 20 * 1024 * 1024,
|
|
93
|
-
env: envWithSpecReporter(process.env)
|
|
103
|
+
env: envWithSpecReporter(process.env, junitDestPath)
|
|
94
104
|
};
|
|
95
105
|
|
|
96
106
|
let exitCode = 0;
|
|
@@ -113,10 +123,33 @@ async function runWorkspaceScript(root, wsPath, scriptName) {
|
|
|
113
123
|
failureDetails: exitCode === 0 ? null : extractFailureDetails(output),
|
|
114
124
|
durationMs: Date.now() - start,
|
|
115
125
|
counts: parseTestCounts(output),
|
|
116
|
-
failingTests: parseFailingTests(output)
|
|
126
|
+
failingTests: parseFailingTests(output),
|
|
127
|
+
junitDestPath
|
|
117
128
|
};
|
|
118
129
|
}
|
|
119
130
|
|
|
131
|
+
async function collectJunitEntries(results) {
|
|
132
|
+
const entries = [];
|
|
133
|
+
const missing = [];
|
|
134
|
+
|
|
135
|
+
for (const result of results) {
|
|
136
|
+
if (!result.junitDestPath) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
entries.push({ name: workspaceName(result.wsPath), xml: await readFile(result.junitDestPath, "utf8") });
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Either the workspace crashed before node:test's own junit reporter could write its
|
|
144
|
+
// file, or --script points at something that isn't node:test at all; skip it, but the
|
|
145
|
+
// caller still needs to know so it can tell the user the report is missing an entry.
|
|
146
|
+
missing.push(workspaceName(result.wsPath));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return { entries, missing };
|
|
151
|
+
}
|
|
152
|
+
|
|
120
153
|
function summaryRow(workspace, status, duration, counts) {
|
|
121
154
|
return {
|
|
122
155
|
workspace,
|
|
@@ -129,52 +162,75 @@ function summaryRow(workspace, status, duration, counts) {
|
|
|
129
162
|
};
|
|
130
163
|
}
|
|
131
164
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
165
|
+
function printWorkspaceResult(name, result) {
|
|
166
|
+
const seconds = formatSeconds(result.durationMs);
|
|
167
|
+
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
135
168
|
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
169
|
+
if (result.exitCode === 0) {
|
|
170
|
+
process.stdout.write(green(`✓ ${name}`) + dim(` ${seconds}${countsLabel}\n`));
|
|
171
|
+
return;
|
|
139
172
|
}
|
|
140
173
|
|
|
141
|
-
|
|
174
|
+
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
|
|
175
|
+
process.stdout.write(result.failureDetails + "\n");
|
|
176
|
+
process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir }) {
|
|
142
180
|
const results = [];
|
|
143
181
|
|
|
144
|
-
for (const wsPath of workspacesToRun) {
|
|
182
|
+
for (const [index, wsPath] of workspacesToRun.entries()) {
|
|
145
183
|
const name = workspaceName(wsPath);
|
|
146
184
|
process.stdout.write(dim(`running ${name}\n`));
|
|
147
185
|
|
|
186
|
+
const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
|
|
187
|
+
|
|
148
188
|
let result;
|
|
149
189
|
try {
|
|
150
|
-
result = await runWorkspaceScript(root, wsPath, scriptName);
|
|
190
|
+
result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath);
|
|
151
191
|
}
|
|
152
192
|
catch (error) {
|
|
153
193
|
console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
|
|
154
194
|
process.exit(1);
|
|
155
195
|
}
|
|
156
196
|
results.push(result);
|
|
197
|
+
printWorkspaceResult(name, result);
|
|
157
198
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (result.exitCode === 0) {
|
|
162
|
-
process.stdout.write(green(`✓ ${name}`) + dim(` ${seconds}${countsLabel}\n`));
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
|
|
166
|
-
process.stdout.write(result.failureDetails + "\n");
|
|
167
|
-
process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
|
|
168
|
-
|
|
169
|
-
if (ff) {
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
199
|
+
if (result.exitCode !== 0 && ff) {
|
|
200
|
+
break;
|
|
172
201
|
}
|
|
173
202
|
}
|
|
174
203
|
|
|
175
|
-
|
|
176
|
-
|
|
204
|
+
return results;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|
|
208
|
+
|
|
209
|
+
async function resolveJunitDestination(root, junitPath) {
|
|
210
|
+
const destination = path.resolve(root, junitPath);
|
|
211
|
+
const isExistingDirectory = await stat(destination).then((stats) => stats.isDirectory(), () => false);
|
|
212
|
+
|
|
213
|
+
return isExistingDirectory ? path.join(destination, DEFAULT_JUNIT_FILENAME) : destination;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function writeJunitReport(root, junitPath, results) {
|
|
217
|
+
const { entries, missing } = await collectJunitEntries(results);
|
|
218
|
+
const destination = await resolveJunitDestination(root, junitPath);
|
|
219
|
+
|
|
220
|
+
if (missing.length > 0) {
|
|
221
|
+
console.log(dim(`${missing.length} workspace(s) missing from the JUnit report: ${missing.join(", ")}`));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
await writeFile(destination, buildJunitReport(entries));
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
console.error(red(`Could not write JUnit report to "${destination}" (${error.message})`));
|
|
229
|
+
process.exitCode = 1;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
177
232
|
|
|
233
|
+
function printSummary(results, skipped) {
|
|
178
234
|
console.log(bold("\nSummary"));
|
|
179
235
|
console.table([
|
|
180
236
|
...results.map((result) => summaryRow(
|
|
@@ -189,18 +245,52 @@ export async function main({ root, scriptName, ff }) {
|
|
|
189
245
|
if (skipped.length > 0) {
|
|
190
246
|
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
|
191
247
|
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function reportOutcome(results) {
|
|
251
|
+
const failed = results.filter((result) => result.exitCode !== 0);
|
|
252
|
+
|
|
253
|
+
if (failed.length === 0) {
|
|
254
|
+
console.log(green(`${results.length}/${results.length} workspaces passed.`));
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
192
257
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
console.log(dim(` ✖ ${testName}`));
|
|
199
|
-
}
|
|
258
|
+
console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
|
|
259
|
+
for (const result of failed) {
|
|
260
|
+
console.log(red(` ${workspaceName(result.wsPath)}`));
|
|
261
|
+
for (const testName of result.failingTests) {
|
|
262
|
+
console.log(dim(` ✖ ${testName}`));
|
|
200
263
|
}
|
|
201
|
-
process.exitCode = 1;
|
|
202
264
|
}
|
|
203
|
-
|
|
204
|
-
|
|
265
|
+
process.exitCode = 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export async function main({ root, scriptName, ff, junitPath }) {
|
|
269
|
+
|
|
270
|
+
const { workspaces } = readJson(path.join(root, "package.json"));
|
|
271
|
+
|
|
272
|
+
if (!workspaces || workspaces.length === 0) {
|
|
273
|
+
console.info("Your project does not have any workspaces.");
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const workspacesToRun = listEligibleWorkspaces(root, workspaces, scriptName);
|
|
278
|
+
const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
|
|
279
|
+
|
|
280
|
+
let results;
|
|
281
|
+
try {
|
|
282
|
+
results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir });
|
|
283
|
+
|
|
284
|
+
if (junitDir) {
|
|
285
|
+
await writeJunitReport(root, junitPath, results);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
if (junitDir) {
|
|
290
|
+
await rm(junitDir, { recursive: true, force: true });
|
|
291
|
+
}
|
|
205
292
|
}
|
|
293
|
+
|
|
294
|
+
printSummary(results, workspacesToRun.slice(results.length));
|
|
295
|
+
reportOutcome(results);
|
|
206
296
|
}
|