@japa/runner 3.0.0-6 → 3.0.0-8
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/build/chunk-7THDHQFT.js +283 -0
- package/build/chunk-HN4AVHWN.js +17 -0
- package/build/chunk-MCOW34SG.js +269 -0
- package/build/chunk-W5IABAQU.js +502 -0
- package/build/factories/main.d.ts +42 -2
- package/build/factories/main.js +209 -13
- package/build/index.d.ts +14 -9
- package/build/index.js +237 -202
- package/build/main-63126780.d.ts +109 -0
- package/build/modules/core/main.d.ts +3 -62
- package/build/modules/core/main.js +21 -121
- package/build/src/reporters/main.d.ts +9 -4
- package/build/src/reporters/main.js +11 -37
- package/build/src/types.d.ts +23 -19
- package/build/src/types.js +14 -9
- package/package.json +41 -32
- package/build/factories/runner.d.ts +0 -27
- package/build/factories/runner.js +0 -206
- package/build/modules/core/reporters/base.d.ts +0 -41
- package/build/modules/core/reporters/base.js +0 -183
- package/build/modules/core/types.d.ts +0 -5
- package/build/modules/core/types.js +0 -9
- package/build/src/cli_parser.d.ts +0 -14
- package/build/src/cli_parser.js +0 -75
- package/build/src/config_manager.d.ts +0 -18
- package/build/src/config_manager.js +0 -168
- package/build/src/create_test.d.ts +0 -21
- package/build/src/create_test.js +0 -53
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/exceptions_manager.d.ts +0 -19
- package/build/src/exceptions_manager.js +0 -85
- package/build/src/files_manager.d.ts +0 -18
- package/build/src/files_manager.js +0 -57
- package/build/src/helpers.d.ts +0 -22
- package/build/src/helpers.js +0 -10
- package/build/src/hooks.d.ts +0 -20
- package/build/src/hooks.js +0 -46
- package/build/src/planner.d.ts +0 -25
- package/build/src/planner.js +0 -98
- package/build/src/plugins/retry.d.ts +0 -20
- package/build/src/plugins/retry.js +0 -66
- package/build/src/reporters/dot.d.ts +0 -15
- package/build/src/reporters/dot.js +0 -41
- package/build/src/reporters/ndjson.d.ts +0 -15
- package/build/src/reporters/ndjson.js +0 -86
- package/build/src/reporters/spec.d.ts +0 -13
- package/build/src/reporters/spec.js +0 -154
- package/build/src/validator.d.ts +0 -30
- package/build/src/validator.js +0 -85
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseReporter
|
|
3
|
+
} from "./chunk-MCOW34SG.js";
|
|
4
|
+
|
|
5
|
+
// src/helpers.ts
|
|
6
|
+
import useColors from "@poppinss/colors";
|
|
7
|
+
var colors = useColors.ansi();
|
|
8
|
+
var icons = process.platform === "win32" && !process.env.WT_SESSION ? {
|
|
9
|
+
tick: "\u221A",
|
|
10
|
+
cross: "\xD7",
|
|
11
|
+
bullet: "*",
|
|
12
|
+
nodejs: "\u2666",
|
|
13
|
+
pointer: ">",
|
|
14
|
+
info: "i",
|
|
15
|
+
warning: "\u203C",
|
|
16
|
+
squareSmallFilled: "[\u2588]"
|
|
17
|
+
} : {
|
|
18
|
+
tick: "\u2714",
|
|
19
|
+
cross: "\u2716",
|
|
20
|
+
bullet: "\u25CF",
|
|
21
|
+
nodejs: "\u2B22",
|
|
22
|
+
pointer: "\u276F",
|
|
23
|
+
info: "\u2139",
|
|
24
|
+
warning: "\u26A0",
|
|
25
|
+
squareSmallFilled: "\u25FC"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/reporters/dot.ts
|
|
29
|
+
var DotReporter = class extends BaseReporter {
|
|
30
|
+
/**
|
|
31
|
+
* When a test ended
|
|
32
|
+
*/
|
|
33
|
+
onTestEnd(payload) {
|
|
34
|
+
let output = "";
|
|
35
|
+
if (payload.isTodo) {
|
|
36
|
+
output = colors.cyan(icons.info);
|
|
37
|
+
} else if (payload.hasError || payload.isFailing) {
|
|
38
|
+
output = payload.hasError ? colors.magenta(icons.squareSmallFilled) : colors.red(icons.cross);
|
|
39
|
+
} else if (payload.isSkipped) {
|
|
40
|
+
output = colors.yellow(icons.bullet);
|
|
41
|
+
} else {
|
|
42
|
+
output = colors.green(icons.tick);
|
|
43
|
+
}
|
|
44
|
+
process.stdout.write(`${output}`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* When test runner ended
|
|
48
|
+
*/
|
|
49
|
+
async end() {
|
|
50
|
+
console.log("");
|
|
51
|
+
await this.printSummary(this.runner.getSummary());
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// src/reporters/spec.ts
|
|
56
|
+
import ms from "ms";
|
|
57
|
+
import { relative } from "node:path";
|
|
58
|
+
var SpecReporter = class extends BaseReporter {
|
|
59
|
+
/**
|
|
60
|
+
* Tracking if the first event we get is for a test without any parent group
|
|
61
|
+
* We need this to decide the display style for tests without groups.
|
|
62
|
+
*/
|
|
63
|
+
#isFirstLoneTest = true;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the icon for the test
|
|
66
|
+
*/
|
|
67
|
+
#getTestIcon(payload) {
|
|
68
|
+
if (payload.isTodo) {
|
|
69
|
+
return colors.cyan(icons.info);
|
|
70
|
+
}
|
|
71
|
+
if (payload.isFailing) {
|
|
72
|
+
return payload.hasError ? colors.magenta(icons.squareSmallFilled) : colors.red(icons.cross);
|
|
73
|
+
}
|
|
74
|
+
if (payload.hasError) {
|
|
75
|
+
return colors.red(icons.cross);
|
|
76
|
+
}
|
|
77
|
+
if (payload.isSkipped) {
|
|
78
|
+
return colors.yellow(icons.bullet);
|
|
79
|
+
}
|
|
80
|
+
return colors.green(icons.tick);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the test message
|
|
84
|
+
*/
|
|
85
|
+
#getTestMessage(payload) {
|
|
86
|
+
const message = typeof payload.title === "string" ? payload.title : payload.title.expanded;
|
|
87
|
+
if (payload.isTodo) {
|
|
88
|
+
return colors.blue(message);
|
|
89
|
+
}
|
|
90
|
+
if (payload.isFailing) {
|
|
91
|
+
return payload.hasError ? colors.magenta(message) : colors.red(message);
|
|
92
|
+
}
|
|
93
|
+
if (payload.hasError) {
|
|
94
|
+
return colors.red(message);
|
|
95
|
+
}
|
|
96
|
+
if (payload.isSkipped) {
|
|
97
|
+
return colors.yellow(message);
|
|
98
|
+
}
|
|
99
|
+
return colors.grey(message);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the subtext message for the test
|
|
103
|
+
*/
|
|
104
|
+
#getSubText(payload) {
|
|
105
|
+
if (payload.isSkipped && payload.skipReason) {
|
|
106
|
+
return colors.yellow(payload.skipReason);
|
|
107
|
+
}
|
|
108
|
+
if (!payload.isFailing) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!payload.hasError) {
|
|
112
|
+
return colors.magenta(`Test marked with ".fails()" must finish with an error`);
|
|
113
|
+
}
|
|
114
|
+
if (payload.failReason) {
|
|
115
|
+
return colors.magenta(payload.failReason);
|
|
116
|
+
}
|
|
117
|
+
const testErrorMessage = payload.errors.find((error) => error.phase === "test");
|
|
118
|
+
if (testErrorMessage && testErrorMessage.error) {
|
|
119
|
+
return colors.magenta(testErrorMessage.error.message);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the filename relative from the current working dir
|
|
124
|
+
*/
|
|
125
|
+
#getRelativeFilename(fileName) {
|
|
126
|
+
return relative(process.cwd(), fileName);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Prints the test details
|
|
130
|
+
*/
|
|
131
|
+
#printTest(payload) {
|
|
132
|
+
const icon = this.#getTestIcon(payload);
|
|
133
|
+
const message = this.#getTestMessage(payload);
|
|
134
|
+
const prefix = payload.isPinned ? colors.yellow("[PINNED] ") : "";
|
|
135
|
+
const indentation = this.currentFileName || this.currentGroupName ? " " : "";
|
|
136
|
+
const duration = colors.dim(`(${ms(Number(payload.duration.toFixed(2)))})`);
|
|
137
|
+
const retries = payload.retryAttempt && payload.retryAttempt > 1 ? colors.dim(`(x${payload.retryAttempt}) `) : "";
|
|
138
|
+
let subText = this.#getSubText(payload);
|
|
139
|
+
subText = subText ? `
|
|
140
|
+
${indentation} ${subText}` : "";
|
|
141
|
+
console.log(`${indentation}${icon} ${prefix}${retries}${message} ${duration}${subText}`);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Prints the group name
|
|
145
|
+
*/
|
|
146
|
+
#printGroup(payload) {
|
|
147
|
+
const title = this.currentSuiteName !== "default" ? `${this.currentSuiteName} / ${payload.title}` : payload.title;
|
|
148
|
+
const suffix = this.currentFileName ? colors.dim(` (${this.#getRelativeFilename(this.currentFileName)})`) : "";
|
|
149
|
+
console.log(`
|
|
150
|
+
${title}${suffix}`);
|
|
151
|
+
}
|
|
152
|
+
onTestStart() {
|
|
153
|
+
if (this.currentFileName && this.#isFirstLoneTest) {
|
|
154
|
+
console.log(`
|
|
155
|
+
${colors.dim(this.#getRelativeFilename(this.currentFileName))}`);
|
|
156
|
+
}
|
|
157
|
+
this.#isFirstLoneTest = false;
|
|
158
|
+
}
|
|
159
|
+
onTestEnd(payload) {
|
|
160
|
+
this.#printTest(payload);
|
|
161
|
+
}
|
|
162
|
+
onGroupStart(payload) {
|
|
163
|
+
this.#isFirstLoneTest = false;
|
|
164
|
+
this.#printGroup(payload);
|
|
165
|
+
}
|
|
166
|
+
onGroupEnd() {
|
|
167
|
+
this.#isFirstLoneTest = true;
|
|
168
|
+
}
|
|
169
|
+
async end() {
|
|
170
|
+
const summary = this.runner.getSummary();
|
|
171
|
+
await this.printSummary(summary);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// src/reporters/ndjson.ts
|
|
176
|
+
import { relative as relative2 } from "node:path";
|
|
177
|
+
import { serializeError } from "serialize-error";
|
|
178
|
+
var NdJSONReporter = class extends BaseReporter {
|
|
179
|
+
/**
|
|
180
|
+
* Returns the filename relative from the current working dir
|
|
181
|
+
*/
|
|
182
|
+
#getRelativeFilename(fileName) {
|
|
183
|
+
return relative2(process.cwd(), fileName);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Serialize errors to JSON
|
|
187
|
+
*/
|
|
188
|
+
#serializeErrors(errors) {
|
|
189
|
+
return errors.map((error) => ({
|
|
190
|
+
phase: error.phase,
|
|
191
|
+
error: serializeError(error.error)
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
onTestEnd(payload) {
|
|
195
|
+
console.log(
|
|
196
|
+
JSON.stringify({
|
|
197
|
+
event: "test:end",
|
|
198
|
+
filePath: this.currentFileName,
|
|
199
|
+
relativePath: this.currentFileName ? this.#getRelativeFilename(this.currentFileName) : void 0,
|
|
200
|
+
title: payload.title,
|
|
201
|
+
duration: payload.duration,
|
|
202
|
+
failReason: payload.failReason,
|
|
203
|
+
isFailing: payload.isFailing,
|
|
204
|
+
skipReason: payload.skipReason,
|
|
205
|
+
isSkipped: payload.isSkipped,
|
|
206
|
+
isTodo: payload.isTodo,
|
|
207
|
+
isPinned: payload.isPinned,
|
|
208
|
+
retryAttempt: payload.retryAttempt,
|
|
209
|
+
retries: payload.retries,
|
|
210
|
+
errors: this.#serializeErrors(payload.errors)
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
onGroupStart(payload) {
|
|
215
|
+
console.log(
|
|
216
|
+
JSON.stringify({
|
|
217
|
+
event: "group:start",
|
|
218
|
+
title: payload.title
|
|
219
|
+
})
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
onGroupEnd(payload) {
|
|
223
|
+
JSON.stringify({
|
|
224
|
+
event: "group:end",
|
|
225
|
+
title: payload.title,
|
|
226
|
+
errors: this.#serializeErrors(payload.errors)
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
onSuiteStart(payload) {
|
|
230
|
+
console.log(
|
|
231
|
+
JSON.stringify({
|
|
232
|
+
event: "suite:start",
|
|
233
|
+
...payload
|
|
234
|
+
})
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
onSuiteEnd(payload) {
|
|
238
|
+
console.log(
|
|
239
|
+
JSON.stringify({
|
|
240
|
+
event: "suite:end",
|
|
241
|
+
...payload
|
|
242
|
+
})
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
async end() {
|
|
246
|
+
const summary = this.runner.getSummary();
|
|
247
|
+
console.log(
|
|
248
|
+
JSON.stringify({
|
|
249
|
+
aggregates: summary.aggregates,
|
|
250
|
+
duration: summary.duration,
|
|
251
|
+
failedTestsTitles: summary.failedTestsTitles,
|
|
252
|
+
hasError: summary.hasError
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/reporters/main.ts
|
|
259
|
+
var spec = (options) => {
|
|
260
|
+
return {
|
|
261
|
+
name: "spec",
|
|
262
|
+
handler: (...args) => new SpecReporter(options).boot(...args)
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
var dot = (options) => {
|
|
266
|
+
return {
|
|
267
|
+
name: "dot",
|
|
268
|
+
handler: (...args) => new DotReporter(options).boot(...args)
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
var ndjson = (options) => {
|
|
272
|
+
return {
|
|
273
|
+
name: "ndjson",
|
|
274
|
+
handler: (...args) => new NdJSONReporter(options).boot(...args)
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export {
|
|
279
|
+
colors,
|
|
280
|
+
spec,
|
|
281
|
+
dot,
|
|
282
|
+
ndjson
|
|
283
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
__reExport
|
|
17
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
// modules/core/main.ts
|
|
2
|
+
import {
|
|
3
|
+
Emitter,
|
|
4
|
+
Refiner,
|
|
5
|
+
Test as BaseTest,
|
|
6
|
+
Suite as BaseSuite,
|
|
7
|
+
Group as BaseGroup,
|
|
8
|
+
Runner as BaseRunner,
|
|
9
|
+
TestContext as BaseTestContext
|
|
10
|
+
} from "@japa/core";
|
|
11
|
+
import { inspect } from "node:util";
|
|
12
|
+
import { AssertionError } from "node:assert";
|
|
13
|
+
|
|
14
|
+
// modules/core/reporters/base.ts
|
|
15
|
+
import ms from "ms";
|
|
16
|
+
import colors from "@poppinss/colors";
|
|
17
|
+
import { ErrorsPrinter } from "@japa/errors-printer";
|
|
18
|
+
var ansi = colors.ansi();
|
|
19
|
+
var BaseReporter = class {
|
|
20
|
+
#options;
|
|
21
|
+
runner;
|
|
22
|
+
/**
|
|
23
|
+
* Path to the file for which the tests are getting executed
|
|
24
|
+
*/
|
|
25
|
+
currentFileName;
|
|
26
|
+
/**
|
|
27
|
+
* Suite for which the tests are getting executed
|
|
28
|
+
*/
|
|
29
|
+
currentSuiteName;
|
|
30
|
+
/**
|
|
31
|
+
* Group for which the tests are getting executed
|
|
32
|
+
*/
|
|
33
|
+
currentGroupName;
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.#options = Object.assign({ stackLinesCount: 2 }, options);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Pretty prints the aggregates
|
|
39
|
+
*/
|
|
40
|
+
#printAggregates(summary) {
|
|
41
|
+
const tests = [];
|
|
42
|
+
if (summary.aggregates.passed) {
|
|
43
|
+
tests.push(ansi.green(`${summary.aggregates.passed} passed`));
|
|
44
|
+
}
|
|
45
|
+
if (summary.aggregates.failed) {
|
|
46
|
+
tests.push(ansi.red(`${summary.aggregates.failed} failed`));
|
|
47
|
+
}
|
|
48
|
+
if (summary.aggregates.todo) {
|
|
49
|
+
tests.push(ansi.cyan(`${summary.aggregates.todo} todo`));
|
|
50
|
+
}
|
|
51
|
+
if (summary.aggregates.skipped) {
|
|
52
|
+
tests.push(ansi.yellow(`${summary.aggregates.skipped} skipped`));
|
|
53
|
+
}
|
|
54
|
+
if (summary.aggregates.regression) {
|
|
55
|
+
tests.push(ansi.magenta(`${summary.aggregates.regression} regression`));
|
|
56
|
+
}
|
|
57
|
+
this.runner.summaryBuilder.use(() => {
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
key: ansi.dim("Tests"),
|
|
61
|
+
value: `${tests.join(", ")} ${ansi.dim(`(${summary.aggregates.total})`)}`
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: ansi.dim("Time"),
|
|
65
|
+
value: ansi.dim(ms(summary.duration))
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
console.log(this.runner.summaryBuilder.build().join("\n"));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Aggregates errors tree to a flat array
|
|
73
|
+
*/
|
|
74
|
+
#aggregateErrors(summary) {
|
|
75
|
+
const errorsList = [];
|
|
76
|
+
summary.failureTree.forEach((suite) => {
|
|
77
|
+
suite.errors.forEach((error) => errorsList.push({ title: suite.name, ...error }));
|
|
78
|
+
suite.children.forEach((testOrGroup) => {
|
|
79
|
+
if (testOrGroup.type === "test") {
|
|
80
|
+
testOrGroup.errors.forEach((error) => {
|
|
81
|
+
errorsList.push({ title: `${suite.name} / ${testOrGroup.title}`, ...error });
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
testOrGroup.errors.forEach((error) => {
|
|
86
|
+
errorsList.push({ title: testOrGroup.name, ...error });
|
|
87
|
+
});
|
|
88
|
+
testOrGroup.children.forEach((test) => {
|
|
89
|
+
test.errors.forEach((error) => {
|
|
90
|
+
errorsList.push({ title: `${testOrGroup.name} / ${test.title}`, ...error });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
return errorsList;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Pretty print errors
|
|
99
|
+
*/
|
|
100
|
+
async #printErrors(summary) {
|
|
101
|
+
if (!summary.failureTree.length) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const errorPrinter = new ErrorsPrinter({
|
|
105
|
+
stackLinesCount: this.#options.stackLinesCount,
|
|
106
|
+
framesMaxLimit: this.#options.framesMaxLimit
|
|
107
|
+
});
|
|
108
|
+
errorPrinter.printSectionHeader("ERRORS");
|
|
109
|
+
await errorPrinter.printErrors(this.#aggregateErrors(summary));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Handlers to capture events
|
|
113
|
+
*/
|
|
114
|
+
onTestStart(_) {
|
|
115
|
+
}
|
|
116
|
+
onTestEnd(_) {
|
|
117
|
+
}
|
|
118
|
+
onGroupStart(_) {
|
|
119
|
+
}
|
|
120
|
+
onGroupEnd(_) {
|
|
121
|
+
}
|
|
122
|
+
onSuiteStart(_) {
|
|
123
|
+
}
|
|
124
|
+
onSuiteEnd(_) {
|
|
125
|
+
}
|
|
126
|
+
async start(_) {
|
|
127
|
+
}
|
|
128
|
+
async end(_) {
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Print tests summary
|
|
132
|
+
*/
|
|
133
|
+
async printSummary(summary) {
|
|
134
|
+
await this.#printErrors(summary);
|
|
135
|
+
console.log("");
|
|
136
|
+
if (summary.aggregates.total === 0 && !summary.hasError) {
|
|
137
|
+
console.log(ansi.bgYellow().black(" NO TESTS EXECUTED "));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (summary.hasError) {
|
|
141
|
+
console.log(ansi.bgRed().black(" FAILED "));
|
|
142
|
+
} else {
|
|
143
|
+
console.log(ansi.bgGreen().black(" PASSED "));
|
|
144
|
+
}
|
|
145
|
+
console.log("");
|
|
146
|
+
this.#printAggregates(summary);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Invoked by the tests runner when tests are about to start
|
|
150
|
+
*/
|
|
151
|
+
boot(runner, emitter) {
|
|
152
|
+
this.runner = runner;
|
|
153
|
+
emitter.on("test:start", (payload) => {
|
|
154
|
+
this.currentFileName = payload.meta.fileName;
|
|
155
|
+
this.onTestStart(payload);
|
|
156
|
+
});
|
|
157
|
+
emitter.on("test:end", (payload) => {
|
|
158
|
+
this.onTestEnd(payload);
|
|
159
|
+
});
|
|
160
|
+
emitter.on("group:start", (payload) => {
|
|
161
|
+
this.currentGroupName = payload.title;
|
|
162
|
+
this.currentFileName = payload.meta.fileName;
|
|
163
|
+
this.onGroupStart(payload);
|
|
164
|
+
});
|
|
165
|
+
emitter.on("group:end", (payload) => {
|
|
166
|
+
this.currentGroupName = void 0;
|
|
167
|
+
this.onGroupEnd(payload);
|
|
168
|
+
});
|
|
169
|
+
emitter.on("suite:start", (payload) => {
|
|
170
|
+
this.currentSuiteName = payload.name;
|
|
171
|
+
this.onSuiteStart(payload);
|
|
172
|
+
});
|
|
173
|
+
emitter.on("suite:end", (payload) => {
|
|
174
|
+
this.currentSuiteName = void 0;
|
|
175
|
+
this.onSuiteEnd(payload);
|
|
176
|
+
});
|
|
177
|
+
emitter.on("runner:start", async (payload) => {
|
|
178
|
+
await this.start(payload);
|
|
179
|
+
});
|
|
180
|
+
emitter.on("runner:end", async (payload) => {
|
|
181
|
+
await this.end(payload);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// modules/core/main.ts
|
|
187
|
+
var TestContext = class extends BaseTestContext {
|
|
188
|
+
constructor(test) {
|
|
189
|
+
super();
|
|
190
|
+
this.test = test;
|
|
191
|
+
this.cleanup = (cleanupCallback) => {
|
|
192
|
+
test.cleanup(cleanupCallback);
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var Test = class extends BaseTest {
|
|
197
|
+
/**
|
|
198
|
+
* @inheritdoc
|
|
199
|
+
*/
|
|
200
|
+
static executedCallbacks = [];
|
|
201
|
+
/**
|
|
202
|
+
* @inheritdoc
|
|
203
|
+
*/
|
|
204
|
+
static executingCallbacks = [];
|
|
205
|
+
/**
|
|
206
|
+
* Assert the test callback throws an exception when a certain
|
|
207
|
+
* error message and optionally is an instance of a given
|
|
208
|
+
* Error class.
|
|
209
|
+
*/
|
|
210
|
+
throws(message, errorConstructor) {
|
|
211
|
+
const errorInPoint = new AssertionError({});
|
|
212
|
+
const existingExecutor = this.options.executor;
|
|
213
|
+
if (!existingExecutor) {
|
|
214
|
+
throw new Error('Cannot use "test.throws" method without a test callback');
|
|
215
|
+
}
|
|
216
|
+
this.options.executor = async (...args) => {
|
|
217
|
+
let raisedException;
|
|
218
|
+
try {
|
|
219
|
+
await existingExecutor(...args);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
raisedException = error;
|
|
222
|
+
}
|
|
223
|
+
if (!raisedException) {
|
|
224
|
+
errorInPoint.message = "Expected test to throw an exception";
|
|
225
|
+
throw errorInPoint;
|
|
226
|
+
}
|
|
227
|
+
if (errorConstructor && !(raisedException instanceof errorConstructor)) {
|
|
228
|
+
errorInPoint.message = `Expected test to throw "${inspect(errorConstructor)}"`;
|
|
229
|
+
throw errorInPoint;
|
|
230
|
+
}
|
|
231
|
+
const exceptionMessage = raisedException.message;
|
|
232
|
+
if (!exceptionMessage || typeof exceptionMessage !== "string") {
|
|
233
|
+
errorInPoint.message = "Expected test to throw an exception with message property";
|
|
234
|
+
throw errorInPoint;
|
|
235
|
+
}
|
|
236
|
+
if (typeof message === "string") {
|
|
237
|
+
if (exceptionMessage !== message) {
|
|
238
|
+
errorInPoint.message = `Expected test to throw "${message}". Instead received "${raisedException.message}"`;
|
|
239
|
+
errorInPoint.actual = raisedException.message;
|
|
240
|
+
errorInPoint.expected = message;
|
|
241
|
+
throw errorInPoint;
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (!message.test(exceptionMessage)) {
|
|
246
|
+
errorInPoint.message = `Expected test error to match "${message}" regular expression`;
|
|
247
|
+
throw errorInPoint;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
return this;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
var Group = class extends BaseGroup {
|
|
254
|
+
};
|
|
255
|
+
var Suite = class extends BaseSuite {
|
|
256
|
+
};
|
|
257
|
+
var Runner = class extends BaseRunner {
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export {
|
|
261
|
+
BaseReporter,
|
|
262
|
+
Emitter,
|
|
263
|
+
Refiner,
|
|
264
|
+
TestContext,
|
|
265
|
+
Test,
|
|
266
|
+
Group,
|
|
267
|
+
Suite,
|
|
268
|
+
Runner
|
|
269
|
+
};
|