@japa/runner 4.4.1 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,67 +14,6 @@ Japa
14
14
  <br />
15
15
  <hr>
16
16
 
17
- **Featured sponsors**
18
-
19
- <table>
20
-
21
- <tr>
22
- <td>
23
-
24
- <a href="https://route4me.com/?utm_source=adonisjs.com">
25
- <img src="https://raw.githubusercontent.com/thetutlage/static/refs/heads/main/featured_sponsors/logos/route4me.jpg" />
26
- </a>
27
-
28
- </td>
29
-
30
- <td>
31
-
32
- <a href="https://ezycourse.com/?utm_source=adonisjs.com">
33
- <img src="https://raw.githubusercontent.com/thetutlage/static/refs/heads/main/featured_sponsors/logos/ezycourse.jpg" />
34
- </a>
35
-
36
- </td>
37
-
38
- </tr>
39
-
40
- <tr>
41
-
42
- <td>
43
-
44
- <a href="https://meteor.software/g6h?utm_source=adonisjs.com">
45
- <img src="https://raw.githubusercontent.com/thetutlage/static/refs/heads/main/featured_sponsors/logos/galaxy.jpg" />
46
- </a>
47
-
48
- </td>
49
-
50
- <td>
51
-
52
- <a href="https://www.lambdatest.com/?utm_source=adonisjs.com">
53
- <img src="https://raw.githubusercontent.com/thetutlage/static/refs/heads/main/featured_sponsors/logos/lambdatest.jpg" />
54
- </a>
55
-
56
- </td>
57
-
58
- </tr>
59
-
60
- <tr>
61
-
62
- <td>
63
-
64
- <a href="https://relancer.com/?utm_source=adonisjs.com">
65
- <img src="https://raw.githubusercontent.com/thetutlage/static/refs/heads/main/featured_sponsors/logos/relancer.jpg" />
66
- </a>
67
-
68
- </td>
69
-
70
- <td>
71
-
72
- </td>
73
-
74
- </tr>
75
-
76
- </table>
77
-
78
17
  ![](https://raw.githubusercontent.com/thetutlage/static/main/sponsorkit/sponsors.png)
79
18
 
80
19
  [github-actions-image]: https://img.shields.io/github/actions/workflow/status/japa/runner/checks.yml?style=for-the-badge "github-actions"
@@ -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,340 @@
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 "util";
12
+ import { AssertionError } from "assert";
13
+
14
+ // modules/core/reporters/base.ts
15
+ import ms from "ms";
16
+ import { ErrorsPrinter } from "@japa/errors-printer";
17
+
18
+ // src/helpers.ts
19
+ import string from "@poppinss/string";
20
+ import useColors from "@poppinss/colors";
21
+ import { fileURLToPath } from "url";
22
+ import supportsColor from "supports-color";
23
+ import { parse } from "error-stack-parser-es";
24
+ var colors = supportsColor.stdout ? useColors.ansi() : useColors.silent();
25
+ var icons = process.platform === "win32" && !process.env.WT_SESSION ? {
26
+ tick: "\u221A",
27
+ cross: "\xD7",
28
+ bullet: "*",
29
+ nodejs: "\u2666",
30
+ pointer: ">",
31
+ info: "i",
32
+ warning: "\u203C",
33
+ branch: " -",
34
+ squareSmallFilled: "[\u2588]"
35
+ } : {
36
+ tick: "\u2714",
37
+ cross: "\u2716",
38
+ bullet: "\u25CF",
39
+ nodejs: "\u2B22",
40
+ pointer: "\u276F",
41
+ info: "\u2139",
42
+ warning: "\u26A0",
43
+ branch: "\u2514\u2500\u2500",
44
+ squareSmallFilled: "\u25FC"
45
+ };
46
+ function formatPinnedTest(test) {
47
+ let fileName = "";
48
+ let line = 0;
49
+ let column = 0;
50
+ try {
51
+ test.options.meta.abort("Finding pinned test location");
52
+ } catch (error) {
53
+ const frame = parse(error).find(
54
+ (f) => f.fileName && f.lineNumber !== void 0 && f.columnNumber !== void 0 && !f.fileName.includes("node:") && !f.fileName.includes("ext:") && !f.fileName.includes("node_modules/")
55
+ );
56
+ if (frame) {
57
+ fileName = frame.fileName.startsWith("file:") ? string.toUnixSlash(fileURLToPath(frame.fileName)) : string.toUnixSlash(frame.fileName);
58
+ line = frame.lineNumber;
59
+ column = frame.columnNumber;
60
+ }
61
+ }
62
+ return `${colors.yellow(` \u2043 ${test.title}`)}
63
+ ${colors.dim(` ${fileName}:${line}:${column}`)}`;
64
+ }
65
+ function printPinnedTests(runner) {
66
+ let pinnedTests = [];
67
+ runner.suites.forEach((suite) => {
68
+ suite.stack.forEach((testOrGroup) => {
69
+ if (testOrGroup instanceof Group) {
70
+ testOrGroup.tests.forEach(($test) => {
71
+ if ($test.isPinned) {
72
+ pinnedTests.push(formatPinnedTest($test));
73
+ }
74
+ });
75
+ } else if (testOrGroup.isPinned) {
76
+ pinnedTests.push(formatPinnedTest(testOrGroup));
77
+ }
78
+ });
79
+ });
80
+ if (pinnedTests.length) {
81
+ console.log(colors.bgYellow().black(` ${pinnedTests.length} pinned test(s) found `));
82
+ pinnedTests.forEach((row) => console.log(row));
83
+ } else {
84
+ console.log(colors.bgYellow().black(` No pinned tests found `));
85
+ }
86
+ }
87
+
88
+ // modules/core/reporters/base.ts
89
+ var BaseReporter = class {
90
+ runner;
91
+ /**
92
+ * Path to the file for which the tests are getting executed
93
+ */
94
+ currentFileName;
95
+ /**
96
+ * Suite for which the tests are getting executed
97
+ */
98
+ currentSuiteName;
99
+ /**
100
+ * Group for which the tests are getting executed
101
+ */
102
+ currentGroupName;
103
+ options;
104
+ constructor(options = {}) {
105
+ this.options = Object.assign({ stackLinesCount: 2 }, options);
106
+ }
107
+ /**
108
+ * Pretty prints the aggregates
109
+ */
110
+ printAggregates(summary) {
111
+ const tests = [];
112
+ if (summary.aggregates.passed) {
113
+ tests.push(colors.green(`${summary.aggregates.passed} passed`));
114
+ }
115
+ if (summary.aggregates.failed) {
116
+ tests.push(colors.red(`${summary.aggregates.failed} failed`));
117
+ }
118
+ if (summary.aggregates.todo) {
119
+ tests.push(colors.cyan(`${summary.aggregates.todo} todo`));
120
+ }
121
+ if (summary.aggregates.skipped) {
122
+ tests.push(colors.yellow(`${summary.aggregates.skipped} skipped`));
123
+ }
124
+ if (summary.aggregates.regression) {
125
+ tests.push(colors.magenta(`${summary.aggregates.regression} regression`));
126
+ }
127
+ this.runner.summaryBuilder.use(() => {
128
+ return [
129
+ {
130
+ key: colors.dim("Tests"),
131
+ value: `${tests.join(", ")} ${colors.dim(`(${summary.aggregates.total})`)}`
132
+ },
133
+ {
134
+ key: colors.dim("Time"),
135
+ value: colors.dim(ms(summary.duration))
136
+ }
137
+ ];
138
+ });
139
+ console.log(this.runner.summaryBuilder.build().join("\n"));
140
+ }
141
+ /**
142
+ * Aggregates errors tree to a flat array
143
+ */
144
+ aggregateErrors(summary) {
145
+ const errorsList = [];
146
+ summary.failureTree.forEach((suite) => {
147
+ suite.errors.forEach((error) => errorsList.push({ title: suite.name, ...error }));
148
+ suite.children.forEach((testOrGroup) => {
149
+ if (testOrGroup.type === "test") {
150
+ testOrGroup.errors.forEach((error) => {
151
+ errorsList.push({ title: `${suite.name} / ${testOrGroup.title}`, ...error });
152
+ });
153
+ return;
154
+ }
155
+ testOrGroup.errors.forEach((error) => {
156
+ errorsList.push({ title: testOrGroup.name, ...error });
157
+ });
158
+ testOrGroup.children.forEach((test) => {
159
+ test.errors.forEach((error) => {
160
+ errorsList.push({ title: `${testOrGroup.name} / ${test.title}`, ...error });
161
+ });
162
+ });
163
+ });
164
+ });
165
+ return errorsList;
166
+ }
167
+ /**
168
+ * Pretty print errors
169
+ */
170
+ async printErrors(summary) {
171
+ if (!summary.failureTree.length) {
172
+ return;
173
+ }
174
+ const errorPrinter = new ErrorsPrinter({
175
+ framesMaxLimit: this.options.framesMaxLimit
176
+ });
177
+ errorPrinter.printSectionHeader("ERRORS");
178
+ await errorPrinter.printErrors(this.aggregateErrors(summary));
179
+ }
180
+ /**
181
+ * Handlers to capture events
182
+ */
183
+ onTestStart(_) {
184
+ }
185
+ onTestEnd(_) {
186
+ }
187
+ onGroupStart(_) {
188
+ }
189
+ onGroupEnd(_) {
190
+ }
191
+ onSuiteStart(_) {
192
+ }
193
+ onSuiteEnd(_) {
194
+ }
195
+ async start(_) {
196
+ }
197
+ async end(_) {
198
+ }
199
+ /**
200
+ * Print tests summary
201
+ */
202
+ async printSummary(summary) {
203
+ await this.printErrors(summary);
204
+ console.log("");
205
+ if (summary.aggregates.total === 0 && !summary.hasError) {
206
+ console.log(colors.bgYellow().black(" NO TESTS EXECUTED "));
207
+ return;
208
+ }
209
+ if (summary.hasError) {
210
+ console.log(colors.bgRed().black(" FAILED "));
211
+ } else {
212
+ console.log(colors.bgGreen().black(" PASSED "));
213
+ }
214
+ console.log("");
215
+ this.printAggregates(summary);
216
+ }
217
+ /**
218
+ * Invoked by the tests runner when tests are about to start
219
+ */
220
+ boot(runner, emitter) {
221
+ this.runner = runner;
222
+ emitter.on("test:start", (payload) => {
223
+ this.currentFileName = payload.meta.fileName;
224
+ this.onTestStart(payload);
225
+ });
226
+ emitter.on("test:end", (payload) => {
227
+ this.onTestEnd(payload);
228
+ });
229
+ emitter.on("group:start", (payload) => {
230
+ this.currentGroupName = payload.title;
231
+ this.currentFileName = payload.meta.fileName;
232
+ this.onGroupStart(payload);
233
+ });
234
+ emitter.on("group:end", (payload) => {
235
+ this.currentGroupName = void 0;
236
+ this.onGroupEnd(payload);
237
+ });
238
+ emitter.on("suite:start", (payload) => {
239
+ this.currentSuiteName = payload.name;
240
+ this.onSuiteStart(payload);
241
+ });
242
+ emitter.on("suite:end", (payload) => {
243
+ this.currentSuiteName = void 0;
244
+ this.onSuiteEnd(payload);
245
+ });
246
+ emitter.on("runner:start", async (payload) => {
247
+ await this.start(payload);
248
+ });
249
+ emitter.on("runner:end", async (payload) => {
250
+ await this.end(payload);
251
+ });
252
+ }
253
+ };
254
+
255
+ // modules/core/main.ts
256
+ var TestContext = class extends BaseTestContext {
257
+ constructor(test) {
258
+ super();
259
+ this.test = test;
260
+ this.cleanup = (cleanupCallback) => {
261
+ test.cleanup(cleanupCallback);
262
+ };
263
+ }
264
+ };
265
+ var Test2 = class extends BaseTest {
266
+ /**
267
+ * @inheritdoc
268
+ */
269
+ static executedCallbacks = [];
270
+ /**
271
+ * @inheritdoc
272
+ */
273
+ static executingCallbacks = [];
274
+ /**
275
+ * Assert the test throws an exception with a certain error message
276
+ * and optionally is an instance of a given Error class.
277
+ */
278
+ throws(message, errorConstructor) {
279
+ const errorInPoint = new AssertionError({});
280
+ const existingExecutor = this.options.executor;
281
+ if (!existingExecutor) {
282
+ throw new Error('Cannot use "test.throws" method without a test callback');
283
+ }
284
+ this.options.executor = async (...args) => {
285
+ let raisedException;
286
+ try {
287
+ await existingExecutor(...args);
288
+ } catch (error) {
289
+ raisedException = error;
290
+ }
291
+ if (!raisedException) {
292
+ errorInPoint.message = "Expected test to throw an exception";
293
+ throw errorInPoint;
294
+ }
295
+ if (errorConstructor && !(raisedException instanceof errorConstructor)) {
296
+ errorInPoint.message = `Expected test to throw "${inspect(errorConstructor)}"`;
297
+ throw errorInPoint;
298
+ }
299
+ const exceptionMessage = raisedException.message;
300
+ if (!exceptionMessage || typeof exceptionMessage !== "string") {
301
+ errorInPoint.message = "Expected test to throw an exception with message property";
302
+ throw errorInPoint;
303
+ }
304
+ if (typeof message === "string") {
305
+ if (exceptionMessage !== message) {
306
+ errorInPoint.message = `Expected test to throw "${message}". Instead received "${raisedException.message}"`;
307
+ errorInPoint.actual = raisedException.message;
308
+ errorInPoint.expected = message;
309
+ throw errorInPoint;
310
+ }
311
+ return;
312
+ }
313
+ if (!message.test(exceptionMessage)) {
314
+ errorInPoint.message = `Expected test error to match "${message}" regular expression`;
315
+ throw errorInPoint;
316
+ }
317
+ };
318
+ return this;
319
+ }
320
+ };
321
+ var Group = class extends BaseGroup {
322
+ };
323
+ var Suite = class extends BaseSuite {
324
+ };
325
+ var Runner2 = class extends BaseRunner {
326
+ };
327
+
328
+ export {
329
+ BaseReporter,
330
+ Emitter,
331
+ Refiner,
332
+ TestContext,
333
+ Test2 as Test,
334
+ Group,
335
+ Suite,
336
+ Runner2 as Runner,
337
+ colors,
338
+ icons,
339
+ printPinnedTests
340
+ };