sumlyzer 0.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/LICENSE +21 -0
- package/README.md +53 -0
- package/bin/sumlyzer.mjs +39 -0
- package/package.json +42 -0
- package/src/run.mjs +200 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Erwan Raulo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Sumlyzer
|
|
2
|
+
|
|
3
|
+
Run every npm workspace's test script, one by one. Passing workspaces output
|
|
4
|
+
to a single line; failing ones print only the relevant failure detail.
|
|
5
|
+
Ends with an aggregated pass/fail summary table, so nothing scrolls out of the terminal.
|
|
6
|
+
|
|
7
|
+
## Scope
|
|
8
|
+
|
|
9
|
+
This tool is intentionally narrow: **npm workspaces** running **`node:test`**.
|
|
10
|
+
It orchestrates `npm run <script> --workspace=<path>` for every workspace that
|
|
11
|
+
declares the target script, and it parses node test's own reporter output to build
|
|
12
|
+
the summary. It does not support pnpm/yarn workspaces or other test runners
|
|
13
|
+
(Jest, Vitest, Mocha etc.).
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npm install --save-dev sumlyzer
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npx sumlyzer [options]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Run from the root of an npm workspaces project (where `package.json` has a
|
|
28
|
+
`workspaces` field).
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
|
|
32
|
+
| Flag | Default | Description |
|
|
33
|
+
| --- | --- | --- |
|
|
34
|
+
| `--script <name>` | `test` | npm script to run per workspace |
|
|
35
|
+
| `--ff` | off | fail fast: stop at the first failing workspace |
|
|
36
|
+
| `-h, --help` | | print usage |
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Why
|
|
44
|
+
|
|
45
|
+
`npm run test --workspaces --if-present` runs every workspace but gives you
|
|
46
|
+
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. Turborepo
|
|
48
|
+
has the [same open issue](https://github.com/vercel/turborepo/issues/1368).
|
|
49
|
+
sumlyzer is a small, dependency-free tool that solves just this.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
package/bin/sumlyzer.mjs
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { main } from "../src/run.mjs";
|
|
6
|
+
|
|
7
|
+
let values;
|
|
8
|
+
try {
|
|
9
|
+
({ values } = parseArgs({
|
|
10
|
+
options: {
|
|
11
|
+
ff: { type: "boolean", default: false },
|
|
12
|
+
script: { type: "string", default: "test" },
|
|
13
|
+
help: { type: "boolean", short: "h", default: false }
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
19
|
+
console.error(`${error.message}. Run "sumlyzer --help" for usage.`);
|
|
20
|
+
}
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (values.help) {
|
|
25
|
+
console.log(`sumlyzer [options]
|
|
26
|
+
|
|
27
|
+
Runs each npm workspace's "${values.script}" script one by one. Passing
|
|
28
|
+
workspaces collapse to a single line; failing ones print only the relevant
|
|
29
|
+
failure detail. Ends with an aggregated pass/fail summary table.
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--script <name> npm script to run per workspace (default: "test")
|
|
33
|
+
--ff fail fast: stop at the first failing workspace
|
|
34
|
+
-h, --help show this help
|
|
35
|
+
`);
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await main({ root: path.resolve(process.cwd()), scriptName: values.script, ff: values.ff });
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sumlyzer",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sumlyzer": "bin/sumlyzer.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=22.0.0"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --test \"./test/*.spec.mjs\""
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"npm",
|
|
23
|
+
"test reporter",
|
|
24
|
+
"test summary",
|
|
25
|
+
"workspaces test summary",
|
|
26
|
+
"node test",
|
|
27
|
+
"test-runner",
|
|
28
|
+
"cli",
|
|
29
|
+
"fail-fast",
|
|
30
|
+
"summary"
|
|
31
|
+
],
|
|
32
|
+
"author": "Erwan Raulo",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/ErwanRaulo/sumlyzer.git"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/ErwanRaulo/sumlyzer/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/ErwanRaulo/sumlyzer#readme"
|
|
42
|
+
}
|
package/src/run.mjs
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { promisify, styleText } from "node:util";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
|
|
8
|
+
const green = (str) => styleText("green", str);
|
|
9
|
+
const red = (str) => styleText("red", str);
|
|
10
|
+
const dim = (str) => styleText("dim", str);
|
|
11
|
+
const bold = (str) => styleText("bold", str);
|
|
12
|
+
|
|
13
|
+
const COUNT_INDEX = 1;
|
|
14
|
+
const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).exec(output)?.[COUNT_INDEX];
|
|
15
|
+
|
|
16
|
+
const SPEC_REPORTER_FLAGS = "--test-reporter=spec --test-reporter-destination=stdout";
|
|
17
|
+
|
|
18
|
+
export function envWithSpecReporter(env) {
|
|
19
|
+
const existing = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} ` : "";
|
|
20
|
+
return { ...env, NODE_OPTIONS: `${existing}${SPEC_REPORTER_FLAGS}` };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function readJson(file) {
|
|
24
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function workspaceName(wsPath) {
|
|
28
|
+
return (wsPath ?? "").replace(/^workspaces[\\/]/, "");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function listWorkspaces(root, scriptName) {
|
|
32
|
+
const rootPkg = readJson(path.join(root, "package.json"));
|
|
33
|
+
|
|
34
|
+
return (rootPkg.workspaces ?? []).filter((wsPath) => {
|
|
35
|
+
const pkgFile = path.join(root, wsPath, "package.json");
|
|
36
|
+
try {
|
|
37
|
+
return Boolean(readJson(pkgFile).scripts?.[scriptName]);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function parseTestCounts(output) {
|
|
46
|
+
const tests = count("tests", output);
|
|
47
|
+
|
|
48
|
+
if (!tests) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
tests,
|
|
54
|
+
pass: count("pass", output) ?? "?",
|
|
55
|
+
fail: count("fail", output) ?? "?",
|
|
56
|
+
durationMs: count("duration_ms", output)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function parseFailingTests(output) {
|
|
61
|
+
const [, section] = output.split("✖ failing tests:");
|
|
62
|
+
if (!section) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return [...section.matchAll(/^✖ (.+) \([\d.]+ms\)$/gm)].map((match) => match[1]);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function stripNpmNoise(output) {
|
|
70
|
+
return output.replace(/^npm warn .*\n?/gm, "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function extractFailureDetails(output) {
|
|
74
|
+
const [, section] = output.split("✖ failing tests:");
|
|
75
|
+
if (!section) {
|
|
76
|
+
return output.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const details = section.split(/\n(?=npm )/)[0].trim();
|
|
80
|
+
|
|
81
|
+
return details.includes("'test failed'") ? output.trim() : details;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function formatSeconds(ms) {
|
|
85
|
+
const seconds = Number.isFinite(ms) ? ms / 1000 : 0;
|
|
86
|
+
return `${seconds.toFixed(1)}s`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function runWorkspaceScript(root, wsPath, scriptName) {
|
|
90
|
+
const start = Date.now();
|
|
91
|
+
const options = {
|
|
92
|
+
cwd: root,
|
|
93
|
+
shell: process.platform === "win32",
|
|
94
|
+
maxBuffer: 20 * 1024 * 1024,
|
|
95
|
+
env: envWithSpecReporter(process.env)
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
let exitCode = 0;
|
|
99
|
+
let output;
|
|
100
|
+
try {
|
|
101
|
+
const { stdout, stderr } = await execFileAsync("npm", ["run", scriptName, "--workspace=" + wsPath], options);
|
|
102
|
+
output = stripNpmNoise(stdout + stderr);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (typeof error.code !== "number") {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
exitCode = error.code;
|
|
109
|
+
output = stripNpmNoise((error.stdout ?? "") + (error.stderr ?? ""));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
wsPath,
|
|
114
|
+
exitCode,
|
|
115
|
+
failureDetails: exitCode === 0 ? null : extractFailureDetails(output),
|
|
116
|
+
durationMs: Date.now() - start,
|
|
117
|
+
counts: parseTestCounts(output),
|
|
118
|
+
failingTests: parseFailingTests(output)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function summaryRow(workspace, status, duration, counts) {
|
|
123
|
+
return {
|
|
124
|
+
workspace,
|
|
125
|
+
status,
|
|
126
|
+
duration,
|
|
127
|
+
testsDuration: counts?.durationMs ? formatSeconds(Number(counts.durationMs)) : "-",
|
|
128
|
+
tests: counts?.tests ?? "-",
|
|
129
|
+
pass: counts?.pass ?? "-",
|
|
130
|
+
fail: counts?.fail ?? "-"
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function main({ root, scriptName, ff }) {
|
|
135
|
+
const workspaces = listWorkspaces(root, scriptName);
|
|
136
|
+
const results = [];
|
|
137
|
+
|
|
138
|
+
for (const wsPath of workspaces) {
|
|
139
|
+
const name = workspaceName(wsPath);
|
|
140
|
+
process.stdout.write(dim(`running ${name}\n`));
|
|
141
|
+
|
|
142
|
+
let result;
|
|
143
|
+
try {
|
|
144
|
+
result = await runWorkspaceScript(root, wsPath, scriptName);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
results.push(result);
|
|
151
|
+
|
|
152
|
+
const seconds = formatSeconds(result.durationMs);
|
|
153
|
+
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
154
|
+
|
|
155
|
+
if (result.exitCode === 0) {
|
|
156
|
+
process.stdout.write(green(`✓ ${name}`) + dim(` ${seconds}${countsLabel}\n`));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
|
|
160
|
+
process.stdout.write(result.failureDetails + "\n");
|
|
161
|
+
process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
|
|
162
|
+
|
|
163
|
+
if (ff) {
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const failed = results.filter((result) => result.exitCode !== 0);
|
|
170
|
+
const skipped = workspaces.slice(results.length);
|
|
171
|
+
|
|
172
|
+
console.log(bold("\nSummary"));
|
|
173
|
+
console.table([
|
|
174
|
+
...results.map((result) => summaryRow(
|
|
175
|
+
workspaceName(result.wsPath),
|
|
176
|
+
result.exitCode === 0 ? "PASS" : "FAIL",
|
|
177
|
+
formatSeconds(result.durationMs),
|
|
178
|
+
result.counts
|
|
179
|
+
)),
|
|
180
|
+
...skipped.map((wsPath) => summaryRow(workspaceName(wsPath), "SKIPPED", "-", null))
|
|
181
|
+
]);
|
|
182
|
+
|
|
183
|
+
if (skipped.length > 0) {
|
|
184
|
+
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (failed.length > 0) {
|
|
188
|
+
console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
|
|
189
|
+
for (const result of failed) {
|
|
190
|
+
console.log(red(` ${workspaceName(result.wsPath)}`));
|
|
191
|
+
for (const testName of result.failingTests) {
|
|
192
|
+
console.log(dim(` ✖ ${testName}`));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
process.exitCode = 1;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
console.log(green(`${results.length}/${results.length} workspaces passed.`));
|
|
199
|
+
}
|
|
200
|
+
}
|