sumlyzer 0.1.1 → 0.2.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
@@ -1,9 +1,25 @@
1
- # Sumlyzer
1
+ <p align="center">
2
+ <img src="https://github.com/ErwanRaulo/sumlyzer/blob/main/logo.png?raw=true" alt="Sumlyzer logo" width="140" />
3
+ </p>
4
+
5
+ <h1 align="center">Sumlyzer</h1>
6
+
7
+ <p align="center">
8
+ <a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/v/sumlyzer.svg" alt="npm version" /></a>
9
+ <a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/npm/dm/sumlyzer.svg" alt="npm downloads" /></a>
10
+ <a href="https://www.npmjs.com/package/sumlyzer"><img src="https://img.shields.io/node/v/sumlyzer.svg" alt="node engine" /></a>
11
+ <a href="./LICENSE"><img src="https://img.shields.io/npm/l/sumlyzer.svg" alt="license" /></a>
12
+ </p>
2
13
 
3
14
  Run every npm workspace's test script, one by one. Passing workspaces output
4
15
  to a single line; failing ones print only the relevant failure detail.
5
16
  Ends with an aggregated pass/fail summary table, so nothing scrolls out of the terminal.
6
17
 
18
+ ## Requirements
19
+
20
+ - Node.js >= 22.0.0
21
+ - An npm workspaces project (`package.json` with a `workspaces` field)
22
+
7
23
  ## Scope
8
24
 
9
25
  This tool is intentionally narrow: **npm workspaces** running **`node:test`**.
@@ -33,12 +49,127 @@ Options:
33
49
  | --- | --- | --- |
34
50
  | `--script <name>` | `test` | npm script to run per workspace |
35
51
  | `--ff` | off | fail fast: stop at the first failing workspace |
52
+ | `--junit <path>` | off | write an aggregated JUnit XML report to `<path>` |
36
53
  | `-h, --help` | | print usage |
37
54
 
55
+ Exit code is `1` if any workspace fails (or if the project has no
56
+ workspaces), `0` otherwise — wire it straight into CI without extra parsing.
57
+
38
58
  ## Example
39
59
 
