sumlyzer 1.3.1 → 1.4.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/CHANGELOG.md +112 -0
- package/README.md +9 -2
- package/bin/sumlyzer.mjs +11 -1
- package/package.json +11 -5
- package/src/changed.mjs +3 -1
- package/src/graph.mjs +60 -0
- package/src/run.mjs +81 -17
- package/src/testEventReporter.mjs +3 -7
- package/src/watch.mjs +44 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based
|
|
4
|
+
on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [1.4.1] - 2026-11-25
|
|
10
|
+
|
|
11
|
+
### Security
|
|
12
|
+
|
|
13
|
+
- `--ref` can no longer be parsed by `git diff` as an option or a pathspec.
|
|
14
|
+
A value such as `--ref=--output=<file>` used to make git create or
|
|
15
|
+
overwrite `<file>`, and a ref matching a file name was silently treated as
|
|
16
|
+
a path ([#46](https://github.com/ErwanRaulo/sumlyzer/pull/46)).
|
|
17
|
+
- Bump `glob` to `^14.0.6` (runtime) and dev dependencies to clear the
|
|
18
|
+
`glob`, `minimatch`, `brace-expansion` and `fast-xml-parser` advisories
|
|
19
|
+
reported by `npm audit` ([#43](https://github.com/ErwanRaulo/sumlyzer/pull/43)).
|
|
20
|
+
|
|
21
|
+
### Documentation
|
|
22
|
+
|
|
23
|
+
- Add this changelog, a CI badge and a security section to the README.
|
|
24
|
+
- Fix outdated statements in `SECURITY.md` and `CONTRIBUTING.md`.
|
|
25
|
+
|
|
26
|
+
## [1.4.0] - 2026-09-08
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- `--watch` mode: re-runs changed workspaces and the workspaces that depend
|
|
31
|
+
on them ([#26](https://github.com/ErwanRaulo/sumlyzer/pull/26)).
|
|
32
|
+
|
|
33
|
+
## [1.3.1]
|
|
34
|
+
|
|
35
|
+
No release notes, see the [diff](https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.0...v1.3.1).
|
|
36
|
+
|
|
37
|
+
## [1.3.0] - 2026-09-03
|
|
38
|
+
|
|
39
|
+
### Added
|
|
40
|
+
|
|
41
|
+
- `--changed` / `--ref`: only run workspaces with changes, via git diff
|
|
42
|
+
([#18](https://github.com/ErwanRaulo/sumlyzer/pull/18)).
|
|
43
|
+
- Support npm `pre`/`post` lifecycle hooks of the test script
|
|
44
|
+
([#20](https://github.com/ErwanRaulo/sumlyzer/pull/20)).
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
- Spawn fewer processes per workspace ([#19](https://github.com/ErwanRaulo/sumlyzer/pull/19)).
|
|
49
|
+
|
|
50
|
+
## [1.2.0] - 2026-08-20
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
|
|
54
|
+
- Skip/todo/cancelled counts moved to a footnote; duplicate duration and
|
|
55
|
+
test-count output removed.
|
|
56
|
+
- Internal refactor of workspace listing, output capture and run loop.
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- README example of sumlyzer's output.
|
|
61
|
+
|
|
62
|
+
## [1.1.0] - 2026-08-19
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
|
|
66
|
+
- Resolve `workspaces` glob patterns.
|
|
67
|
+
- Clear message when no workspace is eligible.
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
|
|
71
|
+
- Runner logic decoupled from `node:test`.
|
|
72
|
+
- More reliable skipped-workspace count.
|
|
73
|
+
|
|
74
|
+
## [1.0.1] - 2026-08-11
|
|
75
|
+
|
|
76
|
+
### Added
|
|
77
|
+
|
|
78
|
+
- Own `node:test` reporter; workspaces using a custom reporter are detected.
|
|
79
|
+
- All workspaces with an invalid `package.json` are listed at once.
|
|
80
|
+
|
|
81
|
+
### Changed
|
|
82
|
+
|
|
83
|
+
- Output read as stream chunks instead of being buffered in memory.
|
|
84
|
+
|
|
85
|
+
### Fixed
|
|
86
|
+
|
|
87
|
+
- Child processes are cleaned up properly instead of being killed mid-flight.
|
|
88
|
+
|
|
89
|
+
## [1.0.0]
|
|
90
|
+
|
|
91
|
+
No release notes, see the [diff](https://github.com/ErwanRaulo/sumlyzer/compare/v0.6.0...v1.0.0).
|
|
92
|
+
|
|
93
|
+
## [0.6.0] - 2026-08-05
|
|
94
|
+
|
|
95
|
+
### Changed
|
|
96
|
+
|
|
97
|
+
- `--concurrency` is clamped to the OS available parallelism.
|
|
98
|
+
- Fewer regex instances and less string splitting when parsing large outputs.
|
|
99
|
+
|
|
100
|
+
Earlier versions (`0.1.1` to `0.5.3`) have no release notes, see the
|
|
101
|
+
[tags](https://github.com/ErwanRaulo/sumlyzer/tags).
|
|
102
|
+
|
|
103
|
+
[Unreleased]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.4.1...HEAD
|
|
104
|
+
[1.4.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.4.0...v1.4.1
|
|
105
|
+
[1.4.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.1...v1.4.0
|
|
106
|
+
[1.3.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.3.0...v1.3.1
|
|
107
|
+
[1.3.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.2.0...v1.3.0
|
|
108
|
+
[1.2.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.1.0...v1.2.0
|
|
109
|
+
[1.1.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.0.1...v1.1.0
|
|
110
|
+
[1.0.1]: https://github.com/ErwanRaulo/sumlyzer/compare/v1.0.0...v1.0.1
|
|
111
|
+
[1.0.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v0.6.0...v1.0.0
|
|
112
|
+
[0.6.0]: https://github.com/ErwanRaulo/sumlyzer/compare/v0.5.3...v0.6.0
|
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<h1 align="center">Sumlyzer</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
+
<a href="https://github.com/ErwanRaulo/sumlyzer/actions/workflows/ci.yml"><img src="https://github.com/ErwanRaulo/sumlyzer/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
8
9
|
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/v/sumlyzer.svg" alt="npm version" /></a>
|
|
9
10
|
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/dm/sumlyzer.svg" alt="npm downloads" /></a>
|
|
10
11
|
<a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/node/v/sumlyzer.svg" alt="node engine" /></a>
|
|
@@ -43,6 +44,7 @@ Run from the root of an npm workspaces project.
|
|
|
43
44
|
| `--changed` | off | only run workspaces with changed files |
|
|
44
45
|
| `--junit <path>` | off | write an aggregated JUnit XML report |
|
|
45
46
|
| `--ref <ref>` | auto-detect | git ref to diff against for `--changed` |
|
|
47
|
+
| `-w, --watch` | off | re-run on file change (can't be combined with `--junit`) |
|
|
46
48
|
| `-h, --help` | | print usage |
|
|
47
49
|
|
|
48
50
|
Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight into CI.
|
|
@@ -65,6 +67,7 @@ Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight
|
|
|
65
67
|
- **GitHub Actions**: on `GITHUB_ACTIONS=true`, each workspace's output is auto-wrapped in a collapsible `::group::` block. No other CI provider has folding support yet.
|
|
66
68
|
- **Concurrency** (`--concurrency <n>`): workspaces finish in whatever order they complete, so output interleaves. With `--ff`, only workspaces that haven't started yet are skipped — in-flight ones run to completion.
|
|
67
69
|
- **Changed workspaces** (`--changed`): maps changed files to the workspace directory containing them. Ref auto-detection: uncommitted changes → diff against `HEAD`; clean tree with upstream → merge-base with upstream; clean tree with no upstream → `HEAD`.
|
|
70
|
+
- **Watch mode** (`--watch`): runs once, then keeps watching the workspaces directories. Re-runs the workspace that changed, plus every workspace of the same project that depends on it, directly or transitively, through `dependencies`/`devDependencies`. `node_modules`, `.git`, `coverage`, and dotfiles are ignored. Stop with `Ctrl+C`. Not compatible with `--junit`.
|
|
68
71
|
- Own `--test-reporter` in a workspace's script is detected ahead of time and that workspace is skipped, to avoid colliding with sumlyzer's own reporter.
|
|
69
72
|
|
|
70
73
|
npm doesn't have native fail-fast on `--workspaces` yet — discussed in
|
|
@@ -75,11 +78,15 @@ Sumlyzer's `--ff` gets you there in the meantime.
|
|
|
75
78
|
|
|
76
79
|
## Roadmap
|
|
77
80
|
|
|
78
|
-
**
|
|
81
|
+
**MCP server**: allow LLM agents to run the fail fast mode on any project organized with npm workspaces.
|
|
79
82
|
|
|
80
83
|
## Contributing
|
|
81
84
|
|
|
82
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
85
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md). Release history is in [CHANGELOG.md](./CHANGELOG.md).
|
|
86
|
+
|
|
87
|
+
## Security
|
|
88
|
+
|
|
89
|
+
Please report vulnerabilities privately, see [SECURITY.md](./SECURITY.md).
|
|
83
90
|
|
|
84
91
|
## License
|
|
85
92
|
|
package/bin/sumlyzer.mjs
CHANGED
|
@@ -21,6 +21,7 @@ try {
|
|
|
21
21
|
concurrency: { type: "string", short: "c", default: "1" },
|
|
22
22
|
changed: { type: "boolean", default: false },
|
|
23
23
|
ref: { type: "string" },
|
|
24
|
+
watch: { type: "boolean", short: "w", default: false },
|
|
24
25
|
help: { type: "boolean", short: "h", default: false }
|
|
25
26
|
}
|
|
26
27
|
}));
|
|
@@ -49,6 +50,11 @@ if (args.ref && !args.changed) {
|
|
|
49
50
|
process.exit(1);
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
if (args.watch && args.junit) {
|
|
54
|
+
console.info(`--watch and --junit can't be combined. Run "sumlyzer --help" for usage.`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
if (args.help) {
|
|
53
59
|
console.log(`sumlyzer [options]
|
|
54
60
|
|
|
@@ -63,6 +69,9 @@ Options:
|
|
|
63
69
|
-c, --concurrency <n> run up to <n> workspaces at once (default: 1)
|
|
64
70
|
--changed only run workspaces with changes (git ref auto-detected, see --ref)
|
|
65
71
|
--ref <ref> git ref to diff against for --changed (default: auto-detect)
|
|
72
|
+
-w, --watch re-run on file change, only for changed workspaces
|
|
73
|
+
and the ones that depend on them (can't be combined
|
|
74
|
+
with --junit)
|
|
66
75
|
-h, --help show this help
|
|
67
76
|
`);
|
|
68
77
|
process.exit(0);
|
|
@@ -76,7 +85,8 @@ try {
|
|
|
76
85
|
junitPath: args.junit,
|
|
77
86
|
concurrency,
|
|
78
87
|
changed: args.changed,
|
|
79
|
-
ref: args.ref
|
|
88
|
+
ref: args.ref,
|
|
89
|
+
watch: args.watch
|
|
80
90
|
});
|
|
81
91
|
}
|
|
82
92
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sumlyzer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"bin",
|
|
11
11
|
"src",
|
|
12
12
|
"README.md",
|
|
13
|
+
"CHANGELOG.md",
|
|
13
14
|
"LICENSE"
|
|
14
15
|
],
|
|
15
16
|
"engines": {
|
|
@@ -53,11 +54,16 @@
|
|
|
53
54
|
},
|
|
54
55
|
"homepage": "https://github.com/ErwanRaulo/sumlyzer#readme",
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@nodesecure/js-x-ray": "^16.
|
|
57
|
-
"@types/node": "^26.
|
|
58
|
-
"fast-xml-parser": "^5.
|
|
57
|
+
"@nodesecure/js-x-ray": "^16.2.0",
|
|
58
|
+
"@types/node": "^26.6.10",
|
|
59
|
+
"fast-xml-parser": "^5.12.1"
|
|
59
60
|
},
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"glob": "^
|
|
62
|
+
"glob": "^14.0.6"
|
|
63
|
+
},
|
|
64
|
+
"overrides": {
|
|
65
|
+
"@typescript-eslint/typescript-estree": {
|
|
66
|
+
"minimatch": "^11.0.1"
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
}
|
package/src/changed.mjs
CHANGED
|
@@ -21,7 +21,9 @@ function tryGit(root, args) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function getChangedFiles(root, ref) {
|
|
24
|
-
|
|
24
|
+
// --end-of-options keeps a ref like "--output=<file>" from being parsed as an
|
|
25
|
+
// option, the trailing "--" keeps it from being parsed as a pathspec.
|
|
26
|
+
const tracked = runGit(root, ["diff", "--name-only", "--end-of-options", ref, "--"], ref);
|
|
25
27
|
const untracked = runGit(root, ["ls-files", "--others", "--exclude-standard"], ref);
|
|
26
28
|
|
|
27
29
|
return [...new Set([...tracked, ...untracked])];
|
package/src/graph.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
function readJson(file) {
|
|
5
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function buildDependentsGraph(root, workspaces) {
|
|
9
|
+
const nameToPath = new Map();
|
|
10
|
+
const depsByPath = new Map();
|
|
11
|
+
|
|
12
|
+
for (const wsPath of workspaces) {
|
|
13
|
+
let pkg;
|
|
14
|
+
try {
|
|
15
|
+
pkg = readJson(path.join(root, wsPath, "package.json"));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (pkg.name) {
|
|
22
|
+
nameToPath.set(pkg.name, wsPath);
|
|
23
|
+
}
|
|
24
|
+
depsByPath.set(wsPath, { ...pkg.dependencies, ...pkg.devDependencies });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const dependents = new Map(workspaces.map((wsPath) => [wsPath, new Set()]));
|
|
28
|
+
|
|
29
|
+
for (const [wsPath, deps] of depsByPath) {
|
|
30
|
+
for (const depName of Object.keys(deps)) {
|
|
31
|
+
const depPath = nameToPath.get(depName);
|
|
32
|
+
if (depPath && depPath !== wsPath) {
|
|
33
|
+
dependents.get(depPath).add(wsPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return dependents;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function expandWithDependents(changedPaths, dependentsGraph) {
|
|
42
|
+
const result = new Set();
|
|
43
|
+
const queue = [...changedPaths];
|
|
44
|
+
|
|
45
|
+
while (queue.length > 0) {
|
|
46
|
+
const wsPath = queue.pop();
|
|
47
|
+
if (result.has(wsPath)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
result.add(wsPath);
|
|
51
|
+
|
|
52
|
+
for (const dependent of dependentsGraph.get(wsPath) ?? []) {
|
|
53
|
+
if (!result.has(dependent)) {
|
|
54
|
+
queue.push(dependent);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
package/src/run.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import path from "node:path";
|
|
|
7
7
|
import { glob } from "glob";
|
|
8
8
|
|
|
9
9
|
import { buildJunitReport } from "./junit.mjs";
|
|
10
|
+
import { buildDependentsGraph, expandWithDependents } from "./graph.mjs";
|
|
11
|
+
import { watchWorkspaces } from "./watch.mjs";
|
|
10
12
|
import { red, dim, workspaceName, githubGroupSyntax, printWorkspaceResult, printSummary, reportOutcome } from "./reporter.mjs";
|
|
11
13
|
import { NoWorkspacesError, InvalidPackageJsonError, WorkspaceLaunchError } from "./errors.mjs";
|
|
12
14
|
import { hasOwnReporter, prepareEnv, parseResult } from "./runners/nodeTest.mjs";
|
|
@@ -389,7 +391,82 @@ async function writeJunitReport(root, junitPath, results) {
|
|
|
389
391
|
}
|
|
390
392
|
}
|
|
391
393
|
|
|
392
|
-
|
|
394
|
+
async function runOnce({ root, workspacesToRun, scriptName, scriptCommands, ff, junitPath, concurrency }) {
|
|
395
|
+
const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
|
|
396
|
+
|
|
397
|
+
let completed, skipped;
|
|
398
|
+
try {
|
|
399
|
+
({ completed, skipped } = await runWorkspaces({ root, workspacesToRun, scriptName, scriptCommands, ff, junitDir, concurrency }));
|
|
400
|
+
|
|
401
|
+
if (junitDir) {
|
|
402
|
+
await writeJunitReport(root, junitPath, completed);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
finally {
|
|
406
|
+
if (junitDir) {
|
|
407
|
+
await rm(junitDir, { recursive: true, force: true });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
printSummary(completed, skipped);
|
|
412
|
+
reportOutcome(completed);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// A workspace's own test run can write files inside itself (e.g. coverage, though that's
|
|
416
|
+
// already ignored) shortly after it exits. Without this, those trailing writes get picked
|
|
417
|
+
// up as a fresh change and the workspace re-runs itself indefinitely.
|
|
418
|
+
const SETTLE_COOLDOWN_MS = 500;
|
|
419
|
+
|
|
420
|
+
async function handleWatchChange({ changedPaths, dependentsGraph, settling, workspacesToRun, root, scriptName, scriptCommands, ff, concurrency }) {
|
|
421
|
+
const affected = [...expandWithDependents(changedPaths, dependentsGraph)]
|
|
422
|
+
.filter((wsPath) => workspacesToRun.includes(wsPath));
|
|
423
|
+
|
|
424
|
+
if (affected.length === 0) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const changedNames = [...changedPaths].map(workspaceName).join(", ");
|
|
429
|
+
const affectedNames = affected.map(workspaceName).join(", ");
|
|
430
|
+
console.log(dim(`\n[watch] change detected in ${changedNames} → re-running: ${affectedNames}\n`));
|
|
431
|
+
|
|
432
|
+
for (const wsPath of affected) {
|
|
433
|
+
settling.add(wsPath);
|
|
434
|
+
}
|
|
435
|
+
try {
|
|
436
|
+
await runOnce({ root, workspacesToRun: affected, scriptName, scriptCommands, ff, junitPath: undefined, concurrency });
|
|
437
|
+
}
|
|
438
|
+
finally {
|
|
439
|
+
setTimeout(() => {
|
|
440
|
+
for (const wsPath of affected) {
|
|
441
|
+
settling.delete(wsPath);
|
|
442
|
+
}
|
|
443
|
+
}, SETTLE_COOLDOWN_MS).unref();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function runWatchMode({ root, workspaces, workspacesToRun, scriptName, scriptCommands, ff, concurrency }) {
|
|
448
|
+
const dependentsGraph = buildDependentsGraph(root, workspaces);
|
|
449
|
+
const settling = new Set();
|
|
450
|
+
|
|
451
|
+
const watcher = watchWorkspaces({
|
|
452
|
+
root,
|
|
453
|
+
workspaces,
|
|
454
|
+
isSuppressed: (wsPath) => settling.has(wsPath),
|
|
455
|
+
onChange: (changedPaths) => handleWatchChange({ changedPaths, dependentsGraph, settling, workspacesToRun, root, scriptName, scriptCommands, ff, concurrency })
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
return new Promise((resolve) => {
|
|
459
|
+
const stop = () => {
|
|
460
|
+
console.log(dim("\n[watch] stopping.\n"));
|
|
461
|
+
watcher.close();
|
|
462
|
+
resolve();
|
|
463
|
+
};
|
|
464
|
+
process.once("SIGINT", stop);
|
|
465
|
+
process.once("SIGTERM", stop);
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
export async function main({ root, scriptName, ff, junitPath, concurrency = 1, changed = false, ref, watch = false }) {
|
|
393
470
|
|
|
394
471
|
const { workspaces } = readJson(path.join(root, "package.json"));
|
|
395
472
|
|
|
@@ -427,22 +504,9 @@ export async function main({ root, scriptName, ff, junitPath, concurrency = 1, c
|
|
|
427
504
|
}
|
|
428
505
|
}
|
|
429
506
|
|
|
430
|
-
|
|
507
|
+
await runOnce({ root, workspacesToRun: finalWorkspacesToRun, scriptName, scriptCommands, ff, junitPath, concurrency });
|
|
431
508
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
({ completed, skipped } = await runWorkspaces({ root, workspacesToRun: finalWorkspacesToRun, scriptName, scriptCommands, ff, junitDir, concurrency }));
|
|
435
|
-
|
|
436
|
-
if (junitDir) {
|
|
437
|
-
await writeJunitReport(root, junitPath, completed);
|
|
438
|
-
}
|
|
509
|
+
if (watch) {
|
|
510
|
+
await runWatchMode({ root, workspaces: resolvedWorkspaces, workspacesToRun: finalWorkspacesToRun, scriptName, scriptCommands, ff, concurrency });
|
|
439
511
|
}
|
|
440
|
-
finally {
|
|
441
|
-
if (junitDir) {
|
|
442
|
-
await rm(junitDir, { recursive: true, force: true });
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
printSummary(completed, skipped);
|
|
447
|
-
reportOutcome(completed);
|
|
448
512
|
}
|
|
@@ -63,7 +63,7 @@ function pickError(error) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* node:test emits a "test:summary" per file plus one aggregate at the end
|
|
66
|
+
* node:test emits a "test:summary" per file plus one aggregate at the end.
|
|
67
67
|
* the aggregate is the only one without a "file" attached.
|
|
68
68
|
* @param {NodeTestSummaryEvent["data"]} data
|
|
69
69
|
* @returns {boolean}
|
|
@@ -73,9 +73,7 @@ function isAggregateSummary(data) {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The node:test custom reporter
|
|
77
|
-
* spawned workspace's process; only test:fail and the aggregate test:summary are kept,
|
|
78
|
-
* each re-emitted as one JSON line on stdout for the parent process to read back.
|
|
76
|
+
* The node:test custom reporter. Runs inside the spawned workspace's process.
|
|
79
77
|
* @param {AsyncIterable<NodeTestEvent>} source
|
|
80
78
|
* @returns {AsyncGenerator<string>}
|
|
81
79
|
*/
|
|
@@ -113,9 +111,7 @@ export default async function* testEventReporter(source) {
|
|
|
113
111
|
|
|
114
112
|
/**
|
|
115
113
|
* Parses the JSON lines emitted by {@link testEventReporter} back out of a workspace's
|
|
116
|
-
* captured stdout, running in the parent process.
|
|
117
|
-
* or a workspace script that never runs node:test at all) are silently skipped rather than
|
|
118
|
-
* treated as a parsing error.
|
|
114
|
+
* captured stdout, running in the parent process.
|
|
119
115
|
* @param {string} output
|
|
120
116
|
* @returns {{ counts: ReportedCounts | null, failingTests: string[], failures: ReportedFailure[] }}
|
|
121
117
|
*/
|
package/src/watch.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { watch } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const IGNORED_SEGMENTS = new Set(["node_modules", "coverage", ".git"]);
|
|
5
|
+
|
|
6
|
+
function isIgnored(relPath) {
|
|
7
|
+
return relPath.split(path.sep).some((segment) => IGNORED_SEGMENTS.has(segment) || segment.startsWith("."));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function matchWorkspace(relPath, workspaces) {
|
|
11
|
+
const normalized = relPath.split(path.sep).join("/");
|
|
12
|
+
return workspaces.find((wsPath) => normalized === wsPath || normalized.startsWith(`${wsPath}/`));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function watchWorkspaces({ root, workspaces, onChange, debounceMs = 300, isSuppressed = () => false }) {
|
|
16
|
+
const pending = new Set();
|
|
17
|
+
let timer = null;
|
|
18
|
+
|
|
19
|
+
const watcher = watch(root, { recursive: true }, (eventType, filename) => {
|
|
20
|
+
if (!filename || isIgnored(filename)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const wsPath = matchWorkspace(filename, workspaces);
|
|
25
|
+
if (!wsPath || isSuppressed(wsPath)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pending.add(wsPath);
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
timer = setTimeout(() => {
|
|
32
|
+
const changed = new Set(pending);
|
|
33
|
+
pending.clear();
|
|
34
|
+
onChange(changed);
|
|
35
|
+
}, debounceMs);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
close() {
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
watcher.close();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|