@japa/runner 4.0.0 → 4.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/build/{chunk-OGQDXVXY.js → chunk-2KG3PWR4.js} +0 -1
- package/build/{chunk-VDZGMJWM.js → chunk-CYGUHLQ7.js} +9 -10
- package/build/{chunk-PLH254PF.js → chunk-DPWXK7IV.js} +83 -3
- package/build/{chunk-ZBQV333W.js → chunk-WEAHCEFK.js} +5 -5
- package/build/factories/main.js +4 -5
- package/build/index.js +16 -5
- package/build/modules/core/main.js +2 -3
- package/build/modules/core/reporters/base.d.ts +17 -1
- package/build/src/reporters/github.d.ts +35 -0
- package/build/src/reporters/main.d.ts +4 -0
- package/build/src/reporters/main.js +5 -4
- package/build/src/types.js +1 -2
- package/package.json +15 -15
- package/build/chunk-OGQDXVXY.js.map +0 -1
- package/build/chunk-PLH254PF.js.map +0 -1
- package/build/chunk-VDZGMJWM.js.map +0 -1
- package/build/chunk-ZBQV333W.js.map +0 -1
- package/build/factories/main.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/modules/core/main.js.map +0 -1
- package/build/src/reporters/main.js.map +0 -1
- package/build/src/types.js.map +0 -1
|
@@ -43,7 +43,6 @@ var icons = process.platform === "win32" && !process.env.WT_SESSION ? {
|
|
|
43
43
|
|
|
44
44
|
// modules/core/reporters/base.ts
|
|
45
45
|
var BaseReporter = class {
|
|
46
|
-
#options;
|
|
47
46
|
runner;
|
|
48
47
|
/**
|
|
49
48
|
* Path to the file for which the tests are getting executed
|
|
@@ -57,13 +56,14 @@ var BaseReporter = class {
|
|
|
57
56
|
* Group for which the tests are getting executed
|
|
58
57
|
*/
|
|
59
58
|
currentGroupName;
|
|
59
|
+
options;
|
|
60
60
|
constructor(options = {}) {
|
|
61
|
-
this
|
|
61
|
+
this.options = Object.assign({ stackLinesCount: 2 }, options);
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Pretty prints the aggregates
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
printAggregates(summary) {
|
|
67
67
|
const tests = [];
|
|
68
68
|
if (summary.aggregates.passed) {
|
|
69
69
|
tests.push(colors.green(`${summary.aggregates.passed} passed`));
|
|
@@ -97,7 +97,7 @@ var BaseReporter = class {
|
|
|
97
97
|
/**
|
|
98
98
|
* Aggregates errors tree to a flat array
|
|
99
99
|
*/
|
|
100
|
-
|
|
100
|
+
aggregateErrors(summary) {
|
|
101
101
|
const errorsList = [];
|
|
102
102
|
summary.failureTree.forEach((suite) => {
|
|
103
103
|
suite.errors.forEach((error) => errorsList.push({ title: suite.name, ...error }));
|
|
@@ -123,15 +123,15 @@ var BaseReporter = class {
|
|
|
123
123
|
/**
|
|
124
124
|
* Pretty print errors
|
|
125
125
|
*/
|
|
126
|
-
async
|
|
126
|
+
async printErrors(summary) {
|
|
127
127
|
if (!summary.failureTree.length) {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
const errorPrinter = new ErrorsPrinter({
|
|
131
|
-
framesMaxLimit: this
|
|
131
|
+
framesMaxLimit: this.options.framesMaxLimit
|
|
132
132
|
});
|
|
133
133
|
errorPrinter.printSectionHeader("ERRORS");
|
|
134
|
-
await errorPrinter.printErrors(this
|
|
134
|
+
await errorPrinter.printErrors(this.aggregateErrors(summary));
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Handlers to capture events
|
|
@@ -156,7 +156,7 @@ var BaseReporter = class {
|
|
|
156
156
|
* Print tests summary
|
|
157
157
|
*/
|
|
158
158
|
async printSummary(summary) {
|
|
159
|
-
await this
|
|
159
|
+
await this.printErrors(summary);
|
|
160
160
|
console.log("");
|
|
161
161
|
if (summary.aggregates.total === 0 && !summary.hasError) {
|
|
162
162
|
console.log(colors.bgYellow().black(" NO TESTS EXECUTED "));
|
|
@@ -168,7 +168,7 @@ var BaseReporter = class {
|
|
|
168
168
|
console.log(colors.bgGreen().black(" PASSED "));
|
|
169
169
|
}
|
|
170
170
|
console.log("");
|
|
171
|
-
this
|
|
171
|
+
this.printAggregates(summary);
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Invoked by the tests runner when tests are about to start
|
|
@@ -293,4 +293,3 @@ export {
|
|
|
293
293
|
Suite,
|
|
294
294
|
Runner
|
|
295
295
|
};
|
|
296
|
-
//# sourceMappingURL=chunk-VDZGMJWM.js.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
BaseReporter,
|
|
3
3
|
colors,
|
|
4
4
|
icons
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-CYGUHLQ7.js";
|
|
6
6
|
|
|
7
7
|
// src/reporters/dot.ts
|
|
8
8
|
var DotReporter = class extends BaseReporter {
|
|
@@ -239,6 +239,80 @@ var NdJSONReporter = class extends BaseReporter {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
|
|
242
|
+
// src/reporters/github.ts
|
|
243
|
+
import slash from "slash";
|
|
244
|
+
import { relative as relative3 } from "node:path";
|
|
245
|
+
import { stripVTControlCharacters } from "node:util";
|
|
246
|
+
import { ErrorsPrinter } from "@japa/errors-printer";
|
|
247
|
+
var GithubReporter = class extends BaseReporter {
|
|
248
|
+
/**
|
|
249
|
+
* Performs string escape on annotation message as per
|
|
250
|
+
* https://github.com/actions/toolkit/blob/f1d9b4b985e6f0f728b4b766db73498403fd5ca3/packages/core/src/command.ts#L80-L85
|
|
251
|
+
*/
|
|
252
|
+
escapeMessage(value) {
|
|
253
|
+
return value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Performs string escape on annotation properties as per
|
|
257
|
+
* https://github.com/actions/toolkit/blob/f1d9b4b985e6f0f728b4b766db73498403fd5ca3/packages/core/src/command.ts#L80-L85
|
|
258
|
+
*/
|
|
259
|
+
escapeProperty(value) {
|
|
260
|
+
return value.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A").replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Formats the message as per the Github annotations spec.
|
|
264
|
+
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
|
|
265
|
+
*/
|
|
266
|
+
formatMessage({
|
|
267
|
+
command,
|
|
268
|
+
properties,
|
|
269
|
+
message
|
|
270
|
+
}) {
|
|
271
|
+
let result = `::${command}`;
|
|
272
|
+
Object.entries(properties).forEach(([k, v], i) => {
|
|
273
|
+
result += i === 0 ? " " : ",";
|
|
274
|
+
result += `${k}=${this.escapeProperty(v)}`;
|
|
275
|
+
});
|
|
276
|
+
result += `::${this.escapeMessage(message)}`;
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Prints Github annotation for a given error
|
|
281
|
+
*/
|
|
282
|
+
async getErrorAnnotation(printer, error) {
|
|
283
|
+
const parsedError = await printer.parseError(error.error);
|
|
284
|
+
if (!("frames" in parsedError)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const mainFrame = parsedError.frames.find((frame) => frame.type === "app");
|
|
288
|
+
if (!mainFrame) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
return this.formatMessage({
|
|
292
|
+
command: "error",
|
|
293
|
+
properties: {
|
|
294
|
+
file: slash(relative3(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) {
|
|
309
|
+
console.log(`
|
|
310
|
+
${formatted}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
242
316
|
// src/reporters/main.ts
|
|
243
317
|
var spec = (options) => {
|
|
244
318
|
return {
|
|
@@ -258,10 +332,16 @@ var ndjson = (options) => {
|
|
|
258
332
|
handler: (...args) => new NdJSONReporter(options).boot(...args)
|
|
259
333
|
};
|
|
260
334
|
};
|
|
335
|
+
var github = (options) => {
|
|
336
|
+
return {
|
|
337
|
+
name: "github",
|
|
338
|
+
handler: (...args) => new GithubReporter(options).boot(...args)
|
|
339
|
+
};
|
|
340
|
+
};
|
|
261
341
|
|
|
262
342
|
export {
|
|
263
343
|
spec,
|
|
264
344
|
dot,
|
|
265
|
-
ndjson
|
|
345
|
+
ndjson,
|
|
346
|
+
github
|
|
266
347
|
};
|
|
267
|
-
//# sourceMappingURL=chunk-PLH254PF.js.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dot,
|
|
3
|
+
github,
|
|
3
4
|
ndjson,
|
|
4
5
|
spec
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DPWXK7IV.js";
|
|
6
7
|
import {
|
|
7
8
|
Group,
|
|
8
9
|
Refiner,
|
|
9
10
|
Test,
|
|
10
11
|
TestContext,
|
|
11
12
|
colors
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-CYGUHLQ7.js";
|
|
13
14
|
|
|
14
15
|
// src/debug.ts
|
|
15
16
|
import { debuglog } from "node:util";
|
|
@@ -331,8 +332,8 @@ var DEFAULTS = {
|
|
|
331
332
|
forceExit: false,
|
|
332
333
|
plugins: [],
|
|
333
334
|
reporters: {
|
|
334
|
-
activated: ["spec"],
|
|
335
|
-
list: [spec(), ndjson(), dot()]
|
|
335
|
+
activated: ["spec"].concat(process.env.GITHUB_ACTIONS === "true" ? ["github"] : []),
|
|
336
|
+
list: [spec(), ndjson(), dot(), github()]
|
|
336
337
|
},
|
|
337
338
|
importer: (filePath) => import(filePath.href),
|
|
338
339
|
configureSuite: () => {
|
|
@@ -510,4 +511,3 @@ export {
|
|
|
510
511
|
createTest,
|
|
511
512
|
createTestGroup
|
|
512
513
|
};
|
|
513
|
-
//# sourceMappingURL=chunk-ZBQV333W.js.map
|
package/build/factories/main.js
CHANGED
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
Planner,
|
|
6
6
|
createTest,
|
|
7
7
|
createTestGroup
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
} from "../chunk-WEAHCEFK.js";
|
|
9
|
+
import "../chunk-DPWXK7IV.js";
|
|
10
10
|
import {
|
|
11
11
|
Emitter,
|
|
12
12
|
Runner,
|
|
13
13
|
Suite
|
|
14
|
-
} from "../chunk-
|
|
15
|
-
import "../chunk-
|
|
14
|
+
} from "../chunk-CYGUHLQ7.js";
|
|
15
|
+
import "../chunk-2KG3PWR4.js";
|
|
16
16
|
|
|
17
17
|
// factories/runner.ts
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
@@ -232,4 +232,3 @@ export {
|
|
|
232
232
|
runner,
|
|
233
233
|
syncReporter
|
|
234
234
|
};
|
|
235
|
-
//# sourceMappingURL=main.js.map
|
package/build/index.js
CHANGED
|
@@ -7,15 +7,15 @@ import {
|
|
|
7
7
|
createTestGroup,
|
|
8
8
|
debug_default,
|
|
9
9
|
validator_default
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-WEAHCEFK.js";
|
|
11
|
+
import "./chunk-DPWXK7IV.js";
|
|
12
12
|
import {
|
|
13
13
|
Emitter,
|
|
14
14
|
Runner,
|
|
15
15
|
Suite,
|
|
16
16
|
colors
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-CYGUHLQ7.js";
|
|
18
|
+
import "./chunk-2KG3PWR4.js";
|
|
19
19
|
|
|
20
20
|
// index.ts
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
@@ -84,6 +84,7 @@ var ExceptionsManager = class {
|
|
|
84
84
|
*/
|
|
85
85
|
monitor() {
|
|
86
86
|
process.on("uncaughtException", async (error) => {
|
|
87
|
+
debug_default("received uncaught exception %O", error);
|
|
87
88
|
this.hasErrors = true;
|
|
88
89
|
if (this.#state === "watching") {
|
|
89
90
|
this.#exceptionsBuffer.push(error);
|
|
@@ -94,6 +95,7 @@ var ExceptionsManager = class {
|
|
|
94
95
|
}
|
|
95
96
|
});
|
|
96
97
|
process.on("unhandledRejection", async (error) => {
|
|
98
|
+
debug_default("received unhandled rejection %O", error);
|
|
97
99
|
this.hasErrors = true;
|
|
98
100
|
if (this.#state === "watching") {
|
|
99
101
|
this.#rejectionsBuffer.push(error);
|
|
@@ -219,6 +221,7 @@ async function run() {
|
|
|
219
221
|
globalHooks.apply(config);
|
|
220
222
|
await globalHooks.setup(runner);
|
|
221
223
|
for (let suite of suites) {
|
|
224
|
+
debug_default("initiating suite %s", suite.name);
|
|
222
225
|
executionPlanState.suite = new Suite(suite.name, emitter, config.refiner);
|
|
223
226
|
executionPlanState.retries = suite.retries;
|
|
224
227
|
executionPlanState.timeout = suite.timeout;
|
|
@@ -226,6 +229,7 @@ async function run() {
|
|
|
226
229
|
suite.configure(executionPlanState.suite);
|
|
227
230
|
}
|
|
228
231
|
if (cliArgs.bail && cliArgs.bailLayer === "suite") {
|
|
232
|
+
debug_default("enabling bail mode for the suite %s", suite.name);
|
|
229
233
|
executionPlanState.suite.bail(true);
|
|
230
234
|
}
|
|
231
235
|
runner.add(executionPlanState.suite);
|
|
@@ -245,18 +249,26 @@ async function run() {
|
|
|
245
249
|
await exceptionsManager.report();
|
|
246
250
|
const summary = runner.getSummary();
|
|
247
251
|
if (summary.hasError || exceptionsManager.hasErrors) {
|
|
252
|
+
debug_default(
|
|
253
|
+
"updating exit code to 1. summary.hasError %s, process.hasError",
|
|
254
|
+
summary.hasError,
|
|
255
|
+
exceptionsManager.hasErrors
|
|
256
|
+
);
|
|
248
257
|
process.exitCode = 1;
|
|
249
258
|
}
|
|
250
259
|
if (config.forceExit) {
|
|
260
|
+
debug_default("force exiting process");
|
|
251
261
|
process.exit();
|
|
252
262
|
}
|
|
253
263
|
} catch (error) {
|
|
264
|
+
debug_default("error running tests %O", error);
|
|
254
265
|
await globalHooks.teardown(error, runner);
|
|
255
266
|
const printer = new ErrorsPrinter2();
|
|
256
267
|
await printer.printError(error);
|
|
257
268
|
await exceptionsManager.report();
|
|
258
269
|
process.exitCode = 1;
|
|
259
270
|
if (runnerConfig.forceExit) {
|
|
271
|
+
debug_default("force exiting process");
|
|
260
272
|
process.exit();
|
|
261
273
|
}
|
|
262
274
|
}
|
|
@@ -268,4 +280,3 @@ export {
|
|
|
268
280
|
run,
|
|
269
281
|
test
|
|
270
282
|
};
|
|
271
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
Suite,
|
|
8
8
|
Test,
|
|
9
9
|
TestContext
|
|
10
|
-
} from "../../chunk-
|
|
11
|
-
import "../../chunk-
|
|
10
|
+
} from "../../chunk-CYGUHLQ7.js";
|
|
11
|
+
import "../../chunk-2KG3PWR4.js";
|
|
12
12
|
export {
|
|
13
13
|
BaseReporter,
|
|
14
14
|
Emitter,
|
|
@@ -19,4 +19,3 @@ export {
|
|
|
19
19
|
Test,
|
|
20
20
|
TestContext
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=main.js.map
|
|
@@ -4,7 +4,6 @@ import type { TestEndNode, SuiteEndNode, GroupEndNode, TestStartNode, RunnerSumm
|
|
|
4
4
|
* Base reporter to build custom reporters on top of
|
|
5
5
|
*/
|
|
6
6
|
export declare abstract class BaseReporter {
|
|
7
|
-
#private;
|
|
8
7
|
runner?: Runner;
|
|
9
8
|
/**
|
|
10
9
|
* Path to the file for which the tests are getting executed
|
|
@@ -18,7 +17,24 @@ export declare abstract class BaseReporter {
|
|
|
18
17
|
* Group for which the tests are getting executed
|
|
19
18
|
*/
|
|
20
19
|
currentGroupName?: string;
|
|
20
|
+
protected options: BaseReporterOptions;
|
|
21
21
|
constructor(options?: BaseReporterOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Pretty prints the aggregates
|
|
24
|
+
*/
|
|
25
|
+
protected printAggregates(summary: RunnerSummary): void;
|
|
26
|
+
/**
|
|
27
|
+
* Aggregates errors tree to a flat array
|
|
28
|
+
*/
|
|
29
|
+
protected aggregateErrors(summary: RunnerSummary): {
|
|
30
|
+
phase: string;
|
|
31
|
+
title: string;
|
|
32
|
+
error: Error;
|
|
33
|
+
}[];
|
|
34
|
+
/**
|
|
35
|
+
* Pretty print errors
|
|
36
|
+
*/
|
|
37
|
+
protected printErrors(summary: RunnerSummary): Promise<void>;
|
|
22
38
|
/**
|
|
23
39
|
* Handlers to capture events
|
|
24
40
|
*/
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ErrorsPrinter } from '@japa/errors-printer';
|
|
2
|
+
import { BaseReporter } from '../../modules/core/main.js';
|
|
3
|
+
/**
|
|
4
|
+
* Prints annotations when executing tests within Github actions
|
|
5
|
+
*/
|
|
6
|
+
export declare class GithubReporter extends BaseReporter {
|
|
7
|
+
/**
|
|
8
|
+
* Performs string escape on annotation message as per
|
|
9
|
+
* https://github.com/actions/toolkit/blob/f1d9b4b985e6f0f728b4b766db73498403fd5ca3/packages/core/src/command.ts#L80-L85
|
|
10
|
+
*/
|
|
11
|
+
protected escapeMessage(value: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Performs string escape on annotation properties as per
|
|
14
|
+
* https://github.com/actions/toolkit/blob/f1d9b4b985e6f0f728b4b766db73498403fd5ca3/packages/core/src/command.ts#L80-L85
|
|
15
|
+
*/
|
|
16
|
+
protected escapeProperty(value: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Formats the message as per the Github annotations spec.
|
|
19
|
+
* https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
|
|
20
|
+
*/
|
|
21
|
+
protected formatMessage({ command, properties, message, }: {
|
|
22
|
+
command: string;
|
|
23
|
+
properties: Record<string, string>;
|
|
24
|
+
message: string;
|
|
25
|
+
}): string;
|
|
26
|
+
/**
|
|
27
|
+
* Prints Github annotation for a given error
|
|
28
|
+
*/
|
|
29
|
+
getErrorAnnotation(printer: ErrorsPrinter, error: {
|
|
30
|
+
phase: string;
|
|
31
|
+
title: string;
|
|
32
|
+
error: Error;
|
|
33
|
+
}): Promise<string | undefined>;
|
|
34
|
+
end(): Promise<void>;
|
|
35
|
+
}
|
|
@@ -11,3 +11,7 @@ export declare const dot: (options?: BaseReporterOptions) => NamedReporterContra
|
|
|
11
11
|
* Create an instance of the ndjson reporter
|
|
12
12
|
*/
|
|
13
13
|
export declare const ndjson: (options?: BaseReporterOptions) => NamedReporterContract;
|
|
14
|
+
/**
|
|
15
|
+
* Create an instance of the github reporter
|
|
16
|
+
*/
|
|
17
|
+
export declare const github: (options?: BaseReporterOptions) => NamedReporterContract;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
dot,
|
|
3
|
+
github,
|
|
3
4
|
ndjson,
|
|
4
5
|
spec
|
|
5
|
-
} from "../../chunk-
|
|
6
|
-
import "../../chunk-
|
|
7
|
-
import "../../chunk-
|
|
6
|
+
} from "../../chunk-DPWXK7IV.js";
|
|
7
|
+
import "../../chunk-CYGUHLQ7.js";
|
|
8
|
+
import "../../chunk-2KG3PWR4.js";
|
|
8
9
|
export {
|
|
9
10
|
dot,
|
|
11
|
+
github,
|
|
10
12
|
ndjson,
|
|
11
13
|
spec
|
|
12
14
|
};
|
|
13
|
-
//# sourceMappingURL=main.js.map
|
package/build/src/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__reExport
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-2KG3PWR4.js";
|
|
4
4
|
|
|
5
5
|
// src/types.ts
|
|
6
6
|
var types_exports2 = {};
|
|
@@ -12,4 +12,3 @@ import * as types_star from "@japa/core/types";
|
|
|
12
12
|
|
|
13
13
|
// src/types.ts
|
|
14
14
|
__reExport(types_exports2, types_exports);
|
|
15
|
-
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@japa/runner",
|
|
3
3
|
"description": "A simple yet powerful testing framework for Node.js",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"build",
|
|
12
12
|
"!build/examples",
|
|
13
|
-
"!build/tests"
|
|
14
|
-
"!build/tests_helpers"
|
|
13
|
+
"!build/tests"
|
|
15
14
|
],
|
|
16
15
|
"exports": {
|
|
17
16
|
".": "./build/index.js",
|
|
@@ -39,29 +38,29 @@
|
|
|
39
38
|
"@adonisjs/eslint-config": "^2.0.0-beta.7",
|
|
40
39
|
"@adonisjs/prettier-config": "^1.4.0",
|
|
41
40
|
"@adonisjs/tsconfig": "^1.4.0",
|
|
42
|
-
"@release-it/conventional-changelog": "^
|
|
43
|
-
"@swc/core": "
|
|
41
|
+
"@release-it/conventional-changelog": "^10.0.0",
|
|
42
|
+
"@swc/core": "1.10.7",
|
|
44
43
|
"@types/chai": "^5.0.1",
|
|
45
44
|
"@types/chai-subset": "^1.3.5",
|
|
46
45
|
"@types/find-cache-dir": "^5.0.2",
|
|
47
|
-
"@types/ms": "^
|
|
48
|
-
"@types/node": "^22.
|
|
46
|
+
"@types/ms": "^2.1.0",
|
|
47
|
+
"@types/node": "^22.12.0",
|
|
49
48
|
"c8": "^10.1.3",
|
|
50
49
|
"chai": "^5.1.2",
|
|
51
50
|
"chai-subset": "^1.6.0",
|
|
52
51
|
"cross-env": "^7.0.3",
|
|
53
52
|
"del-cli": "^6.0.0",
|
|
54
|
-
"eslint": "^9.
|
|
55
|
-
"glob": "^11.0.
|
|
53
|
+
"eslint": "^9.19.0",
|
|
54
|
+
"glob": "^11.0.1",
|
|
56
55
|
"prettier": "^3.4.2",
|
|
57
|
-
"release-it": "^
|
|
58
|
-
"ts-node-maintained": "^10.9.
|
|
59
|
-
"tsup": "^8.3.
|
|
60
|
-
"typescript": "^5.7.
|
|
56
|
+
"release-it": "^18.1.2",
|
|
57
|
+
"ts-node-maintained": "^10.9.5",
|
|
58
|
+
"tsup": "^8.3.6",
|
|
59
|
+
"typescript": "^5.7.3"
|
|
61
60
|
},
|
|
62
61
|
"dependencies": {
|
|
63
62
|
"@japa/core": "^10.3.0",
|
|
64
|
-
"@japa/errors-printer": "^4.
|
|
63
|
+
"@japa/errors-printer": "^4.1.2",
|
|
65
64
|
"@poppinss/colors": "^4.1.4",
|
|
66
65
|
"@poppinss/hooks": "^7.2.5",
|
|
67
66
|
"fast-glob": "^3.3.3",
|
|
@@ -103,7 +102,7 @@
|
|
|
103
102
|
"clean": true,
|
|
104
103
|
"format": "esm",
|
|
105
104
|
"dts": false,
|
|
106
|
-
"sourcemap":
|
|
105
|
+
"sourcemap": false,
|
|
107
106
|
"target": "esnext"
|
|
108
107
|
},
|
|
109
108
|
"release-it": {
|
|
@@ -138,6 +137,7 @@
|
|
|
138
137
|
"exclude": [
|
|
139
138
|
"tests/**",
|
|
140
139
|
"tests_helpers/**",
|
|
140
|
+
"build/**",
|
|
141
141
|
"factories/**",
|
|
142
142
|
"modules/core/**",
|
|
143
143
|
"src/reporters/**"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/reporters/dot.ts","../src/reporters/spec.ts","../src/reporters/ndjson.ts","../src/reporters/main.ts"],"sourcesContent":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { colors, icons } from '../helpers.js'\nimport type { TestEndNode } from '../../modules/core/types.js'\nimport { BaseReporter } from '../../modules/core/reporters/base.js'\n\n/**\n * Minimal reporter that prints each test as an icon.\n */\nexport class DotReporter extends BaseReporter {\n /**\n * When a test ended\n */\n protected onTestEnd(payload: TestEndNode) {\n let output = ''\n if (payload.isTodo) {\n output = colors.cyan(icons.info)\n } else if (payload.hasError) {\n output = colors.red(icons.cross)\n } else if (payload.isSkipped) {\n output = colors.yellow(icons.bullet)\n } else if (payload.isFailing) {\n output = colors.magenta(icons.squareSmallFilled)\n } else {\n output = colors.green(icons.tick)\n }\n\n process.stdout.write(`${output}`)\n }\n\n /**\n * When test runner ended\n */\n protected async end() {\n console.log('')\n await this.printSummary(this.runner!.getSummary())\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport ms from 'ms'\nimport { relative } from 'node:path'\n\nimport { colors, icons } from '../helpers.js'\nimport { BaseReporter } from '../../modules/core/main.js'\nimport { GroupStartNode, TestEndNode } from '../../modules/core/types.js'\n\n/**\n * Pretty prints the tests on the console\n */\nexport class SpecReporter extends BaseReporter {\n /**\n * Tracking if the first event we get is for a test without any parent group\n * We need this to decide the display style for tests without groups.\n */\n #isFirstLoneTest = true\n\n /**\n * Returns the icon for the test\n */\n #getTestIcon(payload: TestEndNode) {\n if (payload.isTodo) {\n return colors.cyan(icons.info)\n }\n\n if (payload.hasError) {\n return colors.red(icons.cross)\n }\n\n if (payload.isSkipped) {\n return colors.yellow(icons.bullet)\n }\n\n if (payload.isFailing) {\n return colors.magenta(icons.squareSmallFilled)\n }\n\n return colors.green(icons.tick)\n }\n\n /**\n * Returns the test message\n */\n #getTestMessage(payload: TestEndNode) {\n const message = payload.title.expanded\n\n if (payload.isTodo) {\n return colors.blue(message)\n }\n\n if (payload.hasError) {\n return colors.red(message)\n }\n\n if (payload.isSkipped) {\n return colors.yellow(message)\n }\n\n if (payload.isFailing) {\n return colors.magenta(message)\n }\n\n return colors.grey(message)\n }\n\n /**\n * Returns the subtext message for the test\n */\n #getSubText(payload: TestEndNode): string | undefined {\n if (payload.isSkipped && payload.skipReason) {\n return colors.dim(`${icons.branch} ${colors.italic(payload.skipReason)}`)\n }\n\n if (!payload.isFailing) {\n return\n }\n\n if (payload.hasError) {\n const message =\n payload.errors.find((error) => error.phase === 'test')?.error.message ??\n `Test marked with \".fails()\" must finish with an error`\n\n return colors.dim(`${icons.branch} ${colors.italic(message)}`)\n }\n\n if (payload.failReason) {\n return colors.dim(`${icons.branch} ${colors.italic(payload.failReason)}`)\n }\n\n const testErrorMessage = payload.errors.find((error) => error.phase === 'test')\n if (testErrorMessage && testErrorMessage.error) {\n return colors.dim(`${icons.branch} ${colors.italic(testErrorMessage.error.message)}`)\n }\n }\n\n /**\n * Returns the filename relative from the current working dir\n */\n #getRelativeFilename(fileName: string) {\n return relative(process.cwd(), fileName)\n }\n\n /**\n * Prints the test details\n */\n #printTest(payload: TestEndNode) {\n const icon = this.#getTestIcon(payload)\n const message = this.#getTestMessage(payload)\n const prefix = payload.isPinned ? colors.yellow('[PINNED] ') : ''\n const indentation = this.currentFileName || this.currentGroupName ? ' ' : ''\n const duration = colors.dim(`(${ms(Number(payload.duration.toFixed(2)))})`)\n const retries =\n payload.retryAttempt && payload.retryAttempt > 1\n ? colors.dim(`(x${payload.retryAttempt}) `)\n : ''\n\n let subText = this.#getSubText(payload)\n subText = subText ? `\\n${indentation} ${subText}` : ''\n\n console.log(`${indentation}${icon} ${prefix}${retries}${message} ${duration}${subText}`)\n }\n\n /**\n * Prints the group name\n */\n #printGroup(payload: GroupStartNode) {\n const title =\n this.currentSuiteName !== 'default'\n ? `${this.currentSuiteName} / ${payload.title}`\n : payload.title\n\n const suffix = this.currentFileName\n ? colors.dim(` (${this.#getRelativeFilename(this.currentFileName)})`)\n : ''\n\n console.log(`\\n${title}${suffix}`)\n }\n\n protected onTestStart(): void {\n /**\n * Display the filename when\n *\n * - The filename exists\n * - The test is not under a group\n * - Test is first in a sequence\n */\n if (this.currentFileName && this.#isFirstLoneTest) {\n console.log(`\\n${colors.dim(this.#getRelativeFilename(this.currentFileName))}`)\n }\n this.#isFirstLoneTest = false\n }\n\n protected onTestEnd(payload: TestEndNode): void {\n this.#printTest(payload)\n }\n\n protected onGroupStart(payload: GroupStartNode): void {\n /**\n * When a group starts, we mark the upcoming test as NOT a\n * lone test\n */\n this.#isFirstLoneTest = false\n this.#printGroup(payload)\n }\n\n protected onGroupEnd(): void {\n /**\n * When the group ends we assume that the next test can\n * be out of the group, hence a lone test.\n *\n * If this assumption is false, then the `onGroupStart` method\n * will toggle the boolean\n */\n this.#isFirstLoneTest = true\n }\n\n protected async end() {\n const summary = this.runner!.getSummary()\n await this.printSummary(summary)\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { relative } from 'node:path'\nimport { serializeError } from 'serialize-error'\n\nimport { BaseReporter } from '../../modules/core/main.js'\nimport type {\n TestEndNode,\n SuiteEndNode,\n GroupEndNode,\n SuiteStartNode,\n GroupStartNode,\n} from '../../modules/core/types.js'\n\n/**\n * Prints tests progress as JSON. Each event is emitted\n * independently\n */\nexport class NdJSONReporter extends BaseReporter {\n /**\n * Returns the filename relative from the current working dir\n */\n #getRelativeFilename(fileName: string) {\n return relative(process.cwd(), fileName)\n }\n\n /**\n * Serialize errors to JSON\n */\n #serializeErrors(\n errors: TestEndNode['errors'] | GroupEndNode['errors'] | SuiteEndNode['errors']\n ) {\n return errors.map((error) => ({\n phase: error.phase,\n error: serializeError(error.error),\n }))\n }\n\n protected onTestEnd(payload: TestEndNode): void {\n console.log(\n JSON.stringify({\n event: 'test:end',\n filePath: this.currentFileName,\n relativePath: this.currentFileName\n ? this.#getRelativeFilename(this.currentFileName)\n : undefined,\n title: payload.title,\n duration: payload.duration,\n failReason: payload.failReason,\n isFailing: payload.isFailing,\n skipReason: payload.skipReason,\n isSkipped: payload.isSkipped,\n isTodo: payload.isTodo,\n isPinned: payload.isPinned,\n retryAttempt: payload.retryAttempt,\n retries: payload.retries,\n errors: this.#serializeErrors(payload.errors),\n })\n )\n }\n\n protected onGroupStart(payload: GroupStartNode): void {\n console.log(\n JSON.stringify({\n event: 'group:start',\n title: payload.title,\n })\n )\n }\n\n protected onGroupEnd(payload: GroupEndNode): void {\n JSON.stringify({\n event: 'group:end',\n title: payload.title,\n errors: this.#serializeErrors(payload.errors),\n })\n }\n\n protected onSuiteStart(payload: SuiteStartNode): void {\n console.log(\n JSON.stringify({\n event: 'suite:start',\n ...payload,\n })\n )\n }\n\n protected onSuiteEnd(payload: SuiteEndNode): void {\n console.log(\n JSON.stringify({\n event: 'suite:end',\n name: payload.name,\n hasError: payload.hasError,\n errors: this.#serializeErrors(payload.errors),\n })\n )\n }\n\n protected async end() {\n const summary = this.runner!.getSummary()\n console.log(\n JSON.stringify({\n aggregates: summary.aggregates,\n duration: summary.duration,\n failedTestsTitles: summary.failedTestsTitles,\n hasError: summary.hasError,\n })\n )\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { DotReporter } from './dot.js'\nimport { SpecReporter } from './spec.js'\nimport { NdJSONReporter } from './ndjson.js'\nimport type { BaseReporterOptions, NamedReporterContract } from '../types.js'\n\n/**\n * Create an instance of the spec reporter\n */\nexport const spec: (options?: BaseReporterOptions) => NamedReporterContract = (options) => {\n return {\n name: 'spec',\n handler: (...args) => new SpecReporter(options).boot(...args),\n }\n}\n\n/**\n * Create an instance of the dot reporter\n */\nexport const dot: (options?: BaseReporterOptions) => NamedReporterContract = (options) => {\n return {\n name: 'dot',\n handler: (...args) => new DotReporter(options).boot(...args),\n }\n}\n\n/**\n * Create an instance of the ndjson reporter\n */\nexport const ndjson: (options?: BaseReporterOptions) => NamedReporterContract = (options) => {\n return {\n name: 'ndjson',\n handler: (...args) => new NdJSONReporter(options).boot(...args),\n }\n}\n"],"mappings":";;;;;;;AAgBO,IAAM,cAAN,cAA0B,aAAa;AAAA;AAAA;AAAA;AAAA,EAIlC,UAAU,SAAsB;AACxC,QAAI,SAAS;AACb,QAAI,QAAQ,QAAQ;AAClB,eAAS,OAAO,KAAK,MAAM,IAAI;AAAA,IACjC,WAAW,QAAQ,UAAU;AAC3B,eAAS,OAAO,IAAI,MAAM,KAAK;AAAA,IACjC,WAAW,QAAQ,WAAW;AAC5B,eAAS,OAAO,OAAO,MAAM,MAAM;AAAA,IACrC,WAAW,QAAQ,WAAW;AAC5B,eAAS,OAAO,QAAQ,MAAM,iBAAiB;AAAA,IACjD,OAAO;AACL,eAAS,OAAO,MAAM,MAAM,IAAI;AAAA,IAClC;AAEA,YAAQ,OAAO,MAAM,GAAG,MAAM,EAAE;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,MAAM;AACpB,YAAQ,IAAI,EAAE;AACd,UAAM,KAAK,aAAa,KAAK,OAAQ,WAAW,CAAC;AAAA,EACnD;AACF;;;ACnCA,OAAO,QAAQ;AACf,SAAS,gBAAgB;AASlB,IAAM,eAAN,cAA2B,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAK7C,mBAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,aAAa,SAAsB;AACjC,QAAI,QAAQ,QAAQ;AAClB,aAAO,OAAO,KAAK,MAAM,IAAI;AAAA,IAC/B;AAEA,QAAI,QAAQ,UAAU;AACpB,aAAO,OAAO,IAAI,MAAM,KAAK;AAAA,IAC/B;AAEA,QAAI,QAAQ,WAAW;AACrB,aAAO,OAAO,OAAO,MAAM,MAAM;AAAA,IACnC;AAEA,QAAI,QAAQ,WAAW;AACrB,aAAO,OAAO,QAAQ,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IACN,SAAS,IAAI,SAAS,IAAI,eAAe,OAAO,EAAE,KAAK,GAAG,IAAI;AAAA,EAChE;AACF;","names":["relative","relative"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../modules/core/main.ts","../modules/core/reporters/base.ts","../src/helpers.ts"],"sourcesContent":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport {\n Emitter,\n Refiner,\n Test as BaseTest,\n Suite as BaseSuite,\n Group as BaseGroup,\n Runner as BaseRunner,\n TestContext as BaseTestContext,\n} from '@japa/core'\nimport { inspect } from 'node:util'\nimport { AssertionError } from 'node:assert'\nimport { BaseReporter } from './reporters/base.js'\nimport type { DataSetNode, TestHooksCleanupHandler } from './types.js'\n\ndeclare module '@japa/core' {\n interface Test<Context extends Record<any, any>, TestData extends DataSetNode = undefined> {\n /**\n * Assert the test throws an exception with a certain error message\n * and optionally is an instance of a given Error class.\n */\n throws(message: string | RegExp, errorConstructor?: any): this\n }\n interface TestContext {\n /**\n * Register a cleanup function that runs after the test finishes\n * successfully or with an error.\n */\n cleanup: (cleanupCallback: TestHooksCleanupHandler<TestContext>) => void\n }\n}\n\nexport { Emitter, Refiner, BaseReporter }\n\n/**\n * Test context carries context data for a given test.\n */\nexport class TestContext extends BaseTestContext {\n /**\n * Register a cleanup function that runs after the test finishes\n * successfully or with an error.\n */\n declare cleanup: (cleanupCallback: TestHooksCleanupHandler<TestContext>) => void\n\n constructor(public test: Test) {\n super()\n this.cleanup = (cleanupCallback: TestHooksCleanupHandler<TestContext>) => {\n test.cleanup(cleanupCallback)\n }\n }\n}\n\n/**\n * Test class represents an individual test and exposes API to tweak\n * its runtime behavior.\n */\nexport class Test<TestData extends DataSetNode = undefined> extends BaseTest<\n TestContext,\n TestData\n> {\n /**\n * @inheritdoc\n */\n static executedCallbacks = []\n\n /**\n * @inheritdoc\n */\n static executingCallbacks = []\n\n /**\n * Assert the test throws an exception with a certain error message\n * and optionally is an instance of a given Error class.\n */\n throws(message: string | RegExp, errorConstructor?: any) {\n const errorInPoint = new AssertionError({})\n const existingExecutor = this.options.executor\n if (!existingExecutor) {\n throw new Error('Cannot use \"test.throws\" method without a test callback')\n }\n\n /**\n * Overwriting existing callback\n */\n this.options.executor = async (...args: [any, any, any]) => {\n let raisedException: any\n try {\n await existingExecutor(...args)\n } catch (error) {\n raisedException = error\n }\n\n /**\n * Notify no exception has been raised\n */\n if (!raisedException) {\n errorInPoint.message = 'Expected test to throw an exception'\n throw errorInPoint\n }\n\n /**\n * Constructor mis-match\n */\n if (errorConstructor && !(raisedException instanceof errorConstructor)) {\n errorInPoint.message = `Expected test to throw \"${inspect(errorConstructor)}\"`\n throw errorInPoint\n }\n\n /**\n * Error does not have a message property\n */\n const exceptionMessage: unknown = raisedException.message\n if (!exceptionMessage || typeof exceptionMessage !== 'string') {\n errorInPoint.message = 'Expected test to throw an exception with message property'\n throw errorInPoint\n }\n\n /**\n * Message does not match\n */\n if (typeof message === 'string') {\n if (exceptionMessage !== message) {\n errorInPoint.message = `Expected test to throw \"${message}\". Instead received \"${raisedException.message}\"`\n errorInPoint.actual = raisedException.message\n errorInPoint.expected = message\n throw errorInPoint\n }\n return\n }\n\n if (!message.test(exceptionMessage)) {\n errorInPoint.message = `Expected test error to match \"${message}\" regular expression`\n throw errorInPoint\n }\n }\n\n return this\n }\n}\n\n/**\n * TestGroup is used to bulk configure a collection of tests and\n * define lifecycle hooks for them\n */\nexport class Group extends BaseGroup<TestContext> {}\n\n/**\n * A suite is a collection of tests created around a given\n * testing type. For example: A suite for unit tests, a\n * suite for functional tests and so on.\n */\nexport class Suite extends BaseSuite<TestContext> {}\n\n/**\n * Runner class is used to execute the tests\n */\nexport class Runner extends BaseRunner<TestContext> {}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport ms from 'ms'\nimport { ErrorsPrinter } from '@japa/errors-printer'\n\nimport { Emitter, Runner } from '../main.js'\nimport { colors } from '../../../src/helpers.js'\nimport type {\n TestEndNode,\n SuiteEndNode,\n GroupEndNode,\n TestStartNode,\n RunnerSummary,\n RunnerEndNode,\n GroupStartNode,\n SuiteStartNode,\n RunnerStartNode,\n BaseReporterOptions,\n} from '../types.js'\n\n/**\n * Base reporter to build custom reporters on top of\n */\nexport abstract class BaseReporter {\n #options: BaseReporterOptions\n runner?: Runner\n\n /**\n * Path to the file for which the tests are getting executed\n */\n currentFileName?: string\n\n /**\n * Suite for which the tests are getting executed\n */\n currentSuiteName?: string\n\n /**\n * Group for which the tests are getting executed\n */\n currentGroupName?: string\n\n constructor(options: BaseReporterOptions = {}) {\n this.#options = Object.assign({ stackLinesCount: 2 }, options)\n }\n\n /**\n * Pretty prints the aggregates\n */\n #printAggregates(summary: RunnerSummary) {\n const tests: string[] = []\n\n /**\n * Set value for tests row\n */\n if (summary.aggregates.passed) {\n tests.push(colors.green(`${summary.aggregates.passed} passed`))\n }\n if (summary.aggregates.failed) {\n tests.push(colors.red(`${summary.aggregates.failed} failed`))\n }\n if (summary.aggregates.todo) {\n tests.push(colors.cyan(`${summary.aggregates.todo} todo`))\n }\n if (summary.aggregates.skipped) {\n tests.push(colors.yellow(`${summary.aggregates.skipped} skipped`))\n }\n if (summary.aggregates.regression) {\n tests.push(colors.magenta(`${summary.aggregates.regression} regression`))\n }\n\n this.runner!.summaryBuilder.use(() => {\n return [\n {\n key: colors.dim('Tests'),\n value: `${tests.join(', ')} ${colors.dim(`(${summary.aggregates.total})`)}`,\n },\n {\n key: colors.dim('Time'),\n value: colors.dim(ms(summary.duration)),\n },\n ]\n })\n\n console.log(this.runner!.summaryBuilder.build().join('\\n'))\n }\n\n /**\n * Aggregates errors tree to a flat array\n */\n #aggregateErrors(summary: RunnerSummary) {\n const errorsList: { phase: string; title: string; error: Error }[] = []\n\n summary.failureTree.forEach((suite) => {\n suite.errors.forEach((error) => errorsList.push({ title: suite.name, ...error }))\n\n suite.children.forEach((testOrGroup) => {\n /**\n * Suite child is a test\n */\n if (testOrGroup.type === 'test') {\n testOrGroup.errors.forEach((error) => {\n errorsList.push({ title: `${suite.name} / ${testOrGroup.title}`, ...error })\n })\n return\n }\n\n /**\n * Suite child is a group\n */\n testOrGroup.errors.forEach((error) => {\n errorsList.push({ title: testOrGroup.name, ...error })\n })\n testOrGroup.children.forEach((test) => {\n test.errors.forEach((error) => {\n errorsList.push({ title: `${testOrGroup.name} / ${test.title}`, ...error })\n })\n })\n })\n })\n\n return errorsList\n }\n\n /**\n * Pretty print errors\n */\n async #printErrors(summary: RunnerSummary) {\n if (!summary.failureTree.length) {\n return\n }\n\n const errorPrinter = new ErrorsPrinter({\n framesMaxLimit: this.#options.framesMaxLimit,\n })\n\n errorPrinter.printSectionHeader('ERRORS')\n await errorPrinter.printErrors(this.#aggregateErrors(summary))\n }\n\n /**\n * Handlers to capture events\n */\n protected onTestStart(_: TestStartNode): void {}\n protected onTestEnd(_: TestEndNode) {}\n\n protected onGroupStart(_: GroupStartNode) {}\n protected onGroupEnd(_: GroupEndNode) {}\n\n protected onSuiteStart(_: SuiteStartNode) {}\n protected onSuiteEnd(_: SuiteEndNode) {}\n\n protected async start(_: RunnerStartNode) {}\n protected async end(_: RunnerEndNode) {}\n\n /**\n * Print tests summary\n */\n protected async printSummary(summary: RunnerSummary) {\n await this.#printErrors(summary)\n\n console.log('')\n if (summary.aggregates.total === 0 && !summary.hasError) {\n console.log(colors.bgYellow().black(' NO TESTS EXECUTED '))\n return\n }\n\n if (summary.hasError) {\n console.log(colors.bgRed().black(' FAILED '))\n } else {\n console.log(colors.bgGreen().black(' PASSED '))\n }\n console.log('')\n this.#printAggregates(summary)\n }\n\n /**\n * Invoked by the tests runner when tests are about to start\n */\n boot(runner: Runner, emitter: Emitter) {\n this.runner = runner\n\n emitter.on('test:start', (payload) => {\n this.currentFileName = payload.meta.fileName\n this.onTestStart(payload)\n })\n\n emitter.on('test:end', (payload) => {\n this.onTestEnd(payload)\n })\n\n emitter.on('group:start', (payload) => {\n this.currentGroupName = payload.title\n this.currentFileName = payload.meta.fileName\n this.onGroupStart(payload)\n })\n\n emitter.on('group:end', (payload) => {\n this.currentGroupName = undefined\n this.onGroupEnd(payload)\n })\n\n emitter.on('suite:start', (payload) => {\n this.currentSuiteName = payload.name\n this.onSuiteStart(payload)\n })\n\n emitter.on('suite:end', (payload) => {\n this.currentSuiteName = undefined\n this.onSuiteEnd(payload)\n })\n\n emitter.on('runner:start', async (payload) => {\n await this.start(payload)\n })\n\n emitter.on('runner:end', async (payload) => {\n await this.end(payload)\n })\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport useColors from '@poppinss/colors'\nimport supportsColor from 'supports-color'\nimport { Colors } from '@poppinss/colors/types'\n\nexport const colors: Colors = supportsColor.stdout ? useColors.ansi() : useColors.silent()\n\n/**\n * A collection of platform specific icons\n */\nexport const icons =\n process.platform === 'win32' && !process.env.WT_SESSION\n ? {\n tick: '√',\n cross: '×',\n bullet: '*',\n nodejs: '♦',\n pointer: '>',\n info: 'i',\n warning: '‼',\n branch: ' -',\n squareSmallFilled: '[█]',\n }\n : {\n tick: '✔',\n cross: '✖',\n bullet: '●',\n nodejs: '⬢',\n pointer: '❯',\n info: 'ℹ',\n warning: '⚠',\n branch: '└──',\n squareSmallFilled: '◼',\n }\n"],"mappings":";AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AAAA,EACT,UAAU;AAAA,EACV,eAAe;AAAA,OACV;AACP,SAAS,eAAe;AACxB,SAAS,sBAAsB;;;ACV/B,OAAO,QAAQ;AACf,SAAS,qBAAqB;;;ACD9B,OAAO,eAAe;AACtB,OAAO,mBAAmB;AAGnB,IAAM,SAAiB,cAAc,SAAS,UAAU,KAAK,IAAI,UAAU,OAAO;AAKlF,IAAM,QACX,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KAAK,QAAQ;AACtC,QAAI,CAAC,kBAAkB;AACrB,YAAM,IAAI,MAAM,yDAAyD;AAAA,IAC3E;AAKA,SAAK,QAAQ,WAAW,UAAU,SAA0B;AAC1D,UAAI;AACJ,UAAI;AACF,cAAM,iBAAiB,GAAG,IAAI;AAAA,MAChC,SAAS,OAAO;AACd,0BAAkB;AAAA,MACpB;AAKA,UAAI,CAAC,iBAAiB;AACpB,qBAAa,UAAU;AACvB,cAAM;AAAA,MACR;AAKA,UAAI,oBAAoB,EAAE,2BAA2B,mBAAmB;AACtE,qBAAa,UAAU,2BAA2B,QAAQ,gBAAgB,CAAC;AAC3E,cAAM;AAAA,MACR;AAKA,YAAM,mBAA4B,gBAAgB;AAClD,UAAI,CAAC,oBAAoB,OAAO,qBAAqB,UAAU;AAC7D,qBAAa,UAAU;AACvB,cAAM;AAAA,MACR;AAKA,UAAI,OAAO,YAAY,UAAU;AAC/B,YAAI,qBAAqB,SAAS;AAChC,uBAAa,UAAU,2BAA2B,OAAO,wBAAwB,gBAAgB,OAAO;AACxG,uBAAa,SAAS,gBAAgB;AACtC,uBAAa,WAAW;AACxB,gBAAM;AAAA,QACR;AACA;AAAA,MACF;AAEA,UAAI,CAAC,QAAQ,KAAK,gBAAgB,GAAG;AACnC,qBAAa,UAAU,iCAAiC,OAAO;AAC/D,cAAM;AAAA,MACR;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAMO,IAAM,QAAN,cAAoB,UAAuB;AAAC;AAO5C,IAAM,QAAN,cAAoB,UAAuB;AAAC;AAK5C,IAAM,SAAN,cAAqB,WAAwB;AAAC;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debug.ts","../src/validator.ts","../src/files_manager.ts","../src/planner.ts","../src/hooks.ts","../src/cli_parser.ts","../src/config_manager.ts","../src/create_test.ts"],"sourcesContent":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { debuglog } from 'node:util'\nexport default debuglog('japa:runner')\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { NormalizedConfig } from './types.js'\n\n/**\n * Validator encapsulates the validations to perform before running\n * the tests\n */\nclass Validator {\n /**\n * Ensures the japa is configured. Otherwise raises an exception\n */\n ensureIsConfigured(config: NormalizedConfig | undefined) {\n if (!config) {\n throw new Error(\n `Cannot run tests. Make sure to call \"configure\" method before the \"run\" method`\n )\n }\n }\n\n /**\n * Ensures the japa is in planning phase\n */\n ensureIsInPlanningPhase(phase: 'idle' | 'planning' | 'executing') {\n if (phase !== 'planning') {\n throw new Error(\n `Cannot import japa test file directly. It must be imported by calling the \"japa.run\" method`\n )\n }\n }\n\n /**\n * Ensures the suites filter uses a subset of the user configured suites.\n */\n validateSuitesFilter(config: NormalizedConfig) {\n /**\n * Do not perform any validation if no filters are applied\n * in the first place\n */\n if (!config.filters.suites || !config.filters.suites.length) {\n return\n }\n\n /**\n * Notify user they have applied the suites filter but forgot to define\n * suites\n */\n if (!('suites' in config) || !config.suites.length) {\n throw new Error(`Cannot apply suites filter. You have not configured any test suites`)\n }\n\n const suites = config.suites.map(({ name }) => name)\n\n /**\n * Find unknown suites and report the error\n */\n const unknownSuites = config.filters.suites.filter((suite) => !suites.includes(suite))\n if (unknownSuites.length) {\n throw new Error(`Cannot apply suites filter. \"${unknownSuites[0]}\" suite is not configured`)\n }\n }\n\n /**\n * Ensure there are unique suites\n */\n validateSuitesForUniqueness(config: NormalizedConfig) {\n if (!('suites' in config)) {\n return\n }\n\n const suites: Set<string> = new Set()\n config.suites.forEach(({ name }) => {\n if (suites.has(name)) {\n throw new Error(`Duplicate suite \"${name}\"`)\n }\n suites.add(name)\n })\n\n suites.clear()\n }\n\n /**\n * Ensure the activated reporters are in the list of defined\n * reporters\n */\n validateActivatedReporters(config: NormalizedConfig) {\n const reportersList = config.reporters.list.map(({ name }) => name)\n const unknownReporters = config.reporters.activated.filter(\n (name) => !reportersList.includes(name)\n )\n\n if (unknownReporters.length) {\n throw new Error(\n `Invalid reporter \"${unknownReporters[0]}\". Make sure to register it first inside the \"reporters.list\" array`\n )\n }\n }\n}\n\nexport default new Validator()\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport slash from 'slash'\nimport fastGlob from 'fast-glob'\nimport { pathToFileURL } from 'node:url'\nimport type { TestFiles } from './types.js'\n\n/**\n * The expression to remove file extension and optionally\n * .spec|.test from the test file name\n */\nconst FILE_SUFFIX_EXPRESSION = /(\\.spec|\\.test)?\\.[js|ts|jsx|tsx|mjs|mts|cjs|cts]+$/\n\n/**\n * Files manager exposes the API to collect, filter and import test\n * files based upon the config\n */\nexport class FilesManager {\n /**\n * Returns a collection of files from the user defined\n * glob or the implementation function\n */\n async getFiles(cwd: string, files: TestFiles, excludes: string[]): Promise<URL[]> {\n if (Array.isArray(files) || typeof files === 'string') {\n const testFiles = await fastGlob(files, {\n absolute: true,\n onlyFiles: true,\n cwd: cwd,\n ignore: excludes,\n })\n return testFiles.map((file) => pathToFileURL(file))\n }\n\n return await files()\n }\n\n /**\n * Applies file name filter on a collection of file\n * URLs\n */\n grep(files: URL[], filters: string[]): URL[] {\n return files.filter((file) => {\n const filename = slash(file.pathname)\n const filenameWithoutTestSuffix = filename.replace(FILE_SUFFIX_EXPRESSION, '')\n\n return !!filters.find((filter) => {\n if (filename.endsWith(filter)) {\n return true\n }\n\n const filterSegments = filter.split('/').reverse()\n const fileSegments = filenameWithoutTestSuffix.split('/').reverse()\n\n return filterSegments.every((segment, index) => {\n return fileSegments[index] && (segment === '*' || fileSegments[index].endsWith(segment))\n })\n })\n })\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport validator from './validator.js'\nimport { FilesManager } from './files_manager.js'\nimport type { NamedReporterContract, NormalizedConfig, TestFiles, TestSuite } from './types.js'\n\n/**\n * The tests planner is used to plan the tests by doing all\n * the heavy lifting of executing plugins, registering\n * reporters, filtering tests and so on.\n */\nexport class Planner {\n #config: NormalizedConfig\n #fileManager = new FilesManager()\n\n constructor(config: NormalizedConfig) {\n validator.validateActivatedReporters(config!)\n validator.validateSuitesFilter(config!)\n validator.validateSuitesForUniqueness(config!)\n this.#config = config\n }\n\n /**\n * Returns a list of reporters based upon the activated\n * reporters list.\n */\n #getActivatedReporters(): NamedReporterContract[] {\n return this.#config.reporters.activated.map((activated) => {\n return this.#config.reporters.list.find(({ name }) => activated === name)!\n })\n }\n\n /**\n * A generic method to collect files from the user defined\n * files glob and apply the files filter\n */\n async #collectFiles(files: TestFiles) {\n let filesURLs = await this.#fileManager.getFiles(this.#config.cwd, files, this.#config.exclude)\n if (this.#config.filters.files && this.#config.filters.files.length) {\n filesURLs = this.#fileManager.grep(filesURLs, this.#config.filters.files)\n }\n\n return filesURLs\n }\n\n /**\n * Returns a collection of suites and their associated\n * test files by applying all the filters\n */\n async #getSuites(): Promise<(TestSuite & { filesURLs: URL[] })[]> {\n let suites: (TestSuite & { filesURLs: URL[] })[] = []\n let suitesFilters = this.#config.filters.suites || []\n\n if ('files' in this.#config) {\n suites.push({\n name: 'default',\n files: this.#config.files,\n timeout: this.#config.timeout,\n retries: this.#config.retries,\n filesURLs: await this.#collectFiles(this.#config.files),\n })\n }\n\n if ('suites' in this.#config) {\n for (let suite of this.#config.suites) {\n if (!suitesFilters.length || suitesFilters.includes(suite.name)) {\n suites.push({\n ...suite,\n filesURLs: await this.#collectFiles(suite.files),\n })\n }\n }\n }\n\n return suites\n }\n\n /**\n * Returns a list of filters to the passed to the refiner\n */\n #getRefinerFilters() {\n return Object.keys(this.#config.filters).reduce(\n (result, layer) => {\n if (layer === 'tests' || layer === 'tags' || layer === 'groups') {\n result.push({ layer, filters: this.#config.filters[layer]! })\n }\n return result\n },\n [] as { layer: 'tags' | 'tests' | 'groups'; filters: string[] }[]\n )\n }\n\n /**\n * Creates a plan for running the tests\n */\n async plan() {\n const suites = await this.#getSuites()\n const reporters = this.#getActivatedReporters()\n const refinerFilters = this.#getRefinerFilters()\n return {\n reporters,\n suites,\n refinerFilters,\n config: this.#config,\n }\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport Hooks from '@poppinss/hooks'\nimport type { Runner as HooksRunner } from '@poppinss/hooks/types'\n\nimport { Runner } from '../modules/core/main.js'\nimport type { HooksEvents, SetupHookState, NormalizedConfig, TeardownHookState } from './types.js'\n\n/**\n * Exposes API for working with global hooks\n */\nexport class GlobalHooks {\n #hooks = new Hooks<HooksEvents>()\n #setupRunner: HooksRunner<SetupHookState[0], SetupHookState[1]> | undefined\n #teardownRunner: HooksRunner<TeardownHookState[0], TeardownHookState[1]> | undefined\n\n /**\n * Apply hooks from the config\n */\n apply(config: NormalizedConfig) {\n config.setup.forEach((hook) => this.#hooks.add('setup', hook))\n config.teardown.forEach((hook) => this.#hooks.add('teardown', hook))\n }\n\n /**\n * Perform setup\n */\n async setup(runner: Runner) {\n this.#setupRunner = this.#hooks.runner('setup')\n this.#teardownRunner = this.#hooks.runner('teardown')\n await this.#setupRunner.run(runner)\n }\n\n /**\n * Perform cleanup\n */\n async teardown(error: Error | null, runner: Runner) {\n if (this.#setupRunner) {\n await this.#setupRunner.cleanup(error, runner)\n }\n if (this.#teardownRunner) {\n if (!error) {\n await this.#teardownRunner.run(runner)\n }\n await this.#teardownRunner.cleanup(error, runner)\n }\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n// @ts-ignore-error\nimport getopts from 'getopts'\nimport { colors } from './helpers.js'\nimport type { CLIArgs } from './types.js'\n\n/**\n * Known commandline options. The user can still define additional flags and they\n * will be parsed aswell, but without any normalization\n */\nconst OPTIONS = {\n string: ['tests', 'groups', 'tags', 'files', 'timeout', 'retries', 'reporters', 'bailLayer'],\n boolean: ['help', 'matchAll', 'failed', 'bail'],\n alias: {\n forceExit: 'force-exit',\n matchAll: 'match-all',\n bailLayer: 'bail-layer',\n help: 'h',\n },\n}\n\n/**\n * Help string to display when the `--help flag is used`\n */\nconst GET_HELP = () => `\n${colors.yellow('@japa/runner v2.3.0')}\n\n${colors.green('--tests')} ${colors.dim('Filter tests by the test title')}\n${colors.green('--groups')} ${colors.dim('Filter tests by the group title')}\n${colors.green('--tags')} ${colors.dim('Filter tests by tags')}\n${colors.green('--match-all')} ${colors.dim('Run tests that matches all the supplied tags')}\n${colors.green('--files')} ${colors.dim('Filter tests by the file name')}\n${colors.green('--force-exit')} ${colors.dim('Forcefully exit the process')}\n${colors.green('--timeout')} ${colors.dim('Define default timeout for all tests')}\n${colors.green('--retries')} ${colors.dim('Define default retries for all tests')}\n${colors.green('--reporters')} ${colors.dim('Activate one or more test reporters')}\n${colors.green('--failed')} ${colors.dim('Run tests failed during the last run')}\n${colors.green('--bail')} ${colors.dim('Exit early when a test fails')}\n${colors.green('--bail-layer')} ${colors.dim('Specify at which layer to enable the bail mode. Can be \"group\" or \"suite\"')}\n${colors.green('-h, --help')} ${colors.dim('View help')}\n\n${colors.yellow('Examples:')}\n${colors.dim('node bin/test.js --tags=\"@github\"')}\n${colors.dim('node bin/test.js --tags=\"~@github\"')}\n${colors.dim('node bin/test.js --tags=\"@github,@slow,@integration\" --match-all')}\n${colors.dim('node bin/test.js --force-exit')}\n${colors.dim('node bin/test.js --files=\"user\"')}\n${colors.dim('node bin/test.js --files=\"functional/user\"')}\n${colors.dim('node bin/test.js --files=\"unit/user\"')}\n${colors.dim('node bin/test.js --failed')}\n${colors.dim('node bin/test.js --bail')}\n${colors.dim('node bin/test.js --bail=group')}\n\n${colors.yellow('Notes:')}\n- When groups and tests filters are applied together. We will first filter the\n tests by group title and then apply the tests filter.\n- The timeout defined on test object takes precedence over the ${colors.green('--timeout')} flag.\n- The retries defined on test object takes precedence over the ${colors.green('--retries')} flag.\n- The ${colors.green('--files')} flag checks for the file names ending with the filter substring.\n- The ${colors.green('--tags')} filter runs tests that has one or more of the supplied tags.\n- You can use the ${colors.green('--match-all')} flag to run tests that has all the supplied tags.\n`\n\n/**\n * CLI Parser is used to parse the commandline argument\n */\nexport class CliParser {\n /**\n * Parses command-line arguments\n */\n parse(argv: string[]): CLIArgs {\n return getopts(argv, OPTIONS)\n }\n\n /**\n * Returns the help string\n */\n getHelp() {\n return GET_HELP()\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport debug from './debug.js'\nimport { Refiner } from '../modules/core/main.js'\nimport { dot, ndjson, spec } from './reporters/main.js'\nimport type { CLIArgs, Config, Filters, NormalizedBaseConfig, NormalizedConfig } from './types.js'\n\nexport const NOOP = () => {}\n\n/**\n * Defaults to use for configuration\n */\nconst DEFAULTS = {\n files: [],\n timeout: 2000,\n retries: 0,\n forceExit: false,\n plugins: [],\n reporters: {\n activated: ['spec'],\n list: [spec(), ndjson(), dot()],\n },\n importer: (filePath) => import(filePath.href),\n configureSuite: () => {},\n} satisfies Config\n\n/**\n * Config manager is used to hydrate the configuration by merging\n * the defaults with the user defined config and the command line\n * flags.\n *\n * The command line flags have the upmost priority\n */\nexport class ConfigManager {\n #config: Config\n #cliArgs: CLIArgs\n\n constructor(config: Config, cliArgs: CLIArgs) {\n this.#config = config\n this.#cliArgs = cliArgs\n }\n\n /**\n * Processes a CLI argument and converts it to an\n * array of strings\n */\n #processAsArray(value: string | string[], splitByComma: boolean): string[] {\n return Array.isArray(value)\n ? value\n : splitByComma\n ? value.split(',').map((item: string) => item.trim())\n : [value]\n }\n\n /**\n * Returns a copy of filters based upon the CLI\n * arguments.\n */\n #getCLIFilters(): Filters {\n const filters: Filters = {}\n\n if (this.#cliArgs.tags) {\n filters.tags = this.#processAsArray(this.#cliArgs.tags, true)\n }\n if (this.#cliArgs.tests) {\n filters.tests = this.#processAsArray(this.#cliArgs.tests, false)\n }\n if (this.#cliArgs.files) {\n filters.files = this.#processAsArray(this.#cliArgs.files, true)\n }\n if (this.#cliArgs.groups) {\n filters.groups = this.#processAsArray(this.#cliArgs.groups, false)\n }\n if (this.#cliArgs._ && this.#cliArgs._.length) {\n filters.suites = this.#processAsArray(this.#cliArgs._, true)\n }\n\n return filters\n }\n\n /**\n * Returns the timeout from the CLI args\n */\n #getCLITimeout(): number | undefined {\n if (this.#cliArgs.timeout) {\n const value = Number(this.#cliArgs.timeout)\n if (!Number.isNaN(value)) {\n return value\n }\n }\n }\n\n /**\n * Returns the retries from the CLI args\n */\n #getCLIRetries(): number | undefined {\n if (this.#cliArgs.retries) {\n const value = Number(this.#cliArgs.retries)\n if (!Number.isNaN(value)) {\n return value\n }\n }\n }\n\n /**\n * Returns the forceExit property from the CLI args\n */\n #getCLIForceExit(): boolean | undefined {\n if (this.#cliArgs.forceExit) {\n return true\n }\n }\n\n /**\n * Returns reporters selected using the commandline\n * --reporter flag\n */\n #getCLIReporters(): string[] | undefined {\n if (this.#cliArgs.reporters) {\n return this.#processAsArray(this.#cliArgs.reporters, true)\n }\n }\n\n /**\n * Hydrates the config with user defined options and the\n * command-line flags.\n */\n hydrate(): NormalizedConfig {\n const cliFilters = this.#getCLIFilters()\n const cliRetries = this.#getCLIRetries()\n const cliTimeout = this.#getCLITimeout()\n const cliReporters = this.#getCLIReporters()\n const cliForceExit = this.#getCLIForceExit()\n\n debug('filters applied using CLI flags %O', cliFilters)\n\n const baseConfig: NormalizedBaseConfig = {\n cwd: this.#config.cwd ?? process.cwd(),\n exclude: this.#config.exclude || ['node_modules/**', '.git/**', 'coverage/**'],\n filters: Object.assign({}, this.#config.filters ?? {}, cliFilters),\n importer: this.#config.importer ?? DEFAULTS.importer,\n refiner: this.#config.refiner ?? new Refiner(),\n retries: cliRetries ?? this.#config.retries ?? DEFAULTS.retries,\n timeout: cliTimeout ?? this.#config.timeout ?? DEFAULTS.timeout,\n plugins: this.#config.plugins ?? DEFAULTS.plugins,\n forceExit: cliForceExit ?? this.#config.forceExit ?? DEFAULTS.forceExit,\n reporters: this.#config.reporters\n ? {\n activated: this.#config.reporters.activated,\n list: this.#config.reporters.list || DEFAULTS.reporters.list,\n }\n : DEFAULTS.reporters,\n configureSuite: this.#config.configureSuite ?? DEFAULTS.configureSuite,\n setup: this.#config.setup || [],\n teardown: this.#config.teardown || [],\n }\n\n /**\n * Overwrite activated reporters when defined using CLI\n * flag\n */\n if (cliReporters) {\n baseConfig.reporters.activated = cliReporters\n }\n\n if ('files' in this.#config) {\n return {\n files: this.#config.files,\n ...baseConfig,\n }\n }\n\n return {\n suites: this.#config.suites.map((suite) => {\n return {\n name: suite.name,\n files: suite.files,\n timeout: cliTimeout ?? suite.timeout ?? baseConfig.timeout,\n retries: cliRetries ?? suite.retries ?? baseConfig.retries,\n configure: suite.configure || NOOP,\n }\n }),\n ...baseConfig,\n }\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Emitter, Group, Refiner, Suite, Test, TestContext } from '../modules/core/main.js'\n\n/**\n * Function to create the test context for the test\n */\nconst contextBuilder = (testInstance: Test<any>) => new TestContext(testInstance)\n\n/**\n * Create a new instance of the Test\n */\nexport function createTest(\n title: string,\n emitter: Emitter,\n refiner: Refiner,\n options: {\n group?: Group\n suite?: Suite\n file?: string\n timeout?: number\n retries?: number\n }\n) {\n const testInstance = new Test<undefined>(title, contextBuilder, emitter, refiner, options.group)\n testInstance.options.meta.suite = options.suite\n testInstance.options.meta.group = options.group\n testInstance.options.meta.fileName = options.file\n\n if (options.timeout !== undefined) {\n testInstance.timeout(options.timeout)\n }\n if (options.retries !== undefined) {\n testInstance.retry(options.retries)\n }\n\n /**\n * Register test as a child either with the group or the suite\n */\n if (options.group) {\n options.group.add(testInstance)\n } else if (options.suite) {\n options.suite.add(testInstance)\n }\n\n return testInstance\n}\n\n/**\n * Create a new instance of the Group\n */\nexport function createTestGroup(\n title: string,\n emitter: Emitter,\n refiner: Refiner,\n options: {\n group?: Group\n suite?: Suite\n file?: string\n timeout?: number\n retries?: number\n }\n) {\n if (options.group) {\n throw new Error('Nested groups are not supported by Japa')\n }\n\n const group = new Group(title, emitter, refiner)\n group.options.meta.suite = options.suite\n group.options.meta.fileName = options.file\n\n if (options.suite) {\n options.suite.add(group)\n }\n\n return group\n}\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAS,gBAAgB;AACzB,IAAO,gBAAQ,SAAS,aAAa;;;ACKrC,IAAM,YAAN,MAAgB;AAAA;AAAA;AAAA;AAAA,EAId,mBAAmB,QAAsC;AACvD,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,wBAAwB,OAA0C;AAChE,QAAI,UAAU,YAAY;AACxB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,qBAAqB,QAA0B;AAK7C,QAAI,CAAC,OAAO,QAAQ,UAAU,CAAC,OAAO,QAAQ,OAAO,QAAQ;AAC3D;AAAA,IACF;AAMA,QAAI,EAAE,YAAY,WAAW,CAAC,OAAO,OAAO,QAAQ;AAClD,YAAM,IAAI,MAAM,qEAAqE;AAAA,IACvF;AAEA,UAAM,SAAS,OAAO,OAAO,IAAI,CAAC,EAAE,KAAK,MAAM,IAAI;AAKnD,UAAM,gBAAgB,OAAO,QAAQ,OAAO,OAAO,CAAC,UAAU,CAAC,OAAO,SAAS,KAAK,CAAC;AACrF,QAAI,cAAc,QAAQ;AACxB,YAAM,IAAI,MAAM,gCAAgC,cAAc,CAAC,CAAC,2BAA2B;AAAA,IAC7F;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,4BAA4B,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Content":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\n\nimport { Planner } from '../src/planner.js'\nimport { GlobalHooks } from '../src/hooks.js'\nimport { CliParser } from '../src/cli_parser.js'\nimport { createTest } from '../src/create_test.js'\nimport { ConfigManager } from '../src/config_manager.js'\nimport { Suite, Runner, Emitter, TestContext, Refiner } from '../modules/core/main.js'\nimport type {\n Config,\n CLIArgs,\n TestExecutor,\n RunnerSummary,\n NormalizedConfig,\n} from '../src/types.js'\n\n/**\n * Runner factory exposes the API to run dummy suites, groups and tests.\n * You might want to use the factory for testing reporters and\n * plugins usage\n */\nexport class RunnerFactory {\n #emitter = new Emitter()\n #config?: NormalizedConfig\n #cliArgs?: CLIArgs\n #file = fileURLToPath(import.meta.url)\n #bail: boolean = false\n\n get #refiner() {\n return this.#config!.refiner\n }\n\n /**\n * Registers plugins\n */\n async #registerPlugins(runner: Runner) {\n for (let plugin of this.#config!.plugins) {\n await plugin({\n config: this.#config!,\n runner,\n emitter: this.#emitter,\n cliArgs: this.#cliArgs!,\n })\n }\n }\n\n /**\n * Configure runner\n */\n configure(config: Config, argv?: string[]) {\n this.#cliArgs = new CliParser().parse(argv || [])\n this.#config = new ConfigManager(config, this.#cliArgs).hydrate()\n return this\n }\n\n /**\n * Define a custom emitter instance to use\n */\n useEmitter(emitter: Emitter) {\n this.#emitter = emitter\n return this\n }\n\n /**\n * Run a test using the runner\n */\n async runTest(\n title: string,\n callback: TestExecutor<TestContext, undefined>\n ): Promise<RunnerSummary> {\n return this.runSuites((emitter, refiner, file) => {\n const defaultSuite = new Suite('default', emitter, refiner)\n\n createTest(title, emitter, refiner, {\n suite: defaultSuite,\n file: file,\n }).run(callback)\n\n return [defaultSuite]\n })\n }\n\n /**\n * Enable/disable the bail mode\n */\n bail(toggle: boolean = true) {\n this.#bail = toggle\n return this\n }\n\n /**\n * Run dummy tests. You might use\n */\n async runSuites(\n suites: (emitter: Emitter, refiner: Refiner, file?: string) => Suite[]\n ): Promise<RunnerSummary> {\n const runner = new Runner(this.#emitter)\n runner.bail(this.#bail)\n\n await this.#registerPlugins(runner)\n\n const { config, reporters, refinerFilters } = await new Planner(this.#config!).plan()\n const globalHooks = new GlobalHooks()\n globalHooks.apply(config)\n\n reporters.forEach((reporter) => {\n runner.registerReporter(reporter)\n })\n\n refinerFilters.forEach((filter) => {\n config.refiner.add(filter.layer, filter.filters)\n })\n\n suites(this.#emitter, this.#refiner, this.#file).forEach((suite) => runner.add(suite))\n\n await globalHooks.setup(runner)\n await runner.start()\n await runner.exec()\n await runner.end()\n await globalHooks.teardown(null, runner)\n\n return runner.getSummary()\n }\n}\n","import assert from 'node:assert'\nimport { Suite, Emitter, Refiner } from '../modules/core/main.js'\nimport { createTest, createTestGroup } from '../src/create_test.js'\n\n/**\n * Creates a unit tests suite with bunch of dummy tests\n * reproducing different tests behavior\n */\nfunction createUnitTestsSuite(emitter: Emitter, refiner: Refiner, file?: string) {\n const suite = new Suite('unit', emitter, refiner)\n const group = createTestGroup('Maths#add', emitter, refiner, {\n suite,\n file,\n })\n\n createTest('A top level test inside a suite', emitter, refiner, {\n suite,\n file,\n }).run(() => {})\n\n createTest('add two numbers', emitter, refiner, { group, file }).run(() => {\n assert.equal(2 + 2, 4)\n })\n createTest('add three numbers', emitter, refiner, {\n group,\n file,\n }).run(() => {\n assert.equal(2 + 2 + 2, 6)\n })\n\n createTest('add group of numbers', emitter, refiner, { group, file })\n createTest('use math.js lib', emitter, refiner, { group, file }).skip(\n true,\n 'Library work pending'\n )\n createTest('add multiple numbers', emitter, refiner, {\n file,\n group,\n }).run(() => {\n assert.equal(2 + 2 + 2 + 2, 6)\n })\n createTest('add floating numbers', emitter, refiner, { group, file })\n .run(() => {\n assert.equal(2 + 2.2 + 2.1, 6)\n })\n .fails('Have to add support for floating numbers')\n\n createTest('regression test that is passing', emitter, refiner, { group, file })\n .run(() => {\n assert.equal(2 + 2.2 + 2.1, 2 + 2.2 + 2.1)\n })\n .fails('Have to add support for floating numbers')\n\n createTest('A test with an error that is not an AssertionError', emitter, refiner, {\n group,\n file,\n }).run(() => {\n throw new Error('This is an error')\n })\n\n return suite\n}\n\n/**\n * Creates a unit functional suite with bunch of dummy tests\n * reproducing different tests behavior\n */\nfunction createFunctionalTestsSuite(emitter: Emitter, refiner: Refiner, file?: string) {\n const suite = new Suite('functional', emitter, refiner)\n\n const group = createTestGroup('Users/store', emitter, refiner, {\n suite,\n file: file,\n })\n createTest('Validate user data', emitter, refiner, {\n group,\n file: file,\n }).run(() => {})\n createTest('Disallow duplicate emails', emitter, refiner, {\n group,\n file: file,\n }).run(() => {})\n createTest('Disallow duplicate emails across tenants', emitter, refiner, {\n group,\n file: file,\n }).run(() => {\n const users = ['', '']\n assert.equal(users.length, 1)\n })\n createTest('Normalize email before persisting it', emitter, refiner, {\n group,\n file: file,\n }).skip(true, 'Have to build a normalizer')\n createTest('Send email verification mail', emitter, refiner, {\n group,\n file: file,\n })\n\n createTest('Test that times out', emitter, refiner, {\n group,\n file: file,\n }).run(() => {\n return new Promise((resolve) => {\n setTimeout(resolve, 2100)\n })\n })\n\n const usersListGroup = createTestGroup('Users/list', emitter, refiner, {\n suite,\n file: file,\n })\n usersListGroup.setup(() => {\n throw new Error('Unable to cleanup database')\n })\n createTest('A test that will never run because the group hooks fails', emitter, refiner, {\n group: usersListGroup,\n })\n\n createTest('A top level test inside functional suite', emitter, refiner, {\n suite,\n file: file,\n }).run(() => {})\n\n return suite\n}\n\n/**\n * Returns an array of suites with dummy tests reproducting\n * different test behavior\n */\nexport function createDummyTests(emitter: Emitter, refiner: Refiner, file?: string): Suite[] {\n return [\n createUnitTestsSuite(emitter, refiner, file),\n createFunctionalTestsSuite(emitter, refiner, file),\n ]\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { ReporterContract } from '../src/types.js'\nimport { RunnerFactory } from './runner.js'\n\n/**\n * Create an instance of the runner factory\n */\nexport const runner = () => new RunnerFactory()\nexport { createDummyTests } from './create_dummy_tests.js'\nexport const syncReporter: ReporterContract = {\n name: 'sync',\n handler(r, emitter) {\n emitter.on('runner:end', function () {\n const summary = r.getSummary()\n if (summary.hasError) {\n if (summary.failureTree[0].errors.length) {\n throw summary.failureTree[0].errors[0].error\n }\n if (summary.failureTree[0].children[0].errors.length) {\n throw summary.failureTree[0].children[0].errors[0].error\n }\n }\n })\n },\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AASA,SAAS,qBAAqB;AAqBvB,IAAM,gBAAN,MAAoB;AAAA,EACzB,WAAW,IAAI,QAAQ;AAAA,EACvB;AAAA,EACA;AAAA,EACA,QAAQ,cAAc,YAAY,GAAG;AAAA,EACrC,QAAiB;AAAA,EAEjB,IAAI,WAAW;AACb,WAAO,KAAK,QAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,iBAAiBA,SAAgB;AACrC,aAAS,UAAU,KAAK,QAAS,SAAS;AACxC,YAAM,OAAO;AAAA,QACX,QAAQ,KAAK;AAAA,QACb,QAAAA;AAAA,QACA,SAAS,KAAK;AAAA,QACd,SAAS,KAAK;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU,QAAgB,MAAiB;AACzC,SAAK,WAAW,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAC,CAAC;AAChD,SAAK,UAAU,IAAI,cAAc,QAAQ,KAAK,QAAQ,EAAE,QAAQ;AAChE,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW,SAAkB;AAC3B,SAAK,WAAW;AAChB,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QACJ,OACA,UACwB;AACxB,WAAO,KAAK,UAAU,CAAC,SAAS,SAAS,SAAS;AAChD,YAAM,eAAe,IAAI,MAAM,WAAW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MO,SAAS,iBAAiB,SAAkB,SAAkB,MAAwB;AAC3F,SAAO;AAAA,IACL,qBAAqB,SAAS,SAAS,IAAI;AAAA,IAC3C,2BAA2B,SAAS,SAAS,IAAI;AAAA,EACnD;AACF;;;ACxHO,IAAM,SAAS,MAAM,IAAI,cAAc;AAEvC,IAAM,eAAiC;AAAA,EAC5C,MAAM;AAAA,EACN,QAAQ,GAAG,SAAS;AAClB,YAAQ,GAAG,cAAc,WAAY;AACnC,YAAM,UAAU,EAAE,WAAW;AAC7B,UAAI,QAAQ,UAAU;AACpB,YAAI,QAAQ,YAAY,CAAC,EAAE,OAAO,QAAQ;AACxC,gBAAM,QAAQ,YAAY,CAAC,EAAE,OAAO,CAAC,EAAE;AAAA,QACzC;AACA,YAAI,QAAQ,YAAY,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,QAAQ;AACpD,gBAAM,QAAQ,YAAY,CAAC,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,EAAE;AAAA,QACrD;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["runner"]}
|
package/build/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts","../src/plugins/retry.ts","../src/exceptions_manager.ts"],"sourcesContent":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport { ErrorsPrinter } from '@japa/errors-printer'\nimport type { TestExecutor } from '@japa/core/types'\n\nimport debug from './src/debug.js'\nimport validator from './src/validator.js'\nimport { Planner } from './src/planner.js'\nimport { GlobalHooks } from './src/hooks.js'\nimport { CliParser } from './src/cli_parser.js'\nimport { retryPlugin } from './src/plugins/retry.js'\nimport { ConfigManager } from './src/config_manager.js'\nimport { ExceptionsManager } from './src/exceptions_manager.js'\nimport { createTest, createTestGroup } from './src/create_test.js'\nimport type { CLIArgs, Config, NormalizedConfig } from './src/types.js'\nimport { Emitter, Group, Runner, Suite, Test, TestContext } from './modules/core/main.js'\n\ntype OmitFirstArg<F> = F extends [_: any, ...args: infer R] ? R : never\n\n/**\n * Global emitter instance used by the test\n */\nconst emitter = new Emitter()\n\n/**\n * The current active test\n */\nlet activeTest: Test<any> | undefined\n\n/**\n * Parsed commandline arguments\n */\nlet cliArgs: CLIArgs = {}\n\n/**\n * Hydrated config\n */\nlet runnerConfig: NormalizedConfig | undefined\n\n/**\n * The state refers to the phase where we configure suites and import\n * test files. We stick this metadata to the test instance one can\n * later reference within the test.\n */\nconst executionPlanState: {\n phase: 'idle' | 'planning' | 'executing'\n file?: string\n suite?: Suite\n group?: Group\n timeout?: number\n retries?: number\n} = {\n phase: 'idle',\n}\n\n/**\n * Create a Japa test. Defining a test without the callback\n * will create a todo test.\n */\nexport function test(title: string, callback?: TestExecutor<TestContext, undefined>) {\n validator.ensureIsInPlanningPhase(executionPlanState.phase)\n\n const testInstance = createTest(title, emitter, runnerConfig!.refiner, executionPlanState)\n testInstance.setup((t) => {\n activeTest = t\n return () => {\n activeTest = undefined\n }\n })\n\n if (callback) {\n testInstance.run(callback, new Error())\n }\n\n return testInstance\n}\n\n/**\n * Create a Japa test group\n */\ntest.group = function (title: string, callback: (group: Group) => void) {\n validator.ensureIsInPlanningPhase(executionPlanState.phase)\n\n executionPlanState.group = createTestGroup(\n title,\n emitter,\n runnerConfig!.refiner,\n executionPlanState\n )\n\n /**\n * Enable bail on the group an when bailLayer is set to \"group\"\n */\n if (cliArgs.bail && cliArgs.bailLayer === 'group') {\n executionPlanState.group.bail(true)\n }\n\n callback(executionPlanState.group)\n executionPlanState.group = undefined\n}\n\n/**\n * Create a test bound macro. Within the macro, you can access the\n * currently executed test to read its context values or define\n * cleanup hooks\n */\ntest.macro = function <T extends (test: Test, ...args: any[]) => any>(\n callback: T\n): (...args: OmitFirstArg<Parameters<T>>) => ReturnType<T> {\n return (...args) => {\n if (!activeTest) {\n throw new Error('Cannot invoke macro outside of the test callback')\n }\n return callback(activeTest, ...args)\n }\n}\n\n/**\n * Get the test of currently running test\n */\nexport function getActiveTest() {\n return activeTest\n}\n\n/**\n * Make Japa process command line arguments. Later the parsed output\n * will be used by Japa to compute the configuration\n */\nexport function processCLIArgs(argv: string[]) {\n cliArgs = new CliParser().parse(argv)\n}\n\n/**\n * Configure the tests runner with inline configuration. You must\n * call configure method before the run method.\n *\n * Do note: The CLI flags will overwrite the options provided\n * to the configure method.\n */\nexport function configure(options: Config) {\n runnerConfig = new ConfigManager(options, cliArgs).hydrate()\n}\n\n/**\n * Execute Japa tests. Calling this function will import the test\n * files behind the scenes\n */\nexport async function run() {\n /**\n * Display help when help flag is used\n */\n if (cliArgs.help) {\n console.log(new CliParser().getHelp())\n return\n }\n\n validator.ensureIsConfigured(runnerConfig)\n\n executionPlanState.phase = 'planning'\n const runner = new Runner(emitter)\n\n /**\n * Enable bail on the runner and all the layers after the\n * runner when no specific bailLayer is specified\n */\n if (cliArgs.bail && cliArgs.bailLayer === '') {\n runner.bail(true)\n }\n\n const globalHooks = new GlobalHooks()\n const exceptionsManager = new ExceptionsManager()\n\n try {\n /**\n * Executing the retry plugin as the first thing\n */\n await retryPlugin({ config: runnerConfig!, runner, emitter, cliArgs })\n\n /**\n * Step 1: Executing plugins before creating a plan, so that it can mutate\n * the config\n */\n for (let plugin of runnerConfig!.plugins) {\n debug('executing \"%s\" plugin', plugin.name || 'anonymous')\n await plugin({ runner, emitter, cliArgs, config: runnerConfig! })\n }\n\n /**\n * Step 2: Creating an execution plan. The output is the result of\n * applying all the filters and validations.\n */\n const { config, reporters, suites, refinerFilters } = await new Planner(runnerConfig!).plan()\n\n /**\n * Step 3: Registering reporters and filters with the runner\n */\n reporters.forEach((reporter) => {\n debug('registering \"%s\" reporter', reporter.name)\n runner.registerReporter(reporter)\n })\n refinerFilters.forEach((filter) => {\n debug('apply %s filters \"%O\" ', filter.layer, filter.filters)\n config.refiner.add(filter.layer, filter.filters)\n })\n config.refiner.matchAllTags(cliArgs.matchAll ?? false)\n runner.onSuite(config.configureSuite)\n\n /**\n * Step 4: Running the setup hooks\n */\n debug('executing global hooks')\n globalHooks.apply(config)\n await globalHooks.setup(runner)\n\n /**\n * Step 5: Register suites and import test files\n */\n for (let suite of suites) {\n /**\n * Creating and configuring the suite\n */\n executionPlanState.suite = new Suite(suite.name, emitter, config.refiner)\n executionPlanState.retries = suite.retries\n executionPlanState.timeout = suite.timeout\n if (typeof suite.configure === 'function') {\n suite.configure(executionPlanState.suite)\n }\n\n /**\n * Enable bail on the suite and all the layers after the\n * suite when bailLayer is set to \"suite\"\n */\n if (cliArgs.bail && cliArgs.bailLayer === 'suite') {\n executionPlanState.suite.bail(true)\n }\n runner.add(executionPlanState.suite)\n\n /**\n * Importing suite files\n */\n for (let fileURL of suite.filesURLs) {\n executionPlanState.file = fileURLToPath(fileURL)\n debug('importing test file %s', executionPlanState.file)\n await config.importer(fileURL)\n }\n\n /**\n * Resetting global state\n */\n executionPlanState.suite = undefined\n }\n\n /**\n * Onto execution phase\n */\n executionPlanState.phase = 'executing'\n\n /**\n * Monitor for unhandled erorrs and rejections\n */\n exceptionsManager.monitor()\n\n await runner.start()\n await runner.exec()\n\n await globalHooks.teardown(null, runner)\n await runner.end()\n\n /**\n * Print unhandled errors\n */\n await exceptionsManager.report()\n\n const summary = runner.getSummary()\n if (summary.hasError || exceptionsManager.hasErrors) {\n process.exitCode = 1\n }\n if (config.forceExit) {\n process.exit()\n }\n } catch (error) {\n await globalHooks.teardown(error, runner)\n const printer = new ErrorsPrinter()\n await printer.printError(error)\n\n /**\n * Print unhandled errors in case the code inside\n * the try block never got triggered\n */\n await exceptionsManager.report()\n\n process.exitCode = 1\n if (runnerConfig!.forceExit) {\n process.exit()\n }\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport findCacheDirectory from 'find-cache-dir'\nimport { mkdir, readFile, unlink, writeFile } from 'node:fs/promises'\n\nimport { colors } from '../helpers.js'\nimport type { PluginFn } from '../types.js'\n\n/**\n * Paths to the cache directory and the summary file\n */\nconst CACHE_DIR = findCacheDirectory({ name: '@japa/runner' })\nconst SUMMARY_FILE = CACHE_DIR ? join(CACHE_DIR, 'summary.json') : undefined\n\n/**\n * Returns an object with the title of the tests failed during\n * the last run.\n */\nexport async function getFailedTests(): Promise<{ tests?: string[] }> {\n try {\n const summary = await readFile(SUMMARY_FILE!, 'utf-8')\n return JSON.parse(summary)\n } catch (error) {\n if (error.code === 'ENOENT') {\n return {}\n }\n throw new Error('Unable to read failed tests cache file', { cause: error })\n }\n}\n\n/**\n * Writes failing tests to the cache directory\n */\nexport async function cacheFailedTests(tests: string[]) {\n await mkdir(CACHE_DIR!, { recursive: true })\n await writeFile(SUMMARY_FILE!, JSON.stringify({ tests: tests }))\n}\n\n/**\n * Clears the cache dir\n */\nexport async function clearCache() {\n await unlink(SUMMARY_FILE!)\n}\n\n/**\n * Exposes the API to run failing tests using the \"failed\" CLI flag.\n */\nexport const retryPlugin: PluginFn = async function retry({ config, cliArgs }) {\n if (!SUMMARY_FILE) {\n return\n }\n\n config.teardown.push(async (runner) => {\n const summary = runner.getSummary()\n await cacheFailedTests(summary.failedTestsTitles)\n })\n\n if (cliArgs.failed) {\n try {\n const { tests } = await getFailedTests()\n if (!tests || !tests.length) {\n console.log(colors.bgYellow().black(' No failing tests found. Running all the tests '))\n return\n }\n config.filters.tests = tests\n } catch (error) {\n console.log(colors.bgRed().black(' Unable to read failed tests. Running all the tests '))\n console.log(colors.red(error))\n }\n }\n}\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { ErrorsPrinter } from '@japa/errors-printer'\n\n/**\n * Handles uncaught exceptions and prints them to the\n * console\n */\nexport class ExceptionsManager {\n #exceptionsBuffer: any[] = []\n #rejectionsBuffer: any[] = []\n #state: 'watching' | 'reporting' = 'watching'\n #errorsPrinter = new ErrorsPrinter({ stackLinesCount: 2, framesMaxLimit: 4 })\n\n hasErrors: boolean = false\n\n /**\n * Monitors unhandled exceptions and rejections. The exceptions\n * are stacked in a buffer, so that we do not clutter the\n * tests output and once the tests are over, we will\n * print them to the console.\n *\n * In case the tests are completed, we will print errors as they\n * happen.\n */\n monitor() {\n process.on('uncaughtException', async (error) => {\n this.hasErrors = true\n if (this.#state === 'watching') {\n this.#exceptionsBuffer.push(error)\n } else {\n this.#errorsPrinter.printSectionBorder('[Unhandled Error]')\n await this.#errorsPrinter.printError(error)\n process.exitCode = 1\n }\n })\n\n process.on('unhandledRejection', async (error) => {\n this.hasErrors = true\n if (this.#state === 'watching') {\n this.#rejectionsBuffer.push(error)\n } else {\n this.#errorsPrinter.printSectionBorder('[Unhandled Rejection]')\n await this.#errorsPrinter.printError(error)\n process.exitCode = 1\n }\n })\n }\n\n async report() {\n if (this.#state === 'reporting') {\n return\n }\n\n this.#state = 'reporting'\n\n /**\n * Print exceptions\n */\n if (this.#exceptionsBuffer.length) {\n let exceptionsCount = this.#exceptionsBuffer.length\n let exceptionsIndex = this.#exceptionsBuffer.length\n this.#errorsPrinter.printSectionHeader('Unhandled Errors')\n for (let exception of this.#exceptionsBuffer) {\n await this.#errorsPrinter.printError(exception)\n this.#errorsPrinter.printSectionBorder(`[${++exceptionsIndex}/${exceptionsCount}]`)\n }\n this.#exceptionsBuffer = []\n }\n\n /**\n * Print rejections\n */\n if (this.#rejectionsBuffer.length) {\n let rejectionsCount = this.#exceptionsBuffer.length\n let rejectionsIndex = this.#exceptionsBuffer.length\n this.#errorsPrinter.printSectionBorder('Unhandled Rejections')\n for (let rejection of this.#rejectionsBuffer) {\n await this.#errorsPrinter.printError(rejection)\n this.#errorsPrinter.printSectionBorder(`[${++rejectionsIndex}/${rejectionsCount}]`)\n }\n this.#rejectionsBuffer = []\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AASA,SAAS,qBAAqB;AA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@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/build/src/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts","../../modules/core/types.ts"],"sourcesContent":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HookHandler } from '@poppinss/hooks/types'\n\nimport type { Emitter, Refiner, Runner, Suite } from '../modules/core/main.js'\nimport type { FilteringOptions, NamedReporterContract } from '../modules/core/types.js'\n\nexport * from '../modules/core/types.js'\n\n/**\n * Global setup hook\n */\nexport type SetupHookState = [[runner: Runner], [error: Error | null, runner: Runner]]\nexport type SetupHookHandler = HookHandler<SetupHookState[0], SetupHookState[1]>\n\n/**\n * Global teardown hook\n */\nexport type TeardownHookState = [[runner: Runner], [error: Error | null, runner: Runner]]\nexport type TeardownHookHandler = HookHandler<TeardownHookState[0], TeardownHookState[1]>\n\n/**\n * Global set of available hooks\n */\nexport type HooksEvents = {\n setup: SetupHookState\n teardown: TeardownHookState\n}\n\n/**\n * Parsed command-line arguments\n */\nexport type CLIArgs = {\n _?: string[]\n tags?: string | string[]\n files?: string | string[]\n tests?: string | string[]\n groups?: string | string[]\n timeout?: string\n retries?: string\n reporters?: string | string[]\n forceExit?: boolean\n failed?: boolean\n help?: boolean\n matchAll?: boolean\n bail?: boolean\n bailLayer?: string\n} & Record<string, string | string[] | boolean>\n\n/**\n * Set of filters you can apply to run only specific tests\n */\nexport type Filters = FilteringOptions & {\n files?: string[]\n suites?: string[]\n}\n\n/**\n * Plugin function receives an instance of the runner,\n * emitter, config and the hooks\n */\nexport type PluginFn = (japa: {\n config: NormalizedConfig\n cliArgs: CLIArgs\n runner: Runner\n emitter: Emitter\n}) => void | Promise<void>\n\n/**\n * Base configuration options\n */\nexport type BaseConfig = {\n /**\n * Current working directory. It is required to search for\n * the test files\n */\n cwd?: string\n\n /**\n * The timeout to apply on all the tests, unless overwritten explicitly\n */\n timeout?: number\n\n /**\n * The retries to apply on all the tests, unless overwritten explicitly\n */\n retries?: number\n\n /**\n * Test filters to apply\n */\n filters?: Filters\n\n /**\n * A hook to configure suites. The callback will be called for each\n * suite before it gets executed.\n */\n configureSuite?: (suite: Suite) => void\n\n /**\n * A collection of registered reporters. Reporters are not activated by\n * default. Either you have to activate them using the commandline,\n * or using the `activated` property.\n */\n reporters?: {\n activated: string[]\n list?: NamedReporterContract[]\n }\n\n /**\n * A collection of registered plugins\n */\n plugins?: PluginFn[]\n\n /**\n * A custom implementation to import test files.\n */\n importer?: (filePath: URL) => void | Promise<void>\n\n /**\n * Overwrite tests refiner. Check documentation for refiner\n * usage\n */\n refiner?: Refiner\n\n /**\n * Enable/disable force exiting.\n */\n forceExit?: boolean\n\n /**\n * Global hooks to execute before importing\n * the test files\n */\n setup?: SetupHookHandler[]\n\n /**\n * Global hooks to execute on teardown\n */\n teardown?: TeardownHookHandler[]\n\n /**\n * An array of directories to exclude when searching\n * for test files.\n *\n * For example, if you search for test files inside the entire\n * project, you might want to exclude \"node_modules\"\n */\n exclude?: string[]\n}\n\n/**\n * A collection of test files defined as a glob or a callback\n * function that returns an array of URLs\n */\nexport type TestFiles = string | string[] | (() => URL[] | Promise<URL[]>)\n\n/**\n * A test suite to register tests under a named suite\n */\nexport type TestSuite = {\n /**\n * A unique name for the suite\n */\n name: string\n\n /**\n * Collection of files associated with the suite. Files should be\n * defined as a glob or a callback function that returns an array of URLs\n */\n files: TestFiles\n\n /**\n * A callback functon to configure the suite. The callback is invoked only\n * when the runner is going to run the tests for the given suite.\n */\n configure?: (suite: Suite) => void\n\n /**\n * The timeout to apply on all the tests in this suite, unless overwritten explicitly\n */\n timeout?: number\n\n /**\n * The retries to apply on all the tests in this suite, unless overwritten explicitly\n */\n retries?: number\n}\n\n/**\n * BaseConfig after normalized by the config manager\n */\nexport type NormalizedBaseConfig = Required<Omit<BaseConfig, 'reporters'>> & {\n reporters: {\n activated: string[]\n list: NamedReporterContract[]\n }\n}\n\n/**\n * Configuration options\n */\nexport type Config = BaseConfig &\n (\n | {\n files: TestFiles\n }\n | {\n suites: TestSuite[]\n }\n )\n\n/**\n * Config after normalized by the config manager\n */\nexport type NormalizedConfig = NormalizedBaseConfig &\n (\n | {\n files: TestFiles\n }\n | {\n suites: Required<TestSuite>[]\n }\n )\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * from '@japa/core/types'\n\nexport type BaseReporterOptions = {\n framesMaxLimit?: number\n}\n"],"mappings":";;;;;AAAA,IAAAA,iBAAA;;;ACAA;AASA;AAAA,4BAAc;;;ADKd,WAAAC,gBAAc;","names":["types_exports","types_exports"]}
|