40
- ![description](https://github.com/ErwanRaulo/sumlyzer/blob/main/example.png?raw=true)
60
+ ```
61
+ running contact
62
+ ✓ contact 2.6s (35/35 tests)
63
+ running scanner
64
+ ✓ scanner 10.1s (161/162 tests)
65
+ running tarball
66
+ ✓ tarball 1.8s (77/77 tests)
67
+ running mama
68
+ ✓ mama 1.2s (85/85 tests)
69
+ running tree-walker
70
+ ✓ tree-walker 3.0s (26/26 tests)
71
+ running conformance
72
+ ✓ conformance 1.1s (35/35 tests)
73
+ running i18n
74
+ ✓ i18n 1.1s (19/19 tests)
75
+ running rc
76
+ ✓ rc 4.1s (28/28 tests)
77
+ running utils
78
+ ✓ utils 1.1s (30/30 tests)
79
+ running flags
80
+ ✓ flags 1.1s (9/9 tests)
81
+ running fs-walk
82
+ ✓ fs-walk 1.1s (3/3 tests)
83
+ running github
84
+ ✓ github 2.9s (8/8 tests)
85
+ running gitlab
86
+ ✓ gitlab 4.3s (8/8 tests)
87
+
88
+ Summary
89
+
90
+ ┌─────────┬────────────────┬──────────┬────────────┬────────────────┬─────────┬────────┬────────┐
91
+ │ (index) │ workspace │ status │ duration │ testsDuration │ tests │ pass │ fail │
92
+ ├─────────┼────────────────┼──────────┼────────────┼────────────────┼─────────┼────────┼────────┤
93
+ │ 0 │ 'contact' │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │
94
+ │ 1 │ 'scanner' │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │
95
+ │ 2 │ 'tarball' │ 'PASS' │ '1.8s' │ '0.7s' │ '77' │ '77' │ '0' │
96
+ │ 3 │ 'mama' │ 'PASS' │ '1.2s' │ '0.1s' │ '85' │ '85' │ '0' │
97
+ │ 4 │ 'tree-walker' │ 'PASS' │ '3.0s' │ '2.0s' │ '26' │ '26' │ '0' │
98
+ │ 5 │ 'conformance' │ 'PASS' │ '1.1s' │ '0.1s' │ '35' │ '35' │ '0' │
99
+ │ 6 │ 'i18n' │ 'PASS' │ '1.1s' │ '0.2s' │ '19' │ '19' │ '0' │
100
+ │ 7 │ 'rc' │ 'PASS' │ '4.1s' │ '0.6s' │ '28' │ '28' │ '0' │
101
+ │ 8 │ 'utils' │ 'PASS' │ '1.1s' │ '0.1s' │ '30' │ '30' │ '0' │
102
+ │ 9 │ 'flags' │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │
103
+ │ 10 │ 'fs-walk' │ 'PASS' │ '1.1s' │ '0.1s' │ '3' │ '3' │ '0' │
104
+ │ 11 │ 'github' │ 'PASS' │ '2.9s' │ '2.0s' │ '8' │ '8' │ '0' │
105
+ │ 12 │ 'gitlab' │ 'PASS' │ '4.3s' │ '3.3s' │ '8' │ '8' │ '0' │
106
+ └─────────┴────────────────┴──────────┴────────────┴────────────────┴─────────┴────────┴────────┘
107
+
108
+ 13/13 workspaces passed.
109
+ ```
110
+
111
+ ### On failure
112
+
113
+ Only the failing workspace prints its detail; passing ones stay collapsed to a single line.
114
+
115
+ ```
116
+ running contact
117
+ ✓ contact 2.6s (35/35 tests)
118
+ running scanner
119
+ ✓ scanner 10.1s (161/162 tests)
120
+ running utils
121
+
122
+ ✗ utils failed
123
+ test at test/format.spec.mjs:12:3
124
+ ✖ formats negative numbers (3ms)
125
+ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal
126
+ + actual - expected
127
+
128
+ + '-1'
129
+ - '(1)'
130
+
131
+ ✗ utils 1.3s, exit code 1
132
+
133
+ running flags
134
+ ✓ flags 1.1s (9/9 tests)
135
+
136
+ Summary
137
+
138
+ ┌─────────┬────────────┬──────────┬────────────┬────────────────┬─────────┬────────┬────────┐
139
+ │ (index) │ workspace │ status │ duration │ testsDuration │ tests │ pass │ fail │
140
+ ├─────────┼────────────┼──────────┼────────────┼────────────────┼─────────┼────────┼────────┤
141
+ │ 0 │ 'contact' │ 'PASS' │ '2.6s' │ '0.9s' │ '35' │ '35' │ '0' │
142
+ │ 1 │ 'scanner' │ 'PASS' │ '10.1s' │ '8.7s' │ '162' │ '161' │ '0' │
143
+ │ 2 │ 'utils' │ 'FAIL' │ '1.3s' │ '0.1s' │ '30' │ '29' │ '1' │
144
+ │ 3 │ 'flags' │ 'PASS' │ '1.1s' │ '0.1s' │ '9' │ '9' │ '0' │
145
+ └─────────┴────────────┴──────────┴────────────┴────────────────┴─────────┴────────┴────────┘
146
+
147
+ 1/4 workspace(s) failed:
148
+ utils
149
+ ✖ formats negative numbers
150
+ ```
151
+
152
+ ### JUnit report
153
+
154
+ `--junit <path>` writes a single aggregated JUnit XML report to `<path>`, merging
155
+ every workspace's own `node:test` results. Each workspace runs with `node:test`'s
156
+ built-in `junit` reporter enabled alongside the terminal one, and sumlyzer combines
157
+ the resulting files into one document, prefixing every `<testsuite>` name with the
158
+ workspace it came from so CI test-report UIs (GitLab, Jenkins, Azure DevOps, ...)
159
+ can tell them apart. If `<path>` is an existing directory, the report is written
160
+ to `<path>/junit.xml`:
161
+
162
+ ```
163
+ npx sumlyzer --junit reports/junit.xml
164
+ npx sumlyzer --junit reports/ # writes reports/junit.xml
165
+ ```
41
166
 
167
+ ```xml
168
+ <testsuites>
169
+ <testsuite name="contact › contact tests">...</testsuite>
170
+ <testsuite name="scanner">...</testsuite>
171
+ </testsuites>
172
+ ```
42
173
 
43
174
  ## Why
44
175
 
@@ -48,6 +179,10 @@ scrolls off screen once later workspaces print their own output. Turborepo
48
179
  has the [same open issue](https://github.com/vercel/turborepo/issues/1368).
49
180
  sumlyzer is a small, dependency-free tool that solves just this.
50
181
 
182
+ ## Contributing
183
+
184
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup, conventions, and how to submit changes.
185
+
51
186
  ## License
52
187
 
53
188
  MIT
package/bin/sumlyzer.mjs CHANGED
@@ -10,6 +10,7 @@ try {
10
10
  options: {
11
11
  ff: { type: "boolean", default: false },
12
12
  script: { type: "string", default: "test" },
13
+ junit: { type: "string" },
13
14
  help: { type: "boolean", short: "h", default: false }
14
15
  }
15
16
  }));
