sumlyzer 0.5.2 → 0.6.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 +2 -2
- package/bin/sumlyzer.mjs +17 -10
- package/package.json +1 -1
- package/src/parseOutput.mjs +23 -16
- package/src/run.mjs +6 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
## Ever wished your npm workspaces stopped at the first failure?
|
|
17
17
|
|
|
18
18
|
`npm run test --workspaces --if-present` runs every workspace, but gives you no
|
|
19
|
-
aggregated summary and no way to fail fast
|
|
19
|
+
aggregated summary and no way to fail fast, an early failure just scrolls off
|
|
20
20
|
screen once later workspaces print their own output.
|
|
21
21
|
|
|
22
22
|
Sumlyzer runs each workspace's test script, one by one or concurrently.
|
|
@@ -228,7 +228,7 @@ workspace already running when the failure is detected runs to completion
|
|
|
228
228
|
This fail-fast behavior at the `--workspaces` level has been requested from
|
|
229
229
|
npm more than once: [npm/rfcs#575](https://github.com/npm/rfcs/issues/575)
|
|
230
230
|
(open) and [npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed).
|
|
231
|
-
Until it lands, sumlyzer's `--ff` flag gets you there
|
|
231
|
+
Until it lands, sumlyzer's `--ff` flag gets you there, see also this
|
|
232
232
|
[Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284)
|
|
233
233
|
on the same problem.
|
|
234
234
|
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { parseArgs } from "node:util";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { availableParallelism } from "node:os";
|
|
4
5
|
|
|
5
6
|
import { main } from "../src/run.mjs";
|
|
6
7
|
|
|
7
|
-
let
|
|
8
|
+
let args;
|
|
8
9
|
try {
|
|
9
|
-
({ values } = parseArgs({
|
|
10
|
+
({ values: args } = parseArgs({
|
|
10
11
|
options: {
|
|
11
12
|
ff: { type: "boolean", default: false },
|
|
12
13
|
script: { type: "string", default: "test" },
|
|
@@ -23,16 +24,22 @@ catch (error) {
|
|
|
23
24
|
process.exit(1);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
if (!Number.isInteger(concurrency) || concurrency < 1 || String(concurrency) !==
|
|
28
|
-
console.info(`--concurrency must be a positive integer, got "${
|
|
27
|
+
let concurrency = Number.parseInt(args.concurrency, 10);
|
|
28
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || String(concurrency) !== args.concurrency) {
|
|
29
|
+
console.info(`--concurrency must be a positive integer, got "${args.concurrency}". Run "sumlyzer --help" for usage.`);
|
|
29
30
|
process.exit(1);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
const maxConcurrency = availableParallelism();
|
|
34
|
+
if (concurrency > maxConcurrency) {
|
|
35
|
+
console.info(`--concurrency ${concurrency} exceeds the available parallelism (${maxConcurrency}), clamping to ${maxConcurrency}.`);
|
|
36
|
+
concurrency = maxConcurrency;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (args.help) {
|
|
33
40
|
console.log(`sumlyzer [options]
|
|
34
41
|
|
|
35
|
-
Runs each npm workspace's "${
|
|
42
|
+
Runs each npm workspace's "${args.script}" script, ${concurrency > 1 ? `${concurrency} at a time` : "one by one"}. Passing
|
|
36
43
|
workspaces collapse to a single line; failing ones print only the relevant
|
|
37
44
|
failure detail. Ends with an aggregated pass/fail summary table.
|
|
38
45
|
|
|
@@ -48,8 +55,8 @@ Options:
|
|
|
48
55
|
|
|
49
56
|
await main({
|
|
50
57
|
root: path.resolve(process.cwd()),
|
|
51
|
-
scriptName:
|
|
52
|
-
ff:
|
|
53
|
-
junitPath:
|
|
58
|
+
scriptName: args.script,
|
|
59
|
+
ff: args.ff,
|
|
60
|
+
junitPath: args.junit,
|
|
54
61
|
concurrency
|
|
55
62
|
});
|
package/package.json
CHANGED
package/src/parseOutput.mjs
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
const COUNT_INDEX = 1;
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
const countTestsRegex = new RegExp(String.raw`ℹ tests (\d+)`);
|
|
4
|
+
const countPassRegex = new RegExp(String.raw`ℹ pass (\d+)`);
|
|
5
|
+
const countFailRegex = new RegExp(String.raw`ℹ fail (\d+)`);
|
|
6
|
+
const countSkippedRegex = new RegExp(String.raw`ℹ skipped (\d+)`);
|
|
7
|
+
const countTodoRegex = new RegExp(String.raw`ℹ todo (\d+)`);
|
|
8
|
+
const countCancelledRegex = new RegExp(String.raw`ℹ cancelled (\d+)`);
|
|
9
|
+
const countDurationRegex = new RegExp(String.raw`ℹ duration_ms (\d+)`);
|
|
10
|
+
|
|
11
|
+
const count = (regex, output) => regex.exec(output)?.[COUNT_INDEX];
|
|
3
12
|
|
|
4
13
|
// skip/todo/cancelled fall back to "0" rather than "?": unlike pass/fail, a missing
|
|
5
14
|
// line here is far more likely to mean "zero" than "parsing went wrong somehow".
|
|
6
15
|
export function parseTestCounts(output) {
|
|
7
|
-
const tests = count(
|
|
16
|
+
const tests = count(countTestsRegex, output);
|
|
8
17
|
|
|
9
18
|
if (!tests) {
|
|
10
19
|
return null;
|
|
@@ -12,35 +21,33 @@ export function parseTestCounts(output) {
|
|
|
12
21
|
|
|
13
22
|
return {
|
|
14
23
|
tests,
|
|
15
|
-
pass: count(
|
|
16
|
-
fail: count(
|
|
17
|
-
skip: count(
|
|
18
|
-
todo: count(
|
|
19
|
-
cancelled: count(
|
|
20
|
-
durationMs: count(
|
|
24
|
+
pass: count(countPassRegex, output) ?? "?",
|
|
25
|
+
fail: count(countFailRegex, output) ?? "?",
|
|
26
|
+
skip: count(countSkippedRegex, output) ?? "0",
|
|
27
|
+
todo: count(countTodoRegex, output) ?? "0",
|
|
28
|
+
cancelled: count(countCancelledRegex, output) ?? "0",
|
|
29
|
+
durationMs: count(countDurationRegex, output)
|
|
21
30
|
};
|
|
22
31
|
}
|
|
23
32
|
|
|
24
|
-
export function parseFailingTests(
|
|
25
|
-
|
|
26
|
-
if (!section) {
|
|
33
|
+
export function parseFailingTests(failureSection) {
|
|
34
|
+
if (!failureSection) {
|
|
27
35
|
return [];
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
return [...
|
|
38
|
+
return [...failureSection.matchAll(/^✖ (.+) \([\d.]+ms\)$/gm)].map((match) => match[1]);
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export function stripNpmNoise(output) {
|
|
34
42
|
return output.replace(/^npm warn .*\n?/gm, "");
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
export function extractFailureDetails(output) {
|
|
38
|
-
|
|
39
|
-
if (!section) {
|
|
45
|
+
export function extractFailureDetails(output, failureSection) {
|
|
46
|
+
if (!failureSection) {
|
|
40
47
|
return output.trim();
|
|
41
48
|
}
|
|
42
49
|
|
|
43
|
-
const details =
|
|
50
|
+
const details = failureSection.split(/\n(?=npm )/)[0].trim();
|
|
44
51
|
|
|
45
52
|
return details.includes("'test failed'") ? output.trim() : details;
|
|
46
53
|
}
|
package/src/run.mjs
CHANGED
|
@@ -22,6 +22,8 @@ export function envWithSpecReporter(env, junitDestPath) {
|
|
|
22
22
|
return { ...rest, NODE_OPTIONS: `${existing}${SPEC_REPORTER_FLAGS}${junitFlags}` };
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// Rethink this synchronous approach in case of very large package.json files, or huge amount of workspaces,
|
|
26
|
+
// but for now it's simpler than async and should be fine in practice.
|
|
25
27
|
function readJson(file) {
|
|
26
28
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
27
29
|
}
|
|
@@ -61,13 +63,15 @@ async function runWorkspaceScript(root, wsPath, scriptName, junitDestPath) {
|
|
|
61
63
|
output = stripNpmNoise((error.stdout ?? "") + (error.stderr ?? ""));
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
const [, failureSection] = output.split("✖ failing tests:");
|
|
67
|
+
|
|
64
68
|
return {
|
|
65
69
|
wsPath,
|
|
66
70
|
exitCode,
|
|
67
|
-
failureDetails: exitCode === 0 ? null : extractFailureDetails(output),
|
|
71
|
+
failureDetails: exitCode === 0 ? null : extractFailureDetails(output, failureSection),
|
|
68
72
|
durationMs: Date.now() - start,
|
|
69
73
|
counts: parseTestCounts(output),
|
|
70
|
-
failingTests: parseFailingTests(
|
|
74
|
+
failingTests: parseFailingTests(failureSection),
|
|
71
75
|
junitDestPath,
|
|
72
76
|
rawOutput: output
|
|
73
77
|
};
|