sumlyzer 0.5.1 → 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 CHANGED
@@ -11,8 +11,12 @@
11
11
  <a href="./LICENSE"><img src="https://img.shields.io/npm/l/sumlyzer.svg" alt="license" /></a>
12
12
  </p>
13
13
 
14
+ ## Ever lost a failing test in thousands of lines of workspace output?
15
+
16
+ ## Ever wished your npm workspaces stopped at the first failure?
17
+
14
18
  `npm run test --workspaces --if-present` runs every workspace, but gives you no
15
- aggregated summary and no way to fail fast — an early failure just scrolls off
19
+ aggregated summary and no way to fail fast, an early failure just scrolls off
16
20
  screen once later workspaces print their own output.
17
21
 
18
22
  Sumlyzer runs each workspace's test script, one by one or concurrently.
@@ -110,18 +114,17 @@ Summary
110
114
 
111
115
  | Column | Meaning |
112
116
  | --------------- | ------------------------------------------------------------------------------------------------ |
113
- | `(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 |
114
- | `status` | `PASS`, `FAIL`, or `SKIPPED` (only reached when `--ff` stopped scheduling before this workspace ran) |
117
+ | `(index)` | Workspace name |
118
+ | `status` | `PASS`, `FAIL`, or `SKIPPED` (reached when `--ff` stopped scheduling before this workspace ran) |
115
119
  | `duration` | Wall-clock time for the whole `npm run <script> --workspace=<path>` process, including npm/spawn overhead |
116
- | `testsDuration` | `duration_ms` as reported by node's own test runner — the actual test execution time, without the npm overhead |
120
+ | `testsDuration` | `duration_ms` as reported by node's own test runner |
117
121
  | `tests` | Total number of tests node:test ran in that workspace |
118
122
  | `pass` | Number of passing tests |
119
123
  | `fail` | Number of failing tests |
120
124
  | `skip` | Tests reported as skipped (`ℹ skipped`), e.g. `t.skip()` or `{ skip: true }` |
121
- | `todo` | Tests reported as todo (`ℹ todo`), e.g. `t.todo()` — intentionally not implemented yet, distinct from `skip` |
122
- | `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 |
125
+ | `todo` | Tests reported as todo (`ℹ todo`), e.g. `t.todo()` |
126
+ | `cancelled` | Tests reported as cancelled (`ℹ cancelled`), unlike `skip`/`todo` this usually signals a real problem |
123
127
 
124
- `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.
125
128
 
126
129
  ### On failure
127
130
 
@@ -225,7 +228,7 @@ workspace already running when the failure is detected runs to completion
225
228
  This fail-fast behavior at the `--workspaces` level has been requested from
226
229
  npm more than once: [npm/rfcs#575](https://github.com/npm/rfcs/issues/575)
227
230
  (open) and [npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed).
228
- Until it lands, sumlyzer's `--ff` flag gets you there — see also this
231
+ Until it lands, sumlyzer's `--ff` flag gets you there, see also this
229
232
  [Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284)
230
233
  on the same problem.
231
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 values;
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
- 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.`);
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
- if (values.help) {
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 "${values.script}" script, ${concurrency > 1 ? `${concurrency} at a time` : "one by one"}. Passing
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: values.script,
52
- ff: values.ff,
53
- junitPath: values.junit,
58
+ scriptName: args.script,
59
+ ff: args.ff,
60
+ junitPath: args.junit,
54
61
  concurrency
55
62
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumlyzer",
3
- "version": "0.5.1",
3
+ "version": "0.6.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": {
@@ -24,25 +24,19 @@
24
24
  "release": "npm publish --dry-run"
25
25
  },
26
26
  "keywords": [
27
- "npm",
28
- "test reporter",
29
- "test summary",
30
- "workspaces test summary",
31
- "node test",
32
- "test-runner",
27
+ "npm workspaces test output",
28
+ "npm workspaces logs",
29
+ "node test runner",
30
+ "node --test",
31
+ "monorepo test output",
32
+ "workspace test logs",
33
+ "parallel test output",
34
+ "npm test readability",
33
35
  "cli",
34
- "fail-fast",
35
- "summary",
36
- "npm-workspaces",
37
- "monorepo",
38
- "test-reporter",
39
- "node-test",
40
- "node:test",
41
- "test-summary",
42
- "ci",
43
36
  "junit",
44
37
  "junit-xml",
45
- "github-actions"
38
+ "github-actions",
39
+ "monorepo"
46
40
  ],
47
41
  "author": {
48
42
  "name": "Erwan Raulo",
@@ -1,10 +1,19 @@
1
1
  const COUNT_INDEX = 1;
2
- const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).exec(output)?.[COUNT_INDEX];
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("tests", output);
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("pass", output) ?? "?",
16
- fail: count("fail", output) ?? "?",
17
- skip: count("skipped", output) ?? "0",
18
- todo: count("todo", output) ?? "0",
19
- cancelled: count("cancelled", output) ?? "0",
20
- durationMs: count("duration_ms", output)
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(output) {
25
- const [, section] = output.split("✖ failing tests:");
26
- if (!section) {
33
+ export function parseFailingTests(failureSection) {
34
+ if (!failureSection) {
27
35
  return [];
28
36
  }
29
37
 
30
- return [...section.matchAll(/^✖ (.+) \([\d.]+ms\)$/gm)].map((match) => match[1]);
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
- const [, section] = output.split("✖ failing tests:");
39
- if (!section) {
45
+ export function extractFailureDetails(output, failureSection) {
46
+ if (!failureSection) {
40
47
  return output.trim();
41
48
  }
42
49
 
43
- const details = section.split(/\n(?=npm )/)[0].trim();
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(output),
74
+ failingTests: parseFailingTests(failureSection),
71
75
  junitDestPath,
72
76
  rawOutput: output
73
77
  };