@@ -31,9 +32,10 @@ failure detail. Ends with an aggregated pass/fail summary table.
31
32
  Options:
32
33
  --script <name> npm script to run per workspace (default: "test")
33
34
  --ff fail fast: stop at the first failing workspace
35
+ --junit <path> write an aggregated JUnit XML report to <path>
34
36
  -h, --help show this help
35
37
  `);
36
38
  process.exit(0);
37
39
  }
38
40
 
39
- await main({ root: path.resolve(process.cwd()), scriptName: values.script, ff: values.ff });
41
+ await main({ root: path.resolve(process.cwd()), scriptName: values.script, ff: values.ff, junitPath: values.junit });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sumlyzer",
3
- "version": "0.1.1",
3
+ "version": "0.2.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": {
@@ -16,7 +16,12 @@
16
16
  "node": ">=22.0.0"
17
17
  },
18
18
  "scripts": {
19
- "test": "node --test \"./test/*.spec.mjs\""
19
+ "test": "node --test \"./test/*.spec.mjs\"",
20
+ "test:coverage": "c8 --reporter=text --reporter=lcov --check-coverage --lines 95 --functions 95 --statements 95 --branches 85 node --test \"./test/*.spec.mjs\"",
21
+ "security-scan": "node scripts/security-scan.mjs",
22
+ "postversion": "git push && git push --tags",
23
+ "prepublishOnly": "npm test",
24
+ "release": "npm publish --dry-run"
20
25
  },
21
26
  "keywords": [
22
27
  "npm",
@@ -27,9 +32,19 @@
27
32
  "test-runner",
28
33
  "cli",
29
34
  "fail-fast",
30
- "summary"
35
+ "summary",
36
+ "npm-workspaces",
37
+ "monorepo",
38
+ "test-reporter",
39
+ "node-test",
40
+ "node:test",
41
+ "test-summary",
42
+ "ci"
31
43
  ],
32
- "author": "Erwan Raulo",
44
+ "author": {
45
+ "name": "Erwan Raulo",
46
+ "url": "https://github.com/ErwanRaulo"
47
+ },
33
48
  "license": "MIT",
34
49
  "repository": {
35
50
  "type": "git",
@@ -40,6 +55,9 @@
40
55
  },
41
56
  "homepage": "https://github.com/ErwanRaulo/sumlyzer#readme",
42
57
  "devDependencies": {
43
- "@types/node": "^26.1.1"
58
+ "@nodesecure/js-x-ray": "^16.0.0",
59
+ "@types/node": "^26.1.1",
60
+ "c8": "^12.0.0",
61
+ "fast-xml-parser": "^5.10.1"
44
62
  }
45
63
  }
package/src/junit.mjs ADDED
@@ -0,0 +1,81 @@
1
+ const XML_BLOCK = /<testsuite\b[^>]*>|<\/testsuite>|<testcase\b[^>]*\/>|<testcase\b[^>]*>[\s\S]*?<\/testcase>/g;
2
+ const TESTSUITE_NAME_ATTR = /(<testsuite\b[^>]*\sname=")([^"]*)(")/;
3
+ const COMMENT = /<!--[\s\S]*?-->/g;
4
+
5
+ export function escapeXmlAttr(value) {
6
+ return String(value)
7
+ .replace(/&/g, "&amp;")
8
+ .replace(/"/g, "&quot;")
9
+ .replace(/</g, "&lt;")
10
+ .replace(/>/g, "&gt;");
11
+ }
12
+
13
+ // describe() blocks can nest, and node:test's own junit reporter mirrors that by nesting
14
+ // <testsuite> inside <testsuite>; a flat top-level test() instead produces a bare <testcase>
15
+ // directly under <testsuites>, with no enclosing suite at all (called orphanTestcases).
16
+ function scanWorkspaceXml(xml) {
17
+ const suiteRanges = [];
18
+ const orphanTestcases = [];
19
+ let depth = 0;
20
+ let blockStart = null;
21
+ let match;
22
+
23
+ XML_BLOCK.lastIndex = 0;
24
+ while ((match = XML_BLOCK.exec(xml)) !== null) {
25
+ const token = match[0];
26
+
27
+ if (token === "</testsuite>") {
28
+ if (depth === 0) {
29
+ continue; // stray closing tag with no matching open; ignore defensively.
30
+ }
31
+ depth -= 1;
32
+ if (depth === 0) {
33
+ suiteRanges.push({ start: blockStart, end: match.index + token.length });
34
+ }
35
+ continue;
36
+ }
37
+
38
+ if (token.startsWith("<testsuite")) {
39
+ if (depth === 0) {
40
+ blockStart = match.index;
41
+ }
42
+ depth += 1;
43
+ continue;
44
+ }
45
+
46
+ // otherwise token is a <testcase> block (self-closing or with a <failure> child).
47
+ if (depth === 0) {
48
+ orphanTestcases.push(token);
49
+ }
50
+ }
51
+
52
+ return { suiteRanges, orphanTestcases };
53
+ }
54
+
55
+ export function extractTestsuites(xml, ranges = scanWorkspaceXml(xml).suiteRanges) {
56
+ return ranges.map(({ start, end }) => xml.slice(start, end));
57
+ }
58
+
59
+ export function prefixTestsuiteName(block, prefix) {
60
+ if (!TESTSUITE_NAME_ATTR.test(block)) {
61
+ return block;
62
+ }
63
+
64
+ return block.replace(TESTSUITE_NAME_ATTR, (_match, open, name, close) => `${open}${escapeXmlAttr(prefix)} › ${name}${close}`);
65
+ }
66
+
67
+ export function buildJunitReport(workspaces) {
68
+ const suites = workspaces.flatMap(({ name, xml }) => {
69
+ const cleaned = xml.replace(COMMENT, "");
70
+ const { suiteRanges, orphanTestcases } = scanWorkspaceXml(cleaned);
71
+ const namedSuites = extractTestsuites(cleaned, suiteRanges).map((block) => prefixTestsuiteName(block, name));
72
+
73
+ if (orphanTestcases.length === 0) {
74
+ return namedSuites;
75
+ }
76
+
77
+ return [...namedSuites, `<testsuite name="${escapeXmlAttr(name)}">\n${orphanTestcases.join("\n")}\n</testsuite>`];
78
+ });
79
+
80
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<testsuites>\n${suites.join("\n")}\n</testsuites>\n`;
81
+ }
package/src/run.mjs CHANGED
@@ -1,8 +1,12 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { readFileSync } from "node:fs";
3
+ import { mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
3
5
  import { promisify, styleText } from "node:util";
4
6
  import path from "node:path";
5
7
 
8
+ import { buildJunitReport } from "./junit.mjs";
9
+
6
10
  const execFileAsync = promisify(execFile);
7
11
 
8
12
  const green = (str) => styleText("green", str);
@@ -15,9 +19,15 @@ const count = (target, output) => new RegExp(String.raw`ℹ ${target} (\d+)`).ex
15
19
 
16
20
  const SPEC_REPORTER_FLAGS = "--test-reporter=spec --test-reporter-destination=stdout";
17
21
 
18
- export function envWithSpecReporter(env) {
22
+ export function envWithSpecReporter(env, junitDestPath) {
19
23
  const existing = env.NODE_OPTIONS ? `${env.NODE_OPTIONS} ` : "";
20
- return { ...env, NODE_OPTIONS: `${existing}${SPEC_REPORTER_FLAGS}` };
24
+ const junitFlags = junitDestPath ? ` --test-reporter=junit --test-reporter-destination=${junitDestPath}` : "";
25
+ // Drop NODE_TEST_CONTEXT: if sumlyzer itself is invoked from inside a node:test run (e.g.
26
+ // its own test suite), this var would otherwise leak into the workspace's own `node --test`
27
+ // process, which then silently treats itself as a nested child and stops reporting normally.
28
+ const rest = { ...env };
29
+ delete rest.NODE_TEST_CONTEXT;
30
+ return { ...rest, NODE_OPTIONS: `${existing}${SPEC_REPORTER_FLAGS}${junitFlags}` };
21
31
  }
22
32
 
23
33
  function readJson(file) {
@@ -84,13 +94,13 @@ export function formatSeconds(ms) {
84
94
  return `${seconds.toFixed(1)}s`;
85
95
  }
86
96
 
87
- async function runWorkspaceScript(root, wsPath, scriptName) {
97
+ async function runWorkspaceScript(root, wsPath, scriptName, junitDestPath) {
88
98
  const start = Date.now();
89
99
  const options = {
90
100
  cwd: root,
91
101
  shell: process.platform === "win32",
92
102
  maxBuffer: 20 * 1024 * 1024,
93
- env: envWithSpecReporter(process.env)
103
+ env: envWithSpecReporter(process.env, junitDestPath)
94
104
  };
95
105
 
96
106
  let exitCode = 0;
@@ -113,10 +123,33 @@ async function runWorkspaceScript(root, wsPath, scriptName) {
113
123
  failureDetails: exitCode === 0 ? null : extractFailureDetails(output),
114
124
  durationMs: Date.now() - start,
115
125
  counts: parseTestCounts(output),
116
- failingTests: parseFailingTests(output)
126
+ failingTests: parseFailingTests(output),
127
+ junitDestPath
117
128
  };
118
129
  }
119
130
 
131
+ async function collectJunitEntries(results) {
132
+ const entries = [];
133
+ const missing = [];
134
+
135
+ for (const result of results) {
136
+ if (!result.junitDestPath) {
137
+ continue;
138
+ }
139
+ try {
140
+ entries.push({ name: workspaceName(result.wsPath), xml: await readFile(result.junitDestPath, "utf8") });
141
+ }
142
+ catch {
143
+ // Either the workspace crashed before node:test's own junit reporter could write its
144
+ // file, or --script points at something that isn't node:test at all; skip it, but the
145
+ // caller still needs to know so it can tell the user the report is missing an entry.
146
+ missing.push(workspaceName(result.wsPath));
147
+ }
148
+ }
149
+
150
+ return { entries, missing };
151
+ }
152
+
120
153
  function summaryRow(workspace, status, duration, counts) {
121
154
  return {
122
155
  workspace,
@@ -129,52 +162,75 @@ function summaryRow(workspace, status, duration, counts) {
129
162
  };
130
163
  }
131
164
 
132
- export async function main({ root, scriptName, ff }) {
133
-
134
- const { workspaces } = readJson(path.join(root, "package.json"));
165
+ function printWorkspaceResult(name, result) {
166
+ const seconds = formatSeconds(result.durationMs);
167
+ const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
135
168
 
136
- if (!workspaces || workspaces.length === 0) {
137
- console.info("Your project does not have any workspaces.");
138
- process.exit(1);
169
+ if (result.exitCode === 0) {
170
+ process.stdout.write(green(`✓ ${name}`) + dim(` ${seconds}${countsLabel}\n`));
171
+ return;
139
172
  }
140
173
 
141
- const workspacesToRun = listEligibleWorkspaces(root, workspaces, scriptName);
174
+ process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
175
+ process.stdout.write(result.failureDetails + "\n");
176
+ process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
177
+ }
178
+
179
+ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir }) {
142
180
  const results = [];
143
181
 
144
- for (const wsPath of workspacesToRun) {
182
+ for (const [index, wsPath] of workspacesToRun.entries()) {
145
183
  const name = workspaceName(wsPath);
146
184
  process.stdout.write(dim(`running ${name}\n`));
147
185
 
186
+ const junitDestPath = junitDir ? path.join(junitDir, `${index}.xml`) : undefined;
187
+
148
188
  let result;
149
189
  try {
150
- result = await runWorkspaceScript(root, wsPath, scriptName);
190
+ result = await runWorkspaceScript(root, wsPath, scriptName, junitDestPath);
151
191
  }
152
192
  catch (error) {
153
193
  console.error(red(`✗ ${name}: could not launch "${scriptName}" (${error.message})`));
154
194
  process.exit(1);
155
195
  }
156
196
  results.push(result);
197
+ printWorkspaceResult(name, result);
157
198
 
158
- const seconds = formatSeconds(result.durationMs);
159
- const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
160
-
161
- if (result.exitCode === 0) {
162
- process.stdout.write(green(`✓ ${name}`) + dim(` ${seconds}${countsLabel}\n`));
163
- }
164
- else {
165
- process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
166
- process.stdout.write(result.failureDetails + "\n");
167
- process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
168
-
169
- if (ff) {
170
- break;
171
- }
199
+ if (result.exitCode !== 0 && ff) {
200
+ break;
172
201
  }
173
202
  }
174
203
 
175
- const failed = results.filter((result) => result.exitCode !== 0);
176
- const skipped = workspacesToRun.slice(results.length);
204
+ return results;
205
+ }
206
+
207
+ const DEFAULT_JUNIT_FILENAME = "junit.xml";
208
+
209
+ async function resolveJunitDestination(root, junitPath) {
210
+ const destination = path.resolve(root, junitPath);
211
+ const isExistingDirectory = await stat(destination).then((stats) => stats.isDirectory(), () => false);
212
+
213
+ return isExistingDirectory ? path.join(destination, DEFAULT_JUNIT_FILENAME) : destination;
214
+ }
215
+
216
+ async function writeJunitReport(root, junitPath, results) {
217
+ const { entries, missing } = await collectJunitEntries(results);
218
+ const destination = await resolveJunitDestination(root, junitPath);
219
+
220
+ if (missing.length > 0) {
221
+ console.log(dim(`${missing.length} workspace(s) missing from the JUnit report: ${missing.join(", ")}`));
222
+ }
223
+
224
+ try {
225
+ await writeFile(destination, buildJunitReport(entries));
226
+ }
227
+ catch (error) {
228
+ console.error(red(`Could not write JUnit report to "${destination}" (${error.message})`));
229
+ process.exitCode = 1;
230
+ }
231
+ }
177
232
 
233
+ function printSummary(results, skipped) {
178
234
  console.log(bold("\nSummary"));
179
235
  console.table([
180
236
  ...results.map((result) => summaryRow(
@@ -189,18 +245,52 @@ export async function main({ root, scriptName, ff }) {
189
245
  if (skipped.length > 0) {
190
246
  console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
191
247
  }
248
+ }
249
+
250
+ function reportOutcome(results) {
251
+ const failed = results.filter((result) => result.exitCode !== 0);
252
+
253
+ if (failed.length === 0) {
254
+ console.log(green(`${results.length}/${results.length} workspaces passed.`));
255
+ return;
256
+ }
192
257
 
193
- if (failed.length > 0) {
194
- console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
195
- for (const result of failed) {
196
- console.log(red(` ${workspaceName(result.wsPath)}`));
197
- for (const testName of result.failingTests) {
198
- console.log(dim(` ✖ ${testName}`));
199
- }
258
+ console.log(red(`${failed.length}/${results.length} workspace(s) failed:`));
259
+ for (const result of failed) {
260
+ console.log(red(` ${workspaceName(result.wsPath)}`));
261
+ for (const testName of result.failingTests) {
262
+ console.log(dim(` ✖ ${testName}`));
200
263
  }
201
- process.exitCode = 1;
202
264
  }
203
- else {
204
- console.log(green(`${results.length}/${results.length} workspaces passed.`));
265
+ process.exitCode = 1;
266
+ }
267
+
268
+ export async function main({ root, scriptName, ff, junitPath }) {
269
+
270
+ const { workspaces } = readJson(path.join(root, "package.json"));
271
+
272
+ if (!workspaces || workspaces.length === 0) {
273
+ console.info("Your project does not have any workspaces.");
274
+ process.exit(1);
275
+ }
276
+
277
+ const workspacesToRun = listEligibleWorkspaces(root, workspaces, scriptName);
278
+ const junitDir = junitPath ? await mkdtemp(path.join(tmpdir(), "sumlyzer-junit-")) : null;
279
+
280
+ let results;
281
+ try {
282
+ results = await runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir });
283
+
284
+ if (junitDir) {
285
+ await writeJunitReport(root, junitPath, results);
286
+ }
287
+ }
288
+ finally {
289
+ if (junitDir) {
290
+ await rm(junitDir, { recursive: true, force: true });
291
+ }
205
292
  }
293
+
294
+ printSummary(results, workspacesToRun.slice(results.length));
295
+ reportOutcome(results);
206
296
  }