@japa/runner 4.4.1 → 4.5.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 +0 -61
- package/build/chunk-2KG3PWR4.js +17 -0
- package/build/chunk-L7YZLDZD.js +340 -0
- package/build/chunk-RFKFNXTE.js +347 -0
- package/build/chunk-WNJXMFYL.js +520 -0
- package/build/factories/create_dummy_tests.d.ts +1 -1
- package/build/factories/main.d.ts +1 -1
- package/build/factories/main.js +232 -182
- package/build/factories/runner.d.ts +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +278 -214
- package/build/modules/core/main.js +21 -2
- package/build/modules/core/reporters/base.d.ts +1 -1
- package/build/src/create_test.d.ts +1 -1
- package/build/src/debug.d.ts +1 -1
- package/build/src/helpers.d.ts +2 -2
- package/build/src/hooks.d.ts +1 -1
- package/build/src/plugins/main.js +28 -20
- package/build/src/reporters/main.js +14 -3
- package/build/src/reporters/spec.d.ts +1 -1
- package/build/src/types.js +14 -7
- package/build/src/validator.d.ts +1 -1
- package/package.json +32 -29
- package/build/create_test-CuTGNCAf.js +0 -353
- package/build/helpers-BlHaYYTh.js +0 -241
- package/build/main-CB1nhl6c.js +0 -336
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
-
import { ErrorsPrinter } from "@japa/errors-printer";
|
|
3
|
-
import { inspect } from "node:util";
|
|
4
|
-
import string from "@poppinss/string";
|
|
5
|
-
import useColors from "@poppinss/colors";
|
|
6
|
-
import supportsColor from "supports-color";
|
|
7
|
-
import { parse } from "error-stack-parser-es";
|
|
8
|
-
import { Emitter, Group, Refiner, Runner, Suite, Test, TestContext } from "@japa/core";
|
|
9
|
-
import { AssertionError } from "node:assert";
|
|
10
|
-
var BaseReporter = class {
|
|
11
|
-
runner;
|
|
12
|
-
currentFileName;
|
|
13
|
-
currentSuiteName;
|
|
14
|
-
currentGroupName;
|
|
15
|
-
options;
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
this.options = Object.assign({ stackLinesCount: 2 }, options);
|
|
18
|
-
}
|
|
19
|
-
printAggregates(summary) {
|
|
20
|
-
const tests = [];
|
|
21
|
-
if (summary.aggregates.passed) tests.push(colors.green(`${summary.aggregates.passed} passed`));
|
|
22
|
-
if (summary.aggregates.failed) tests.push(colors.red(`${summary.aggregates.failed} failed`));
|
|
23
|
-
if (summary.aggregates.todo) tests.push(colors.cyan(`${summary.aggregates.todo} todo`));
|
|
24
|
-
if (summary.aggregates.skipped) tests.push(colors.yellow(`${summary.aggregates.skipped} skipped`));
|
|
25
|
-
if (summary.aggregates.regression) tests.push(colors.magenta(`${summary.aggregates.regression} regression`));
|
|
26
|
-
this.runner.summaryBuilder.use(() => {
|
|
27
|
-
return [{
|
|
28
|
-
key: colors.dim("Tests"),
|
|
29
|
-
value: `${tests.join(", ")} ${colors.dim(`(${summary.aggregates.total})`)}`
|
|
30
|
-
}, {
|
|
31
|
-
key: colors.dim("Time"),
|
|
32
|
-
value: colors.dim(string.milliseconds.format(summary.duration))
|
|
33
|
-
}];
|
|
34
|
-
});
|
|
35
|
-
console.log(this.runner.summaryBuilder.build().join("\n"));
|
|
36
|
-
}
|
|
37
|
-
aggregateErrors(summary) {
|
|
38
|
-
const errorsList = [];
|
|
39
|
-
summary.failureTree.forEach((suite) => {
|
|
40
|
-
suite.errors.forEach((error) => errorsList.push({
|
|
41
|
-
title: suite.name,
|
|
42
|
-
...error
|
|
43
|
-
}));
|
|
44
|
-
suite.children.forEach((testOrGroup) => {
|
|
45
|
-
if (testOrGroup.type === "test") {
|
|
46
|
-
testOrGroup.errors.forEach((error) => {
|
|
47
|
-
errorsList.push({
|
|
48
|
-
title: `${suite.name} / ${testOrGroup.title}`,
|
|
49
|
-
...error
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
testOrGroup.errors.forEach((error) => {
|
|
55
|
-
errorsList.push({
|
|
56
|
-
title: testOrGroup.name,
|
|
57
|
-
...error
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
testOrGroup.children.forEach((test) => {
|
|
61
|
-
test.errors.forEach((error) => {
|
|
62
|
-
errorsList.push({
|
|
63
|
-
title: `${testOrGroup.name} / ${test.title}`,
|
|
64
|
-
...error
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
return errorsList;
|
|
71
|
-
}
|
|
72
|
-
async printErrors(summary) {
|
|
73
|
-
if (!summary.failureTree.length) return;
|
|
74
|
-
const errorPrinter = new ErrorsPrinter({ framesMaxLimit: this.options.framesMaxLimit });
|
|
75
|
-
errorPrinter.printSectionHeader("ERRORS");
|
|
76
|
-
await errorPrinter.printErrors(this.aggregateErrors(summary));
|
|
77
|
-
}
|
|
78
|
-
onTestStart(_) {}
|
|
79
|
-
onTestEnd(_) {}
|
|
80
|
-
onGroupStart(_) {}
|
|
81
|
-
onGroupEnd(_) {}
|
|
82
|
-
onSuiteStart(_) {}
|
|
83
|
-
onSuiteEnd(_) {}
|
|
84
|
-
async start(_) {}
|
|
85
|
-
async end(_) {}
|
|
86
|
-
async printSummary(summary) {
|
|
87
|
-
await this.printErrors(summary);
|
|
88
|
-
console.log("");
|
|
89
|
-
if (summary.aggregates.total === 0 && !summary.hasError) {
|
|
90
|
-
console.log(colors.bgYellow().black(" NO TESTS EXECUTED "));
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (summary.hasError) console.log(colors.bgRed().black(" FAILED "));
|
|
94
|
-
else console.log(colors.bgGreen().black(" PASSED "));
|
|
95
|
-
console.log("");
|
|
96
|
-
this.printAggregates(summary);
|
|
97
|
-
}
|
|
98
|
-
boot(runner, emitter) {
|
|
99
|
-
this.runner = runner;
|
|
100
|
-
emitter.on("test:start", (payload) => {
|
|
101
|
-
this.currentFileName = payload.meta.fileName;
|
|
102
|
-
this.onTestStart(payload);
|
|
103
|
-
});
|
|
104
|
-
emitter.on("test:end", (payload) => {
|
|
105
|
-
this.onTestEnd(payload);
|
|
106
|
-
});
|
|
107
|
-
emitter.on("group:start", (payload) => {
|
|
108
|
-
this.currentGroupName = payload.title;
|
|
109
|
-
this.currentFileName = payload.meta.fileName;
|
|
110
|
-
this.onGroupStart(payload);
|
|
111
|
-
});
|
|
112
|
-
emitter.on("group:end", (payload) => {
|
|
113
|
-
this.currentGroupName = void 0;
|
|
114
|
-
this.onGroupEnd(payload);
|
|
115
|
-
});
|
|
116
|
-
emitter.on("suite:start", (payload) => {
|
|
117
|
-
this.currentSuiteName = payload.name;
|
|
118
|
-
this.onSuiteStart(payload);
|
|
119
|
-
});
|
|
120
|
-
emitter.on("suite:end", (payload) => {
|
|
121
|
-
this.currentSuiteName = void 0;
|
|
122
|
-
this.onSuiteEnd(payload);
|
|
123
|
-
});
|
|
124
|
-
emitter.on("runner:start", async (payload) => {
|
|
125
|
-
await this.start(payload);
|
|
126
|
-
});
|
|
127
|
-
emitter.on("runner:end", async (payload) => {
|
|
128
|
-
await this.end(payload);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
var TestContext$1 = class extends TestContext {
|
|
133
|
-
constructor(test) {
|
|
134
|
-
super();
|
|
135
|
-
this.test = test;
|
|
136
|
-
this.cleanup = (cleanupCallback) => {
|
|
137
|
-
test.cleanup(cleanupCallback);
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
var Test$1 = class extends Test {
|
|
142
|
-
static executedCallbacks = [];
|
|
143
|
-
static executingCallbacks = [];
|
|
144
|
-
throws(message, errorConstructor) {
|
|
145
|
-
const errorInPoint = new AssertionError({});
|
|
146
|
-
const existingExecutor = this.options.executor;
|
|
147
|
-
if (!existingExecutor) throw new Error("Cannot use \"test.throws\" method without a test callback");
|
|
148
|
-
this.options.executor = async (...args) => {
|
|
149
|
-
let raisedException;
|
|
150
|
-
try {
|
|
151
|
-
await existingExecutor(...args);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
raisedException = error;
|
|
154
|
-
}
|
|
155
|
-
if (!raisedException) {
|
|
156
|
-
errorInPoint.message = "Expected test to throw an exception";
|
|
157
|
-
throw errorInPoint;
|
|
158
|
-
}
|
|
159
|
-
if (errorConstructor && !(raisedException instanceof errorConstructor)) {
|
|
160
|
-
errorInPoint.message = `Expected test to throw "${inspect(errorConstructor)}"`;
|
|
161
|
-
throw errorInPoint;
|
|
162
|
-
}
|
|
163
|
-
const exceptionMessage = raisedException.message;
|
|
164
|
-
if (!exceptionMessage || typeof exceptionMessage !== "string") {
|
|
165
|
-
errorInPoint.message = "Expected test to throw an exception with message property";
|
|
166
|
-
throw errorInPoint;
|
|
167
|
-
}
|
|
168
|
-
if (typeof message === "string") {
|
|
169
|
-
if (exceptionMessage !== message) {
|
|
170
|
-
errorInPoint.message = `Expected test to throw "${message}". Instead received "${raisedException.message}"`;
|
|
171
|
-
errorInPoint.actual = raisedException.message;
|
|
172
|
-
errorInPoint.expected = message;
|
|
173
|
-
throw errorInPoint;
|
|
174
|
-
}
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (!message.test(exceptionMessage)) {
|
|
178
|
-
errorInPoint.message = `Expected test error to match "${message}" regular expression`;
|
|
179
|
-
throw errorInPoint;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
var Group$1 = class extends Group {};
|
|
186
|
-
var Suite$1 = class extends Suite {};
|
|
187
|
-
var Runner$1 = class extends Runner {};
|
|
188
|
-
const colors = supportsColor.stdout ? useColors.ansi() : useColors.silent();
|
|
189
|
-
const icons = process.platform === "win32" && !process.env.WT_SESSION ? {
|
|
190
|
-
tick: "√",
|
|
191
|
-
cross: "×",
|
|
192
|
-
bullet: "*",
|
|
193
|
-
nodejs: "♦",
|
|
194
|
-
pointer: ">",
|
|
195
|
-
info: "i",
|
|
196
|
-
warning: "‼",
|
|
197
|
-
branch: " -",
|
|
198
|
-
squareSmallFilled: "[█]"
|
|
199
|
-
} : {
|
|
200
|
-
tick: "✔",
|
|
201
|
-
cross: "✖",
|
|
202
|
-
bullet: "●",
|
|
203
|
-
nodejs: "⬢",
|
|
204
|
-
pointer: "❯",
|
|
205
|
-
info: "ℹ",
|
|
206
|
-
warning: "⚠",
|
|
207
|
-
branch: "└──",
|
|
208
|
-
squareSmallFilled: "◼"
|
|
209
|
-
};
|
|
210
|
-
function formatPinnedTest(test) {
|
|
211
|
-
let fileName = "";
|
|
212
|
-
let line = 0;
|
|
213
|
-
let column = 0;
|
|
214
|
-
try {
|
|
215
|
-
test.options.meta.abort("Finding pinned test location");
|
|
216
|
-
} catch (error) {
|
|
217
|
-
const frame = parse(error).find((f) => f.fileName && f.lineNumber !== void 0 && f.columnNumber !== void 0 && !f.fileName.includes("node:") && !f.fileName.includes("ext:") && !f.fileName.includes("node_modules/"));
|
|
218
|
-
if (frame) {
|
|
219
|
-
fileName = frame.fileName.startsWith("file:") ? string.toUnixSlash(fileURLToPath(frame.fileName)) : string.toUnixSlash(frame.fileName);
|
|
220
|
-
line = frame.lineNumber;
|
|
221
|
-
column = frame.columnNumber;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return `${colors.yellow(` ⁃ ${test.title}`)}\n${colors.dim(` ${fileName}:${line}:${column}`)}`;
|
|
225
|
-
}
|
|
226
|
-
function printPinnedTests(runner) {
|
|
227
|
-
let pinnedTests = [];
|
|
228
|
-
runner.suites.forEach((suite) => {
|
|
229
|
-
suite.stack.forEach((testOrGroup) => {
|
|
230
|
-
if (testOrGroup instanceof Group$1) testOrGroup.tests.forEach(($test) => {
|
|
231
|
-
if ($test.isPinned) pinnedTests.push(formatPinnedTest($test));
|
|
232
|
-
});
|
|
233
|
-
else if (testOrGroup.isPinned) pinnedTests.push(formatPinnedTest(testOrGroup));
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
if (pinnedTests.length) {
|
|
237
|
-
console.log(colors.bgYellow().black(` ${pinnedTests.length} pinned test(s) found `));
|
|
238
|
-
pinnedTests.forEach((row) => console.log(row));
|
|
239
|
-
} else console.log(colors.bgYellow().black(` No pinned tests found `));
|
|
240
|
-
}
|
|
241
|
-
export { Group$1 as a, Suite$1 as c, BaseReporter as d, Emitter as i, Test$1 as l, icons as n, Refiner as o, printPinnedTests as r, Runner$1 as s, colors as t, TestContext$1 as u };
|
package/build/main-CB1nhl6c.js
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
import { d as BaseReporter, n as icons, t as colors } from "./helpers-BlHaYYTh.js";
|
|
2
|
-
import { ErrorsPrinter } from "@japa/errors-printer";
|
|
3
|
-
import { stripVTControlCharacters } from "node:util";
|
|
4
|
-
import { relative } from "node:path";
|
|
5
|
-
import string from "@poppinss/string";
|
|
6
|
-
var DotReporter = class extends BaseReporter {
|
|
7
|
-
onTestEnd(payload) {
|
|
8
|
-
let output = "";
|
|
9
|
-
if (payload.isTodo) output = colors.cyan(icons.info);
|
|
10
|
-
else if (payload.hasError) output = colors.red(icons.cross);
|
|
11
|
-
else if (payload.isSkipped) output = colors.yellow(icons.bullet);
|
|
12
|
-
else if (payload.isFailing) output = colors.magenta(icons.squareSmallFilled);
|
|
13
|
-
else output = colors.green(icons.tick);
|
|
14
|
-
process.stdout.write(`${output}`);
|
|
15
|
-
}
|
|
16
|
-
async end() {
|
|
17
|
-
console.log("");
|
|
18
|
-
await this.printSummary(this.runner.getSummary());
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var SpecReporter = class extends BaseReporter {
|
|
22
|
-
#isFirstLoneTest = true;
|
|
23
|
-
#getTestIcon(payload) {
|
|
24
|
-
if (payload.isTodo) return colors.cyan(icons.info);
|
|
25
|
-
if (payload.hasError) return colors.red(icons.cross);
|
|
26
|
-
if (payload.isSkipped) return colors.yellow(icons.bullet);
|
|
27
|
-
if (payload.isFailing) return colors.magenta(icons.squareSmallFilled);
|
|
28
|
-
return colors.green(icons.tick);
|
|
29
|
-
}
|
|
30
|
-
#getTestMessage(payload) {
|
|
31
|
-
const message = payload.title.expanded;
|
|
32
|
-
if (payload.isTodo) return colors.blue(message);
|
|
33
|
-
if (payload.hasError) return colors.red(message);
|
|
34
|
-
if (payload.isSkipped) return colors.yellow(message);
|
|
35
|
-
if (payload.isFailing) return colors.magenta(message);
|
|
36
|
-
return colors.grey(message);
|
|
37
|
-
}
|
|
38
|
-
#getSubText(payload) {
|
|
39
|
-
if (payload.isSkipped && payload.skipReason) return colors.dim(`${icons.branch} ${colors.italic(payload.skipReason)}`);
|
|
40
|
-
if (!payload.isFailing) return;
|
|
41
|
-
if (payload.hasError) {
|
|
42
|
-
const message = payload.errors.find((error) => error.phase === "test")?.error.message ?? `Test marked with ".fails()" must finish with an error`;
|
|
43
|
-
return colors.dim(`${icons.branch} ${colors.italic(message)}`);
|
|
44
|
-
}
|
|
45
|
-
if (payload.failReason) return colors.dim(`${icons.branch} ${colors.italic(payload.failReason)}`);
|
|
46
|
-
const testErrorMessage = payload.errors.find((error) => error.phase === "test");
|
|
47
|
-
if (testErrorMessage && testErrorMessage.error) return colors.dim(`${icons.branch} ${colors.italic(testErrorMessage.error.message)}`);
|
|
48
|
-
}
|
|
49
|
-
#getRelativeFilename(fileName) {
|
|
50
|
-
return relative(process.cwd(), fileName);
|
|
51
|
-
}
|
|
52
|
-
#printTest(payload) {
|
|
53
|
-
const icon = this.#getTestIcon(payload);
|
|
54
|
-
const message = this.#getTestMessage(payload);
|
|
55
|
-
const prefix = payload.isPinned ? colors.yellow("[PINNED] ") : "";
|
|
56
|
-
const indentation = this.currentFileName || this.currentGroupName ? " " : "";
|
|
57
|
-
const duration = colors.dim(`(${string.milliseconds.format(Number(payload.duration.toFixed(2)))})`);
|
|
58
|
-
const retries = payload.retryAttempt && payload.retryAttempt > 1 ? colors.dim(`(x${payload.retryAttempt}) `) : "";
|
|
59
|
-
let subText = this.#getSubText(payload);
|
|
60
|
-
subText = subText ? `\n${indentation} ${subText}` : "";
|
|
61
|
-
console.log(`${indentation}${icon} ${prefix}${retries}${message} ${duration}${subText}`);
|
|
62
|
-
}
|
|
63
|
-
#printGroup(payload) {
|
|
64
|
-
const title = this.currentSuiteName !== "default" ? `${this.currentSuiteName} / ${payload.title}` : payload.title;
|
|
65
|
-
const suffix = this.currentFileName ? colors.dim(` (${this.#getRelativeFilename(this.currentFileName)})`) : "";
|
|
66
|
-
console.log(`\n${title}${suffix}`);
|
|
67
|
-
}
|
|
68
|
-
onTestStart() {
|
|
69
|
-
if (this.currentFileName && this.#isFirstLoneTest) console.log(`\n${colors.dim(this.#getRelativeFilename(this.currentFileName))}`);
|
|
70
|
-
this.#isFirstLoneTest = false;
|
|
71
|
-
}
|
|
72
|
-
onTestEnd(payload) {
|
|
73
|
-
this.#printTest(payload);
|
|
74
|
-
}
|
|
75
|
-
onGroupStart(payload) {
|
|
76
|
-
this.#isFirstLoneTest = false;
|
|
77
|
-
this.#printGroup(payload);
|
|
78
|
-
}
|
|
79
|
-
onGroupEnd() {
|
|
80
|
-
this.#isFirstLoneTest = true;
|
|
81
|
-
}
|
|
82
|
-
async end() {
|
|
83
|
-
const summary = this.runner.getSummary();
|
|
84
|
-
await this.printSummary(summary);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const list = [
|
|
88
|
-
Error,
|
|
89
|
-
EvalError,
|
|
90
|
-
RangeError,
|
|
91
|
-
ReferenceError,
|
|
92
|
-
SyntaxError,
|
|
93
|
-
TypeError,
|
|
94
|
-
URIError,
|
|
95
|
-
AggregateError,
|
|
96
|
-
globalThis.DOMException,
|
|
97
|
-
globalThis.AssertionError,
|
|
98
|
-
globalThis.SystemError
|
|
99
|
-
].filter(Boolean).map((constructor) => [constructor.name, constructor]);
|
|
100
|
-
const errorConstructors = new Map(list);
|
|
101
|
-
Error;
|
|
102
|
-
const errorProperties = [
|
|
103
|
-
{
|
|
104
|
-
property: "name",
|
|
105
|
-
enumerable: false
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
property: "message",
|
|
109
|
-
enumerable: false
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
property: "stack",
|
|
113
|
-
enumerable: false
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
property: "code",
|
|
117
|
-
enumerable: true
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
property: "cause",
|
|
121
|
-
enumerable: false
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
property: "errors",
|
|
125
|
-
enumerable: false
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
129
|
-
const toJSON = (from) => {
|
|
130
|
-
toJsonWasCalled.add(from);
|
|
131
|
-
const json = from.toJSON();
|
|
132
|
-
toJsonWasCalled.delete(from);
|
|
133
|
-
return json;
|
|
134
|
-
};
|
|
135
|
-
const newError = (name) => {
|
|
136
|
-
const ErrorConstructor = errorConstructors.get(name) ?? Error;
|
|
137
|
-
return ErrorConstructor === AggregateError ? new ErrorConstructor([]) : new ErrorConstructor();
|
|
138
|
-
};
|
|
139
|
-
const destroyCircular = ({ from, seen, to, forceEnumerable, maxDepth, depth, useToJSON, serialize }) => {
|
|
140
|
-
if (!to) if (Array.isArray(from)) to = [];
|
|
141
|
-
else if (!serialize && isErrorLike(from)) to = newError(from.name);
|
|
142
|
-
else to = {};
|
|
143
|
-
seen.push(from);
|
|
144
|
-
if (depth >= maxDepth) return to;
|
|
145
|
-
if (useToJSON && typeof from.toJSON === "function" && !toJsonWasCalled.has(from)) return toJSON(from);
|
|
146
|
-
const continueDestroyCircular = (value) => destroyCircular({
|
|
147
|
-
from: value,
|
|
148
|
-
seen: [...seen],
|
|
149
|
-
forceEnumerable,
|
|
150
|
-
maxDepth,
|
|
151
|
-
depth,
|
|
152
|
-
useToJSON,
|
|
153
|
-
serialize
|
|
154
|
-
});
|
|
155
|
-
for (const [key, value] of Object.entries(from)) {
|
|
156
|
-
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
157
|
-
to[key] = "[object Buffer]";
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
161
|
-
to[key] = "[object Stream]";
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (typeof value === "function") continue;
|
|
165
|
-
if (!value || typeof value !== "object") {
|
|
166
|
-
try {
|
|
167
|
-
to[key] = value;
|
|
168
|
-
} catch {}
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (!seen.includes(from[key])) {
|
|
172
|
-
depth++;
|
|
173
|
-
to[key] = continueDestroyCircular(from[key]);
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
to[key] = "[Circular]";
|
|
177
|
-
}
|
|
178
|
-
if (serialize || to instanceof Error) {
|
|
179
|
-
for (const { property, enumerable } of errorProperties) if (from[property] !== void 0 && from[property] !== null) Object.defineProperty(to, property, {
|
|
180
|
-
value: isErrorLike(from[property]) || Array.isArray(from[property]) ? continueDestroyCircular(from[property]) : from[property],
|
|
181
|
-
enumerable: forceEnumerable ? true : enumerable,
|
|
182
|
-
configurable: true,
|
|
183
|
-
writable: true
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
return to;
|
|
187
|
-
};
|
|
188
|
-
function serializeError(value, options = {}) {
|
|
189
|
-
const { maxDepth = Number.POSITIVE_INFINITY, useToJSON = true } = options;
|
|
190
|
-
if (typeof value === "object" && value !== null) return destroyCircular({
|
|
191
|
-
from: value,
|
|
192
|
-
seen: [],
|
|
193
|
-
forceEnumerable: true,
|
|
194
|
-
maxDepth,
|
|
195
|
-
depth: 0,
|
|
196
|
-
useToJSON,
|
|
197
|
-
serialize: true
|
|
198
|
-
});
|
|
199
|
-
if (typeof value === "function") return `[Function: ${value.name || "anonymous"}]`;
|
|
200
|
-
return value;
|
|
201
|
-
}
|
|
202
|
-
function isErrorLike(value) {
|
|
203
|
-
return Boolean(value) && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && typeof value.stack === "string";
|
|
204
|
-
}
|
|
205
|
-
var NdJSONReporter = class extends BaseReporter {
|
|
206
|
-
#getRelativeFilename(fileName) {
|
|
207
|
-
return relative(process.cwd(), fileName);
|
|
208
|
-
}
|
|
209
|
-
#serializeErrors(errors) {
|
|
210
|
-
return errors.map((error) => ({
|
|
211
|
-
phase: error.phase,
|
|
212
|
-
error: serializeError(error.error)
|
|
213
|
-
}));
|
|
214
|
-
}
|
|
215
|
-
onTestEnd(payload) {
|
|
216
|
-
console.log(JSON.stringify({
|
|
217
|
-
event: "test:end",
|
|
218
|
-
filePath: this.currentFileName,
|
|
219
|
-
relativePath: this.currentFileName ? this.#getRelativeFilename(this.currentFileName) : void 0,
|
|
220
|
-
title: payload.title,
|
|
221
|
-
duration: payload.duration,
|
|
222
|
-
failReason: payload.failReason,
|
|
223
|
-
isFailing: payload.isFailing,
|
|
224
|
-
skipReason: payload.skipReason,
|
|
225
|
-
isSkipped: payload.isSkipped,
|
|
226
|
-
isTodo: payload.isTodo,
|
|
227
|
-
isPinned: payload.isPinned,
|
|
228
|
-
retryAttempt: payload.retryAttempt,
|
|
229
|
-
retries: payload.retries,
|
|
230
|
-
errors: this.#serializeErrors(payload.errors)
|
|
231
|
-
}));
|
|
232
|
-
}
|
|
233
|
-
onGroupStart(payload) {
|
|
234
|
-
console.log(JSON.stringify({
|
|
235
|
-
event: "group:start",
|
|
236
|
-
title: payload.title
|
|
237
|
-
}));
|
|
238
|
-
}
|
|
239
|
-
onGroupEnd(payload) {
|
|
240
|
-
JSON.stringify({
|
|
241
|
-
event: "group:end",
|
|
242
|
-
title: payload.title,
|
|
243
|
-
errors: this.#serializeErrors(payload.errors)
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
onSuiteStart(payload) {
|
|
247
|
-
console.log(JSON.stringify({
|
|
248
|
-
event: "suite:start",
|
|
249
|
-
...payload
|
|
250
|
-
}));
|
|
251
|
-
}
|
|
252
|
-
onSuiteEnd(payload) {
|
|
253
|
-
console.log(JSON.stringify({
|
|
254
|
-
event: "suite:end",
|
|
255
|
-
name: payload.name,
|
|
256
|
-
hasError: payload.hasError,
|
|
257
|
-
errors: this.#serializeErrors(payload.errors)
|
|
258
|
-
}));
|
|
259
|
-
}
|
|
260
|
-
async end() {
|
|
261
|
-
const summary = this.runner.getSummary();
|
|
262
|
-
console.log(JSON.stringify({
|
|
263
|
-
aggregates: summary.aggregates,
|
|
264
|
-
duration: summary.duration,
|
|
265
|
-
failedTestsTitles: summary.failedTestsTitles,
|
|
266
|
-
hasError: summary.hasError
|
|
267
|
-
}));
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
var GithubReporter = class extends BaseReporter {
|
|
271
|
-
escapeMessage(value) {
|
|
272
|
-
return value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
273
|
-
}
|
|
274
|
-
escapeProperty(value) {
|
|
275
|
-
return value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A").replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
276
|
-
}
|
|
277
|
-
formatMessage({ command, properties, message }) {
|
|
278
|
-
let result = `::${command}`;
|
|
279
|
-
Object.entries(properties).forEach(([k, v], i) => {
|
|
280
|
-
result += i === 0 ? " " : ",";
|
|
281
|
-
result += `${k}=${this.escapeProperty(v)}`;
|
|
282
|
-
});
|
|
283
|
-
result += `::${this.escapeMessage(message)}`;
|
|
284
|
-
return result;
|
|
285
|
-
}
|
|
286
|
-
async getErrorAnnotation(printer, error) {
|
|
287
|
-
const parsedError = await printer.parseError(error.error);
|
|
288
|
-
if (!("frames" in parsedError)) return;
|
|
289
|
-
const mainFrame = parsedError.frames.find((frame) => frame.type === "app");
|
|
290
|
-
if (!mainFrame) return;
|
|
291
|
-
return this.formatMessage({
|
|
292
|
-
command: "error",
|
|
293
|
-
properties: {
|
|
294
|
-
file: string.toUnixSlash(relative(process.cwd(), mainFrame.fileName)),
|
|
295
|
-
title: error.title,
|
|
296
|
-
line: String(mainFrame.lineNumber),
|
|
297
|
-
column: String(mainFrame.columnNumber)
|
|
298
|
-
},
|
|
299
|
-
message: stripVTControlCharacters(parsedError.message)
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
async end() {
|
|
303
|
-
const summary = this.runner.getSummary();
|
|
304
|
-
const errorsList = this.aggregateErrors(summary);
|
|
305
|
-
const errorPrinter = new ErrorsPrinter(this.options);
|
|
306
|
-
for (let error of errorsList) {
|
|
307
|
-
const formatted = await this.getErrorAnnotation(errorPrinter, error);
|
|
308
|
-
if (formatted) console.log(`\n${formatted}`);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
const spec = (options) => {
|
|
313
|
-
return {
|
|
314
|
-
name: "spec",
|
|
315
|
-
handler: (...args) => new SpecReporter(options).boot(...args)
|
|
316
|
-
};
|
|
317
|
-
};
|
|
318
|
-
const dot = (options) => {
|
|
319
|
-
return {
|
|
320
|
-
name: "dot",
|
|
321
|
-
handler: (...args) => new DotReporter(options).boot(...args)
|
|
322
|
-
};
|
|
323
|
-
};
|
|
324
|
-
const ndjson = (options) => {
|
|
325
|
-
return {
|
|
326
|
-
name: "ndjson",
|
|
327
|
-
handler: (...args) => new NdJSONReporter(options).boot(...args)
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
const github = (options) => {
|
|
331
|
-
return {
|
|
332
|
-
name: "github",
|
|
333
|
-
handler: (...args) => new GithubReporter(options).boot(...args)
|
|
334
|
-
};
|
|
335
|
-
};
|
|
336
|
-
export { spec as i, github as n, ndjson as r, dot as t };
|