sumlyzer 1.1.0 → 1.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 +6 -4
- package/package.json +1 -1
- package/src/reporter.mjs +23 -12
- package/src/run.mjs +55 -38
package/README.md
CHANGED
|
@@ -94,13 +94,15 @@ This also applies when `--junit` can't write its report.
|
|
|
94
94
|
| `(index)` | Workspace name |
|
|
95
95
|
| `status` | `PASS`, `FAIL`, or `SKIPPED` (reached when `--ff` stopped scheduling before this workspace ran) |
|
|
96
96
|
| `duration` | Wall-clock time for the whole `npm run <script> --workspace=<path>` process, including npm/spawn overhead |
|
|
97
|
-
| `testsDuration` | `duration_ms` as reported by node's own test runner |
|
|
98
97
|
| `tests` | Total number of tests node:test ran in that workspace |
|
|
99
98
|
| `pass` | Number of passing tests |
|
|
100
99
|
| `fail` | Number of failing tests |
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
|
|
101
|
+
Skipped (`t.skip()`), todo (`t.todo()`), and cancelled tests are rare enough
|
|
102
|
+
that a column of zeros for every workspace would just bury the one row that
|
|
103
|
+
has a nonzero count. Instead, sumlyzer prints a footnote below the table,
|
|
104
|
+
naming only the workspaces that actually have some, e.g. `skipped tests:
|
|
105
|
+
flags (2)`.
|
|
104
106
|
|
|
105
107
|
|
|
106
108
|
### JUnit report
|
package/package.json
CHANGED
package/src/reporter.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { styleText } from "node:util";
|
|
|
2
2
|
|
|
3
3
|
export const green = (str) => styleText("green", str);
|
|
4
4
|
export const red = (str) => styleText("red", str);
|
|
5
|
+
export const blue = (str) => styleText("blue", str);
|
|
5
6
|
export const dim = (str) => styleText("dim", str);
|
|
6
7
|
export const bold = (str) => styleText("bold", str);
|
|
7
8
|
|
|
@@ -44,33 +45,36 @@ export function printWorkspaceResult(name, result, ciGroup) {
|
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
const seconds = formatSeconds(result.durationMs);
|
|
48
|
-
const countsLabel = result.counts ? ` (${result.counts.pass}/${result.counts.tests} tests)` : "";
|
|
49
|
-
|
|
50
48
|
if (result.exitCode === 0) {
|
|
51
|
-
process.stdout.write(green(`✓ ${name}
|
|
49
|
+
process.stdout.write(green(`✓ ${name}\n`));
|
|
52
50
|
return;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))}\n`);
|
|
56
|
-
process.stdout.write(result.failureDetails + "\n");
|
|
57
|
-
process.stdout.write(red(`✗ ${name}`) + dim(` ${seconds}, exit code ${result.exitCode}\n\n`));
|
|
53
|
+
process.stdout.write(`\n${bold(red(`✗ ${name} failed`))} ${dim(`(exit code ${result.exitCode})`)}\n`);
|
|
54
|
+
process.stdout.write(result.failureDetails + "\n\n");
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
function summaryRow(status, duration, counts) {
|
|
61
58
|
return {
|
|
62
59
|
status,
|
|
63
60
|
duration,
|
|
64
|
-
testsDuration: counts?.durationMs ? formatSeconds(Number(counts.durationMs)) : "-",
|
|
65
61
|
tests: counts?.tests ?? "-",
|
|
66
62
|
pass: counts?.pass ?? "-",
|
|
67
|
-
fail: counts?.fail ?? "-"
|
|
68
|
-
skip: counts?.skip ?? "-",
|
|
69
|
-
todo: counts?.todo ?? "-",
|
|
70
|
-
cancelled: counts?.cancelled ?? "-"
|
|
63
|
+
fail: counts?.fail ?? "-"
|
|
71
64
|
};
|
|
72
65
|
}
|
|
73
66
|
|
|
67
|
+
// skip/todo/cancelled are rare in practice: a full column of zeros for every
|
|
68
|
+
// workspace buries the one row that actually has a nonzero count, so they're
|
|
69
|
+
// called out as a footnote instead of living in the table.
|
|
70
|
+
function extraCountsFootnote(results, key, label) {
|
|
71
|
+
const entries = results
|
|
72
|
+
.filter(({ counts }) => Number(counts?.[key]) > 0)
|
|
73
|
+
.map(({ wsPath, counts }) => `${workspaceName(wsPath)} (${counts[key]})`);
|
|
74
|
+
|
|
75
|
+
return entries.length > 0 ? `${label}: ${entries.join(", ")}` : null;
|
|
76
|
+
}
|
|
77
|
+
|
|
74
78
|
export function printSummary(results, skipped) {
|
|
75
79
|
console.log(bold("\nSummary"));
|
|
76
80
|
|
|
@@ -84,6 +88,13 @@ export function printSummary(results, skipped) {
|
|
|
84
88
|
|
|
85
89
|
console.table(rows);
|
|
86
90
|
|
|
91
|
+
for (const [key, label] of [["skip", "skipped tests"], ["todo", "todo tests"], ["cancelled", "cancelled tests"]]) {
|
|
92
|
+
const footnote = extraCountsFootnote(results, key, label);
|
|
93
|
+
if (footnote) {
|
|
94
|
+
console.log(blue(`ℹ ${footnote}`));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
87
98
|
if (skipped.length > 0) {
|
|
88
99
|
console.log(dim(`${skipped.length} workspace(s) skipped (--ff): ${skipped.map(workspaceName).join(", ")}`));
|
|
89
100
|
}
|
package/src/run.mjs
CHANGED
|
@@ -56,34 +56,41 @@ async function resolveWorkspacePaths(root, workspaces) {
|
|
|
56
56
|
return [...resolved];
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
function classifyWorkspace(root, wsPath, scriptName) {
|
|
60
|
+
const pkgFile = path.join(root, wsPath, "package.json");
|
|
61
|
+
let pkg;
|
|
62
|
+
try {
|
|
63
|
+
pkg = readJson(pkgFile);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return error.code === "ENOENT" ? { kind: "absent" } : { kind: "invalid", message: error.message };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const script = pkg.scripts?.[scriptName];
|
|
70
|
+
if (!script) {
|
|
71
|
+
return { kind: "absent" };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return runner.hasOwnReporter(script) ? { kind: "ownReporterConflict" } : { kind: "eligible" };
|
|
75
|
+
}
|
|
76
|
+
|
|
59
77
|
function listEligibleWorkspaces(root, workspaces, scriptName) {
|
|
60
78
|
const eligible = [];
|
|
61
79
|
const ownReporterConflicts = [];
|
|
62
80
|
const invalidPackageJson = [];
|
|
63
81
|
|
|
64
82
|
for (const wsPath of workspaces) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const script = pkg.scripts?.[scriptName];
|
|
79
|
-
if (!script) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (runner.hasOwnReporter(script)) {
|
|
83
|
-
ownReporterConflicts.push(wsPath);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
eligible.push(wsPath);
|
|
83
|
+
const classification = classifyWorkspace(root, wsPath, scriptName);
|
|
84
|
+
switch (classification.kind) {
|
|
85
|
+
case "invalid":
|
|
86
|
+
invalidPackageJson.push({ wsPath, message: classification.message });
|
|
87
|
+
break;
|
|
88
|
+
case "ownReporterConflict":
|
|
89
|
+
ownReporterConflicts.push(wsPath);
|
|
90
|
+
break;
|
|
91
|
+
case "eligible":
|
|
92
|
+
eligible.push(wsPath);
|
|
93
|
+
break;
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
|
|
@@ -107,6 +114,13 @@ function killWorkspaceChild(child) {
|
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
116
|
|
|
117
|
+
function waitForExit(child) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
child.on("error", reject);
|
|
120
|
+
child.on("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
110
124
|
async function captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath, activeChildren }) {
|
|
111
125
|
const options = {
|
|
112
126
|
cwd: root,
|
|
@@ -124,10 +138,7 @@ async function captureWorkspaceOutput({ root, wsPath, scriptName, junitDestPath,
|
|
|
124
138
|
child.stderr.on("data", (chunk) => stderrChunks.push(chunk));
|
|
125
139
|
|
|
126
140
|
try {
|
|
127
|
-
const exitCode = await
|
|
128
|
-
child.on("error", reject);
|
|
129
|
-
child.on("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
130
|
-
});
|
|
141
|
+
const exitCode = await waitForExit(child);
|
|
131
142
|
|
|
132
143
|
return {
|
|
133
144
|
exitCode,
|
|
@@ -196,6 +207,23 @@ async function collectJunitEntries(results) {
|
|
|
196
207
|
return { entries, missing };
|
|
197
208
|
}
|
|
198
209
|
|
|
210
|
+
// A worker leaves its slot in `results` undefined when it never got to start
|
|
211
|
+
// (--ff stopped scheduling first); that's the signal to bucket it as skipped.
|
|
212
|
+
function partitionResults(results, workspacesToRun) {
|
|
213
|
+
const completed = [];
|
|
214
|
+
const skipped = [];
|
|
215
|
+
for (const [index, result] of results.entries()) {
|
|
216
|
+
if (result === undefined) {
|
|
217
|
+
skipped.push(workspacesToRun[index]);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
completed.push(result);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return { completed, skipped };
|
|
225
|
+
}
|
|
226
|
+
|
|
199
227
|
async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir, concurrency }) {
|
|
200
228
|
const results = new Array(workspacesToRun.length);
|
|
201
229
|
const ciGroup = githubGroupSyntax(process.env);
|
|
@@ -234,18 +262,7 @@ async function runWorkspaces({ root, workspacesToRun, scriptName, ff, junitDir,
|
|
|
234
262
|
const workerCount = Math.max(1, Math.min(concurrency, workspacesToRun.length));
|
|
235
263
|
await withInterruptHandling(activeChildren, () => Promise.all(Array.from({ length: workerCount }, worker)));
|
|
236
264
|
|
|
237
|
-
|
|
238
|
-
const skipped = [];
|
|
239
|
-
for (const [index, result] of results.entries()) {
|
|
240
|
-
if (result === undefined) {
|
|
241
|
-
skipped.push(workspacesToRun[index]);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
completed.push(result);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return { completed, skipped };
|
|
265
|
+
return partitionResults(results, workspacesToRun);
|
|
249
266
|
}
|
|
250
267
|
|
|
251
268
|
const DEFAULT_JUNIT_FILENAME = "junit.xml";
|