sumlyzer 1.3.0 → 1.4.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 +35 -147
- package/bin/sumlyzer.mjs +11 -1
- package/package.json +1 -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/README.md
CHANGED
|
@@ -11,33 +11,15 @@
|
|
|
11
11
|
<a href="./LICENSE"><img src="https://img.shields.io/npm/l/sumlyzer.svg" alt="license" /></a>
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
<p align="center"><b>A better feedback loop for monorepos organized under npm workspaces</b></p>
|
|
15
15
|
|
|
16
|
-
`npm run test --workspaces --if-present` runs every workspace
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
`npm run test --workspaces --if-present` runs every workspace but gives no
|
|
17
|
+
summary, no fail-fast, and buries an early failure under everyone else's
|
|
18
|
+
output. Sumlyzer fixes that, and runs workspaces concurrently too (~3.5x
|
|
19
|
+
faster, see [Benchmark](#benchmark)).
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
## Requirements
|
|
24
|
-
|
|
25
|
-
- Node.js >= 22.0.0
|
|
26
|
-
- An npm workspaces project (`package.json` with a `workspaces` field)
|
|
27
|
-
|
|
28
|
-
## Scope
|
|
29
|
-
|
|
30
|
-
Intentionally narrow: **npm workspaces** running **`node:test`**. It does not
|
|
31
|
-
support pnpm/yarn workspaces or other test runners (Jest, Vitest, Mocha etc.) for the moment.
|
|
32
|
-
|
|
33
|
-
It runs each workspace's script directly (no `npm run` in between) but still
|
|
34
|
-
chains its `pre`/`post` lifecycle scripts (e.g. `pretest`) itself, with the
|
|
35
|
-
same semantics as `npm run`: a failing `pre<script>` skips the rest, and a
|
|
36
|
-
failing `post<script>` still fails the workspace even if the main script passed.
|
|
37
|
-
|
|
38
|
-
sumlyzer forces its own `node:test` reporter via `NODE_OPTIONS`, so a
|
|
39
|
-
workspace that sets its own `--test-reporter` is detected ahead of time
|
|
40
|
-
and skipped instead of colliding with it.
|
|
21
|
+
Scope: **npm workspaces** running **`node:test`** only, for now. No
|
|
22
|
+
pnpm/yarn, no Jest/Vitest/Mocha.
|
|
41
23
|
|
|
42
24
|
## Install
|
|
43
25
|
|
|
@@ -51,151 +33,57 @@ npm install --save-dev sumlyzer
|
|
|
51
33
|
npx sumlyzer [options]
|
|
52
34
|
```
|
|
53
35
|
|
|
54
|
-
Run from the root of an npm workspaces project
|
|
55
|
-
`workspaces` field).
|
|
56
|
-
|
|
57
|
-
Options:
|
|
36
|
+
Run from the root of an npm workspaces project.
|
|
58
37
|
|
|
59
38
|
| Flag | Default | Description |
|
|
60
39
|
| --- | --- | --- |
|
|
61
40
|
| `--script <name>` | `test` | npm script to run per workspace |
|
|
62
|
-
| `--ff` | off |
|
|
63
|
-
| `--junit <path>` | off | write an aggregated JUnit XML report to `<path>` |
|
|
41
|
+
| `--ff` | off | stop at the first failing workspace |
|
|
64
42
|
| `-c, --concurrency <n>` | `1` | run up to `<n>` workspaces at once |
|
|
65
|
-
| `--changed` | off | only run workspaces with changed files
|
|
43
|
+
| `--changed` | off | only run workspaces with changed files |
|
|
44
|
+
| `--junit <path>` | off | write an aggregated JUnit XML report |
|
|
66
45
|
| `--ref <ref>` | auto-detect | git ref to diff against for `--changed` |
|
|
46
|
+
| `-w, --watch` | off | re-run on file change (can't be combined with `--junit`) |
|
|
67
47
|
| `-h, --help` | | print usage |
|
|
68
48
|
|
|
69
|
-
Exit code is `1` if any workspace fails, `0` otherwise
|
|
70
|
-
into CI without extra parsing. This also applies when `--junit` can't write
|
|
71
|
-
its report.
|
|
72
|
-
|
|
73
|
-
## Benchmark
|
|
74
|
-
|
|
75
|
-
Measured on a real 15-workspace monorepo where each workspace's `test` script does real work (coverage + type-checking), averaged over a few runs on the same machine:
|
|
76
|
-
|
|
77
|
-
| Command | Wall-clock time |
|
|
78
|
-
| ----------------------------------------- | ---------------- |
|
|
79
|
-
| `npm run test --workspaces --if-present` | ~22s |
|
|
80
|
-
| `sumlyzer` (default, sequential) | ~21s |
|
|
81
|
-
| `sumlyzer --concurrency 8` | **~6s** |
|
|
82
|
-
|
|
83
|
-
See [Concurrency](#concurrency) for where that gain comes from.
|
|
84
|
-
|
|
85
|
-
## Roadmap
|
|
86
|
-
|
|
87
|
-
- **Watch mode**: walking the workspace dependency graph (topological sort) so a change in
|
|
88
|
-
one workspace also re-runs the workspaces that depend on it.
|
|
89
|
-
|
|
90
|
-
## Example
|
|
49
|
+
Exit code is `1` if any workspace fails, `0` otherwise — safe to drop straight into CI.
|
|
91
50
|
|
|
92
51
|

|
|
93
52
|
|
|
94
|
-
|
|
53
|
+
## Benchmark
|
|
95
54
|
|
|
96
|
-
|
|
97
|
-
| --------------- | ------------------------------------------------------------------------------------------------ |
|
|
98
|
-
| `(index)` | Workspace name |
|
|
99
|
-
| `status` | `PASS`, `FAIL`, or `SKIPPED` (reached when `--ff` stopped scheduling before this workspace ran) |
|
|
100
|
-
| `duration` | Wall-clock time for the workspace's script process, including spawn overhead |
|
|
101
|
-
| `tests` | Total number of tests node:test ran in that workspace |
|
|
102
|
-
| `pass` | Number of passing tests |
|
|
103
|
-
| `fail` | Number of failing tests |
|
|
55
|
+
15-workspace monorepo, each workspace's `test` script doing real work (coverage + type-checking):
|
|
104
56
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
57
|
+
| Command | Wall-clock time |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `npm run test --workspaces --if-present` | ~22s |
|
|
60
|
+
| `sumlyzer` (sequential) | ~21s |
|
|
61
|
+
| `sumlyzer --concurrency 8` | **~6s** |
|
|
110
62
|
|
|
111
63
|
## Reference
|
|
112
64
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`--
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
workspace it came from so CI test-report UIs (GitLab, Jenkins, Azure DevOps, ...)
|
|
120
|
-
can tell them apart.
|
|
65
|
+
- **JUnit** (`--junit <path>`): merges every workspace's `node:test` JUnit output into one file, each `<testsuite>` prefixed with its workspace name. A workspace whose script never produces one is left out, with a warning naming it.
|
|
66
|
+
- **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.
|
|
67
|
+
- **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.
|
|
68
|
+
- **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`.
|
|
69
|
+
- **Watch mode** (`--watch`): runs once, then keeps watching the workspaces directories. Re-runs the workspace that changed and Whatever else, in the same project, declares it as a `dependencies`/`devDependencies` entry . `node_modules`, `.git`, `coverage`, and dotfiles are ignored. Stop with `Ctrl+C`. Not compatible with `--junit`.
|
|
70
|
+
- 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.
|
|
121
71
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
72
|
+
npm doesn't have native fail-fast on `--workspaces` yet — discussed in
|
|
73
|
+
[npm/rfcs#575](https://github.com/npm/rfcs/issues/575) (open) and
|
|
74
|
+
[npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed), see also this
|
|
75
|
+
[Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284).
|
|
76
|
+
Sumlyzer's `--ff` gets you there in the meantime.
|
|
126
77
|
|
|
127
|
-
|
|
128
|
-
<testsuites>
|
|
129
|
-
<testsuite name="contact › contact tests">...</testsuite>
|
|
130
|
-
<testsuite name="scanner">...</testsuite>
|
|
131
|
-
</testsuites>
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
A workspace whose script never produces a junit file is left out of the aggregated report and sumlyzer
|
|
135
|
-
prints a warning naming it.
|
|
136
|
-
|
|
137
|
-
### GitHub Actions log folding
|
|
138
|
-
|
|
139
|
-
On GitHub Actions (detected via `GITHUB_ACTIONS=true`), each workspace's full
|
|
140
|
-
`node:test` output is wrapped in a collapsible `::group::`/`::endgroup::`
|
|
141
|
-
section instead of the terminal's format.
|
|
142
|
-
|
|
143
|
-
This is automatic, no flag needed, keeping the job log short while still
|
|
144
|
-
letting you expand any workspace's full output.
|
|
145
|
-
|
|
146
|
-
No other CI provider is currently supported: GitHub is the
|
|
147
|
-
only one whose log folding sumlyzer has actually verified end-to-end.
|
|
148
|
-
|
|
149
|
-
### Concurrency
|
|
150
|
-
|
|
151
|
-
`--concurrency <n>` runs up to `<n>` workspaces' scripts at the same time
|
|
152
|
-
instead of one after another (something npm doesn't support natively)
|
|
153
|
-
which can noticeably cut wall-clock time on projects with
|
|
154
|
-
many workspaces (see [Benchmark](#benchmark)).
|
|
155
|
-
|
|
156
|
-
Since workspaces can now finish in any order, their output interleaves in
|
|
157
|
-
whatever order they complete, rather than following the `workspaces` list
|
|
158
|
-
order.
|
|
159
|
-
|
|
160
|
-
With `--ff`, a failure only stops workspaces that haven't started yet; any
|
|
161
|
-
workspace already running when the failure is detected runs to completion
|
|
162
|
-
(sumlyzer doesn't kill in-flight processes).
|
|
163
|
-
|
|
164
|
-

|
|
165
|
-
|
|
166
|
-
### Changed workspaces
|
|
167
|
-
|
|
168
|
-
`--changed` only runs workspaces whose own files changed according to git,
|
|
169
|
-
skipping the rest. It maps each changed file to the workspace directory that
|
|
170
|
-
contains it.
|
|
171
|
-
|
|
172
|
-
```
|
|
173
|
-
npx sumlyzer --changed
|
|
174
|
-
npx sumlyzer --changed --ref origin/main
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
Without `--ref`, the git ref to diff against is auto-detected:
|
|
178
|
-
|
|
179
|
-
- Uncommitted changes present → diff against `HEAD` (the local dev loop).
|
|
180
|
-
- Clean working tree with an upstream branch configured → diff against the
|
|
181
|
-
merge-base with that upstream, so commits already on the branch count as
|
|
182
|
-
"changed" without pulling in unrelated commits the upstream picked up in
|
|
183
|
-
the meantime.
|
|
184
|
-
- Clean working tree with no upstream configured (or no common ancestor, e.g.
|
|
185
|
-
a shallow clone) → `HEAD`, which reports "no changes".
|
|
78
|
+
## Roadmap
|
|
186
79
|
|
|
187
|
-
|
|
80
|
+
**Watch mode**: walk the workspace dependency graph so a change in one workspace also re-runs the ones that depend on it.
|
|
188
81
|
|
|
189
|
-
|
|
190
|
-
npm more than once: [npm/rfcs#575](https://github.com/npm/rfcs/issues/575)
|
|
191
|
-
(open) and [npm/rfcs#602](https://github.com/npm/rfcs/issues/602) (closed).
|
|
192
|
-
Until it lands, sumlyzer's `--ff` flag gets you there, see also this
|
|
193
|
-
[Stack Overflow answer](https://stackoverflow.com/questions/71300870/npm-workspace-command-does-not-stop-executing-when-command-fails-for-a-workspace/79989284#79989284)
|
|
194
|
-
on the same problem.
|
|
82
|
+
**MCP server**: allow LLM agent to run the fail fast mode on any project organized with npm workspaces.
|
|
195
83
|
|
|
196
84
|
## Contributing
|
|
197
85
|
|
|
198
|
-
See [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
86
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
199
87
|
|
|
200
88
|
## License
|
|
201
89
|
|
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
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
|
+
}
|