@japa/runner 1.0.0 → 1.1.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/index.d.ts +15 -7
- package/build/index.js +53 -36
- package/package.json +2 -1
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TestExecutor } from '@japa/core';
|
|
2
2
|
import { Test, TestContext, Group } from './src/Core';
|
|
3
|
-
import { ConfigureOptions
|
|
4
|
-
export { Test, TestContext, Group }
|
|
3
|
+
import { ConfigureOptions } from './src/Contracts';
|
|
4
|
+
export { Test, TestContext, Group };
|
|
5
5
|
/**
|
|
6
6
|
* Configure the tests runner
|
|
7
7
|
*/
|
|
@@ -9,16 +9,24 @@ export declare function configure(options: ConfigureOptions): void;
|
|
|
9
9
|
/**
|
|
10
10
|
* Add a new test
|
|
11
11
|
*/
|
|
12
|
-
declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<TestContext, undefined>;
|
|
13
|
-
declare namespace test {
|
|
12
|
+
export declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<TestContext, undefined>;
|
|
13
|
+
export declare namespace test {
|
|
14
14
|
var group: (title: string, callback: (group: Group<TestContext>) => void) => void;
|
|
15
15
|
}
|
|
16
|
-
export default test;
|
|
17
16
|
/**
|
|
18
17
|
* Run japa tests
|
|
19
18
|
*/
|
|
20
19
|
export declare function run(): Promise<void>;
|
|
21
20
|
/**
|
|
22
|
-
* Process CLI arguments into
|
|
21
|
+
* Process CLI arguments into configuration options. The following
|
|
22
|
+
* command line arguments are processed.
|
|
23
|
+
*
|
|
24
|
+
* * --tests=Specify test titles
|
|
25
|
+
* * --tags=Specify test tags
|
|
26
|
+
* * --groups=Specify group titles
|
|
27
|
+
* * --ignore-tags=Specify negated tags
|
|
28
|
+
* * --files=Specify files to match and run
|
|
29
|
+
* * --force-exit=Enable/disable force exit
|
|
30
|
+
* * --timeout=Define timeout for all the tests
|
|
23
31
|
*/
|
|
24
|
-
export declare function processCliArgs(argv: string[]):
|
|
32
|
+
export declare function processCliArgs(argv: string[]): Partial<ConfigureOptions>;
|
package/build/index.js
CHANGED
|
@@ -11,18 +11,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.processCliArgs = exports.run = exports.configure = exports.Group = exports.TestContext = exports.Test = void 0;
|
|
14
|
+
exports.processCliArgs = exports.run = exports.test = exports.configure = exports.Group = exports.TestContext = exports.Test = void 0;
|
|
15
15
|
const getopts_1 = __importDefault(require("getopts"));
|
|
16
16
|
const path_1 = require("path");
|
|
17
17
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
18
18
|
const inclusion_1 = __importDefault(require("inclusion"));
|
|
19
19
|
const hooks_1 = require("@poppinss/hooks");
|
|
20
|
+
const errors_printer_1 = require("@japa/errors-printer");
|
|
20
21
|
const core_1 = require("@japa/core");
|
|
21
22
|
const Core_1 = require("./src/Core");
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
Object.defineProperty(exports, "
|
|
25
|
-
Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return Core_2.Group; } });
|
|
23
|
+
Object.defineProperty(exports, "Test", { enumerable: true, get: function () { return Core_1.Test; } });
|
|
24
|
+
Object.defineProperty(exports, "TestContext", { enumerable: true, get: function () { return Core_1.TestContext; } });
|
|
25
|
+
Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return Core_1.Group; } });
|
|
26
26
|
/**
|
|
27
27
|
* Filtering layers allowed by the refiner
|
|
28
28
|
*/
|
|
@@ -80,10 +80,13 @@ async function endTests(runner) {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
-
* Process command line
|
|
83
|
+
* Process command line argument into a string value
|
|
84
84
|
*/
|
|
85
|
-
function
|
|
86
|
-
|
|
85
|
+
function processAsString(argv, flagName, onMatch) {
|
|
86
|
+
const flag = argv[flagName];
|
|
87
|
+
if (flag) {
|
|
88
|
+
onMatch((Array.isArray(flag) ? flag : flag.split(',')).map((tag) => tag.trim()));
|
|
89
|
+
}
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* Find if the file path matches the files filter array.
|
|
@@ -149,7 +152,7 @@ function test(title, callback) {
|
|
|
149
152
|
}
|
|
150
153
|
return testInstance;
|
|
151
154
|
}
|
|
152
|
-
exports.
|
|
155
|
+
exports.test = test;
|
|
153
156
|
/**
|
|
154
157
|
* Define test group
|
|
155
158
|
*/
|
|
@@ -198,10 +201,7 @@ async function run() {
|
|
|
198
201
|
*/
|
|
199
202
|
runnerOptions.reporters.forEach((reporter) => runner.registerReporter(reporter));
|
|
200
203
|
/**
|
|
201
|
-
* Step 3:
|
|
202
|
-
*
|
|
203
|
-
* We run hooks before importing test files. It allows hooks
|
|
204
|
-
* to setup the app environment for the test files
|
|
204
|
+
* Step 3: Configure runner hooks.
|
|
205
205
|
*/
|
|
206
206
|
runnerOptions.setup.forEach((hook) => hooks.add('setup', hook));
|
|
207
207
|
runnerOptions.teardown.forEach((hook) => hooks.add('teardown', hook));
|
|
@@ -209,6 +209,10 @@ async function run() {
|
|
|
209
209
|
teardownRunner = hooks.runner('teardown');
|
|
210
210
|
/**
|
|
211
211
|
* Step 3.1: Run setup hooks
|
|
212
|
+
*
|
|
213
|
+
* We run the setup hooks before importing test files. It
|
|
214
|
+
* allows hooks to setup the app environment for the
|
|
215
|
+
* test files.
|
|
212
216
|
*/
|
|
213
217
|
await setupRunner.run(runner);
|
|
214
218
|
/**
|
|
@@ -255,9 +259,11 @@ async function run() {
|
|
|
255
259
|
*/
|
|
256
260
|
await runner.exec();
|
|
257
261
|
/**
|
|
258
|
-
* Step 7.3: Run teardown hooks
|
|
262
|
+
* Step 7.3: Run cleanup and teardown hooks
|
|
259
263
|
*/
|
|
264
|
+
await setupRunner.cleanup(runner);
|
|
260
265
|
await teardownRunner.run(runner);
|
|
266
|
+
await teardownRunner.cleanup(runner);
|
|
261
267
|
/**
|
|
262
268
|
* Step 7.4: End or wait for process to exit
|
|
263
269
|
*/
|
|
@@ -270,8 +276,6 @@ async function run() {
|
|
|
270
276
|
process.exitCode = 1;
|
|
271
277
|
}
|
|
272
278
|
runnerOptions.forceExit && process.exit();
|
|
273
|
-
await setupRunner.cleanup(runner);
|
|
274
|
-
await teardownRunner.cleanup(runner);
|
|
275
279
|
}
|
|
276
280
|
catch (error) {
|
|
277
281
|
if (setupRunner && setupRunner.isCleanupPending) {
|
|
@@ -280,40 +284,53 @@ async function run() {
|
|
|
280
284
|
if (teardownRunner && teardownRunner.isCleanupPending) {
|
|
281
285
|
await teardownRunner.cleanup(error, runner);
|
|
282
286
|
}
|
|
287
|
+
const printer = new errors_printer_1.ErrorsPrinter();
|
|
288
|
+
await printer.printError(error);
|
|
283
289
|
process.exitCode = 1;
|
|
284
290
|
runnerOptions.forceExit && process.exit();
|
|
285
291
|
}
|
|
286
292
|
}
|
|
287
293
|
exports.run = run;
|
|
288
294
|
/**
|
|
289
|
-
* Process CLI arguments into
|
|
295
|
+
* Process CLI arguments into configuration options. The following
|
|
296
|
+
* command line arguments are processed.
|
|
297
|
+
*
|
|
298
|
+
* * --tests=Specify test titles
|
|
299
|
+
* * --tags=Specify test tags
|
|
300
|
+
* * --groups=Specify group titles
|
|
301
|
+
* * --ignore-tags=Specify negated tags
|
|
302
|
+
* * --files=Specify files to match and run
|
|
303
|
+
* * --force-exit=Enable/disable force exit
|
|
304
|
+
* * --timeout=Define timeout for all the tests
|
|
290
305
|
*/
|
|
291
306
|
function processCliArgs(argv) {
|
|
292
307
|
const parsed = (0, getopts_1.default)(argv, {
|
|
293
|
-
string: ['tests', 'tags', 'groups', 'ignoreTags', 'files'],
|
|
308
|
+
string: ['tests', 'tags', 'groups', 'ignoreTags', 'files', 'timeout'],
|
|
309
|
+
boolean: ['forceExit'],
|
|
294
310
|
alias: {
|
|
295
311
|
ignoreTags: 'ignore-tags',
|
|
312
|
+
forceExit: 'force-exit',
|
|
296
313
|
},
|
|
297
314
|
});
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (parsed.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
315
|
+
const config = {
|
|
316
|
+
filters: {},
|
|
317
|
+
};
|
|
318
|
+
processAsString(parsed, 'tags', (tags) => (config.filters.tags = tags));
|
|
319
|
+
processAsString(parsed, 'ignoreTags', (tags) => {
|
|
320
|
+
tags.forEach((tag) => config.filters.tags.push(`!${tag}`));
|
|
321
|
+
});
|
|
322
|
+
processAsString(parsed, 'groups', (groups) => (config.filters.groups = groups));
|
|
323
|
+
processAsString(parsed, 'tests', (tests) => (config.filters.tests = tests));
|
|
324
|
+
processAsString(parsed, 'files', (files) => (config.filters.files = files));
|
|
325
|
+
if (parsed.timeout) {
|
|
326
|
+
const value = Number(parsed.timeout);
|
|
327
|
+
if (!isNaN(value)) {
|
|
328
|
+
config.timeout = value;
|
|
329
|
+
}
|
|
313
330
|
}
|
|
314
|
-
if (parsed.
|
|
315
|
-
|
|
331
|
+
if (parsed.forceExit) {
|
|
332
|
+
config.forceExit = true;
|
|
316
333
|
}
|
|
317
|
-
return
|
|
334
|
+
return config;
|
|
318
335
|
}
|
|
319
336
|
exports.processCliArgs = processCliArgs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@japa/runner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Runner for Japa testing framework",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -106,6 +106,7 @@
|
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
108
|
"@japa/core": "^5.0.17-0",
|
|
109
|
+
"@japa/errors-printer": "^1.3.1",
|
|
109
110
|
"@poppinss/hooks": "^6.0.1-0",
|
|
110
111
|
"fast-glob": "^3.2.11",
|
|
111
112
|
"getopts": "^2.3.0",
|