@epicat/toon-reporter 0.0.8 → 0.0.9
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/dist/index.d.mts +2 -0
- package/dist/index.mjs +43 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,8 @@ interface ToonReporterOptions {
|
|
|
7
7
|
color?: boolean;
|
|
8
8
|
/** When true, shows all files and all coverage metrics. When false (default), only shows files with gaps and only metrics < 100% */
|
|
9
9
|
verbose?: boolean;
|
|
10
|
+
/** When true, shows per-test timing in passing[N]{at,name,ms} format */
|
|
11
|
+
timing?: boolean;
|
|
10
12
|
/** @internal Used for testing to capture output */
|
|
11
13
|
_captureOutput?: (output: string) => void;
|
|
12
14
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -38,13 +38,26 @@ const colors = {
|
|
|
38
38
|
red: (s) => `\x1b[31m${s}\x1b[0m`,
|
|
39
39
|
yellow: (s) => `\x1b[33m${s}\x1b[0m`,
|
|
40
40
|
gray: (s) => `\x1b[90m${s}\x1b[0m`,
|
|
41
|
-
cyan: (s) => `\x1b[36m${s}\x1b[0m
|
|
41
|
+
cyan: (s) => `\x1b[36m${s}\x1b[0m`,
|
|
42
|
+
purple: (s) => `\x1b[35m${s}\x1b[0m`
|
|
42
43
|
};
|
|
43
44
|
function shouldUseColor(option) {
|
|
44
45
|
if (process.env.CI) return false;
|
|
45
46
|
if (option !== void 0) return option;
|
|
46
47
|
return !!process.env.COLOR;
|
|
47
48
|
}
|
|
49
|
+
function formatDuration(ms) {
|
|
50
|
+
const h = Math.floor(ms / 36e5);
|
|
51
|
+
const m = Math.floor(ms % 36e5 / 6e4);
|
|
52
|
+
const s = Math.floor(ms % 6e4 / 1e3);
|
|
53
|
+
const remaining = Math.round(ms % 1e3);
|
|
54
|
+
const parts = [];
|
|
55
|
+
if (h) parts.push(`${h}h`);
|
|
56
|
+
if (m) parts.push(`${m}m`);
|
|
57
|
+
if (s) parts.push(`${s}s`);
|
|
58
|
+
if (remaining || parts.length === 0) parts.push(`${remaining}ms`);
|
|
59
|
+
return parts.join("");
|
|
60
|
+
}
|
|
48
61
|
var ToonReporter = class {
|
|
49
62
|
constructor(options = {}) {
|
|
50
63
|
this.options = options;
|
|
@@ -157,10 +170,12 @@ var ToonReporter = class {
|
|
|
157
170
|
return message;
|
|
158
171
|
}
|
|
159
172
|
buildReportForModules(modules) {
|
|
160
|
-
const
|
|
173
|
+
const files = modules.map((m) => m.task);
|
|
174
|
+
const tests = getTests(files);
|
|
161
175
|
const rootDir = this.ctx.config.root;
|
|
162
176
|
const failedTests = tests.filter((t) => t.result?.state === "fail");
|
|
163
|
-
const
|
|
177
|
+
const passedTests = tests.filter((t) => t.result?.state === "pass");
|
|
178
|
+
const passedCount = passedTests.length;
|
|
164
179
|
const skippedTests = tests.filter((t) => t.mode === "skip");
|
|
165
180
|
const todoTests = tests.filter((t) => t.mode === "todo");
|
|
166
181
|
const grouped = /* @__PURE__ */ new Map();
|
|
@@ -191,13 +206,30 @@ var ToonReporter = class {
|
|
|
191
206
|
at: this.formatLocation(relative(rootDir, t.file.filepath), t.location?.line, t.location?.column),
|
|
192
207
|
name: t.name
|
|
193
208
|
});
|
|
194
|
-
const report = {
|
|
209
|
+
const report = {};
|
|
210
|
+
if (this.options.timing) {
|
|
211
|
+
report.duration = formatDuration(files.reduce((sum, f) => sum + (f.result?.duration ?? 0), 0));
|
|
212
|
+
report.passing = passedTests.map((t) => ({
|
|
213
|
+
at: this.formatLocation(relative(rootDir, t.file.filepath), t.location?.line, t.location?.column),
|
|
214
|
+
name: t.name,
|
|
215
|
+
ms: Math.round(t.result?.duration ?? 0)
|
|
216
|
+
}));
|
|
217
|
+
} else report.passing = passedCount;
|
|
195
218
|
if (failures.length > 0) report.failing = failures;
|
|
196
|
-
if (
|
|
197
|
-
|
|
219
|
+
if (passedCount === 0 && failedTests.length === 0) {
|
|
220
|
+
if (todoTests.length > 0) report.todo = todoTests.length;
|
|
221
|
+
if (skippedTests.length > 0) report.skipped = skippedTests.length;
|
|
222
|
+
} else {
|
|
223
|
+
if (todoTests.length > 0) report.todo = todoTests.map(mapToSkipped);
|
|
224
|
+
if (skippedTests.length > 0) report.skipped = skippedTests.map(mapToSkipped);
|
|
225
|
+
}
|
|
198
226
|
return report;
|
|
199
227
|
}
|
|
200
228
|
async onTestRunEnd(testModules, _unhandledErrors, _reason) {
|
|
229
|
+
if (testModules.length === 0) {
|
|
230
|
+
await this.writeReport(encode({ error: "No test files found" }));
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
201
233
|
const projectNames = /* @__PURE__ */ new Set();
|
|
202
234
|
const modulesByProject = /* @__PURE__ */ new Map();
|
|
203
235
|
for (const m of testModules) {
|
|
@@ -217,14 +249,17 @@ var ToonReporter = class {
|
|
|
217
249
|
else await this.writeReport(encode(projectReports));
|
|
218
250
|
return;
|
|
219
251
|
}
|
|
252
|
+
const testNamePattern = this.ctx.config.testNamePattern;
|
|
220
253
|
const report = this.buildReportForModules([...testModules]);
|
|
221
254
|
const coverage = this.getCoverageSummary();
|
|
222
255
|
if (coverage) report.coverage = coverage;
|
|
223
|
-
|
|
256
|
+
let output = encode(report);
|
|
257
|
+
if (testNamePattern) output = output.replace(/^(passing: .+)$/m, "$1 (filtered)");
|
|
258
|
+
await this.writeReport(output);
|
|
224
259
|
}
|
|
225
260
|
colorize(report) {
|
|
226
261
|
if (!this.useColor) return report;
|
|
227
|
-
return report.replace(/^(passing:)/m, colors.green("$1")).replace(/^(failing\[.*?\]:)/m, colors.red("$1")).replace(/^(todo\[.*?\]:)/m, colors.cyan("$1")).replace(/^(skipped\[.*?\]:)/m, colors.gray("$1")).replace(/at: "([^"]+)"/g, `at: "${colors.yellow("$1")}"`).replace(/("at",)([^,\n]+)/g, `$1${colors.yellow("$2")}`);
|
|
262
|
+
return report.replace(/^(passing:)/m, colors.green("$1")).replace(/(\(filtered\))/g, colors.purple("$1")).replace(/^(failing\[.*?\]:)/m, colors.red("$1")).replace(/^(todo\[.*?\]:)/m, colors.cyan("$1")).replace(/^(todo:)/m, colors.cyan("$1")).replace(/^(skipped\[.*?\]:)/m, colors.gray("$1")).replace(/^(skipped:)/m, colors.yellow("$1")).replace(/at: "([^"]+)"/g, `at: "${colors.yellow("$1")}"`).replace(/("at",)([^,\n]+)/g, `$1${colors.yellow("$2")}`);
|
|
228
263
|
}
|
|
229
264
|
async writeReport(report) {
|
|
230
265
|
if (this.options._captureOutput) {
|