@japa/runner 1.2.0 → 2.0.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 +6 -6
- package/build/index.js +36 -7
- package/build/src/Contracts/index.d.ts +16 -11
- package/build/src/Core/index.d.ts +12 -4
- package/build/src/Core/index.js +14 -3
- package/package.json +4 -4
package/build/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { TestExecutor, ReporterContract } from '@japa/core';
|
|
2
2
|
import { Test, TestContext, Group } from './src/Core';
|
|
3
|
-
import {
|
|
4
|
-
export { Test,
|
|
3
|
+
import { Config, PluginFn, RunnerHooksHandler, RunnerHooksCleanupHandler } from './src/Contracts';
|
|
4
|
+
export { Test, Config, Group, PluginFn, TestContext, ReporterContract, RunnerHooksHandler, RunnerHooksCleanupHandler, };
|
|
5
5
|
/**
|
|
6
6
|
* Configure the tests runner
|
|
7
7
|
*/
|
|
8
|
-
export declare function configure(options:
|
|
8
|
+
export declare function configure(options: Config): void;
|
|
9
9
|
/**
|
|
10
10
|
* Add a new test
|
|
11
11
|
*/
|
|
12
|
-
export declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<
|
|
12
|
+
export declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<undefined>;
|
|
13
13
|
export declare namespace test {
|
|
14
|
-
var group: (title: string, callback: (group: Group
|
|
14
|
+
var group: (title: string, callback: (group: Group) => void) => void;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Run japa tests
|
|
@@ -29,4 +29,4 @@ export declare function run(): Promise<void>;
|
|
|
29
29
|
* * --force-exit=Enable/disable force exit
|
|
30
30
|
* * --timeout=Define timeout for all the tests
|
|
31
31
|
*/
|
|
32
|
-
export declare function processCliArgs(argv: string[]): Partial<
|
|
32
|
+
export declare function processCliArgs(argv: string[]): Partial<Config>;
|
package/build/index.js
CHANGED
|
@@ -11,7 +11,7 @@ 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.test = exports.configure = exports.
|
|
14
|
+
exports.processCliArgs = exports.run = exports.test = exports.configure = exports.TestContext = exports.Group = 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"));
|
|
@@ -48,7 +48,7 @@ const emitter = new core_1.Emitter();
|
|
|
48
48
|
/**
|
|
49
49
|
* Active suite for tests
|
|
50
50
|
*/
|
|
51
|
-
let activeSuite = new
|
|
51
|
+
let activeSuite = new Core_1.Suite('default', emitter);
|
|
52
52
|
/**
|
|
53
53
|
* Currently active group
|
|
54
54
|
*/
|
|
@@ -65,6 +65,23 @@ function ensureIsConfigured(message) {
|
|
|
65
65
|
throw new Error(message);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Validate suites filter to ensure a wrong suite is not
|
|
70
|
+
* mentioned
|
|
71
|
+
*/
|
|
72
|
+
function validateSuitesFilter() {
|
|
73
|
+
if (!('suites' in runnerOptions)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!runnerOptions.filters.suites || !runnerOptions.filters.suites.length) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const suites = runnerOptions.suites.map(({ name }) => name);
|
|
80
|
+
const invalidSuites = runnerOptions.filters.suites.filter((suite) => !suites.includes(suite));
|
|
81
|
+
if (invalidSuites.length) {
|
|
82
|
+
throw new Error(`Unrecognized suite "${invalidSuites[0]}". Make sure to define it in the config first`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
68
85
|
/**
|
|
69
86
|
* End tests. We wait for the "beforeExit" event when
|
|
70
87
|
* forceExit is not set to true
|
|
@@ -227,7 +244,7 @@ async function importFiles(files) {
|
|
|
227
244
|
* Run japa tests
|
|
228
245
|
*/
|
|
229
246
|
async function run() {
|
|
230
|
-
const runner = new
|
|
247
|
+
const runner = new Core_1.Runner(emitter);
|
|
231
248
|
runner.manageUnHandledExceptions();
|
|
232
249
|
runner.onSuite(runnerOptions.configureSuite);
|
|
233
250
|
const hooks = new hooks_1.Hooks();
|
|
@@ -244,6 +261,7 @@ async function run() {
|
|
|
244
261
|
for (let plugin of runnerOptions.plugins) {
|
|
245
262
|
await plugin(runnerOptions, runner, { Test: Core_1.Test, TestContext: Core_1.TestContext, Group: Core_1.Group });
|
|
246
263
|
}
|
|
264
|
+
validateSuitesFilter();
|
|
247
265
|
/**
|
|
248
266
|
* Step 2: Notify runner about reporters
|
|
249
267
|
*/
|
|
@@ -268,8 +286,8 @@ async function run() {
|
|
|
268
286
|
* as part of the default suite
|
|
269
287
|
*/
|
|
270
288
|
if ('files' in runnerOptions && runnerOptions.files.length) {
|
|
271
|
-
const files = await collectFiles(runnerOptions.files);
|
|
272
289
|
globalTimeout = runnerOptions.timeout;
|
|
290
|
+
const files = await collectFiles(runnerOptions.files);
|
|
273
291
|
runner.add(activeSuite);
|
|
274
292
|
await importFiles(files);
|
|
275
293
|
}
|
|
@@ -286,7 +304,7 @@ async function run() {
|
|
|
286
304
|
else {
|
|
287
305
|
globalTimeout = runnerOptions.timeout;
|
|
288
306
|
}
|
|
289
|
-
activeSuite = new
|
|
307
|
+
activeSuite = new Core_1.Suite(suite.name, emitter);
|
|
290
308
|
const files = await collectFiles(suite.files);
|
|
291
309
|
runner.add(activeSuite);
|
|
292
310
|
await importFiles(files);
|
|
@@ -359,7 +377,7 @@ exports.run = run;
|
|
|
359
377
|
*/
|
|
360
378
|
function processCliArgs(argv) {
|
|
361
379
|
const parsed = (0, getopts_1.default)(argv, {
|
|
362
|
-
string: ['tests', 'tags', 'groups', 'ignoreTags', 'files', 'timeout'
|
|
380
|
+
string: ['tests', 'tags', 'groups', 'ignoreTags', 'files', 'timeout'],
|
|
363
381
|
boolean: ['forceExit'],
|
|
364
382
|
alias: {
|
|
365
383
|
ignoreTags: 'ignore-tags',
|
|
@@ -376,13 +394,24 @@ function processCliArgs(argv) {
|
|
|
376
394
|
processAsString(parsed, 'groups', (groups) => (config.filters.groups = groups));
|
|
377
395
|
processAsString(parsed, 'tests', (tests) => (config.filters.tests = tests));
|
|
378
396
|
processAsString(parsed, 'files', (files) => (config.filters.files = files));
|
|
379
|
-
|
|
397
|
+
/**
|
|
398
|
+
* Get suites
|
|
399
|
+
*/
|
|
400
|
+
if (parsed._.length) {
|
|
401
|
+
processAsString({ suites: parsed._ }, 'suites', (suites) => (config.filters.suites = suites));
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Get timeout
|
|
405
|
+
*/
|
|
380
406
|
if (parsed.timeout) {
|
|
381
407
|
const value = Number(parsed.timeout);
|
|
382
408
|
if (!isNaN(value)) {
|
|
383
409
|
config.timeout = value;
|
|
384
410
|
}
|
|
385
411
|
}
|
|
412
|
+
/**
|
|
413
|
+
* Get forceExit
|
|
414
|
+
*/
|
|
386
415
|
if (parsed.forceExit) {
|
|
387
416
|
config.forceExit = true;
|
|
388
417
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Test, Group, TestContext } from '../Core';
|
|
1
|
+
import { Refiner, FilteringOptions, ReporterContract } from '@japa/core';
|
|
2
|
+
import { Test, Group, TestContext, Runner, Suite } from '../Core';
|
|
3
3
|
/**
|
|
4
4
|
* The cleanup function for runner hooks
|
|
5
5
|
*/
|
|
6
|
-
export declare type RunnerHooksCleanupHandler = (error: null | any, runner: Runner
|
|
6
|
+
export declare type RunnerHooksCleanupHandler = (error: null | any, runner: Runner) => Promise<any> | any;
|
|
7
7
|
/**
|
|
8
8
|
* The function that can be registered as a runner hook
|
|
9
9
|
*/
|
|
10
|
-
export declare type RunnerHooksHandler = (runner: Runner
|
|
10
|
+
export declare type RunnerHooksHandler = (runner: Runner) => Promise<any> | any | RunnerHooksCleanupHandler | Promise<RunnerHooksCleanupHandler>;
|
|
11
11
|
/**
|
|
12
12
|
* Allowed filters
|
|
13
13
|
*/
|
|
@@ -18,30 +18,35 @@ export declare type Filters = FilteringOptions & {
|
|
|
18
18
|
/**
|
|
19
19
|
* Shape of the plugin function
|
|
20
20
|
*/
|
|
21
|
-
export declare type PluginFn = (config: Required<
|
|
21
|
+
export declare type PluginFn = (config: Required<Config>, runner: Runner, classes: {
|
|
22
22
|
Test: typeof Test;
|
|
23
23
|
TestContext: typeof TestContext;
|
|
24
24
|
Group: typeof Group;
|
|
25
25
|
}) => void | Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Runner hooks
|
|
28
|
+
*/
|
|
29
|
+
export declare type RunnerHooks = {
|
|
30
|
+
setup: RunnerHooksHandler[];
|
|
31
|
+
teardown: RunnerHooksHandler[];
|
|
32
|
+
};
|
|
26
33
|
/**
|
|
27
34
|
* Base configuration options
|
|
28
35
|
*/
|
|
29
|
-
export declare type
|
|
36
|
+
export declare type BaseConfig = {
|
|
30
37
|
timeout?: number;
|
|
31
38
|
plugins?: PluginFn[];
|
|
32
39
|
filters?: Filters;
|
|
33
|
-
configureSuite?: (suite: Suite
|
|
34
|
-
setup?: RunnerHooksHandler[];
|
|
35
|
-
teardown?: RunnerHooksHandler[];
|
|
40
|
+
configureSuite?: (suite: Suite) => void;
|
|
36
41
|
reporters?: ReporterContract[];
|
|
37
42
|
importer?: (filePath: string) => void | Promise<void>;
|
|
38
43
|
refiner?: Refiner;
|
|
39
44
|
forceExit?: boolean;
|
|
40
|
-
}
|
|
45
|
+
} & Partial<RunnerHooks>;
|
|
41
46
|
/**
|
|
42
47
|
* Configuration options
|
|
43
48
|
*/
|
|
44
|
-
export declare type
|
|
49
|
+
export declare type Config = BaseConfig & ({
|
|
45
50
|
files: string[] | (() => string[] | Promise<string[]>);
|
|
46
51
|
} | {
|
|
47
52
|
suites: {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { Test, Group, TestContext as BaseTestContext } from '@japa/core';
|
|
1
|
+
import { DataSetNode, Test as BaseTest, Group as BaseGroup, Suite as BaseSuite, Runner as BaseRunner, TestContext as BaseTestContext } from '@japa/core';
|
|
2
2
|
export declare class TestContext extends BaseTestContext {
|
|
3
|
-
test: Test
|
|
4
|
-
constructor(test: Test
|
|
3
|
+
test: Test;
|
|
4
|
+
constructor(test: Test);
|
|
5
|
+
}
|
|
6
|
+
export declare class Test<TestData extends DataSetNode = undefined> extends BaseTest<TestContext, TestData> {
|
|
7
|
+
static disposeCallback: never[];
|
|
8
|
+
}
|
|
9
|
+
export declare class Group extends BaseGroup<TestContext> {
|
|
10
|
+
}
|
|
11
|
+
export declare class Suite extends BaseSuite<TestContext> {
|
|
12
|
+
}
|
|
13
|
+
export declare class Runner extends BaseRunner<TestContext> {
|
|
5
14
|
}
|
|
6
|
-
export { Group, Test };
|
package/build/src/Core/index.js
CHANGED
|
@@ -8,10 +8,8 @@
|
|
|
8
8
|
* file that was distributed with this source code.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.
|
|
11
|
+
exports.Runner = exports.Suite = exports.Group = exports.Test = exports.TestContext = void 0;
|
|
12
12
|
const core_1 = require("@japa/core");
|
|
13
|
-
Object.defineProperty(exports, "Test", { enumerable: true, get: function () { return core_1.Test; } });
|
|
14
|
-
Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return core_1.Group; } });
|
|
15
13
|
class TestContext extends core_1.TestContext {
|
|
16
14
|
constructor(test) {
|
|
17
15
|
super();
|
|
@@ -19,3 +17,16 @@ class TestContext extends core_1.TestContext {
|
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
exports.TestContext = TestContext;
|
|
20
|
+
class Test extends core_1.Test {
|
|
21
|
+
}
|
|
22
|
+
exports.Test = Test;
|
|
23
|
+
Test.disposeCallback = [];
|
|
24
|
+
class Group extends core_1.Group {
|
|
25
|
+
}
|
|
26
|
+
exports.Group = Group;
|
|
27
|
+
class Suite extends core_1.Suite {
|
|
28
|
+
}
|
|
29
|
+
exports.Suite = Suite;
|
|
30
|
+
class Runner extends core_1.Runner {
|
|
31
|
+
}
|
|
32
|
+
exports.Runner = Runner;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@japa/runner",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Runner for Japa testing framework",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"files": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"cz-conventional-changelog": "^3.3.0",
|
|
42
42
|
"del-cli": "^4.0.1",
|
|
43
43
|
"eslint": "^8.10.0",
|
|
44
|
-
"eslint-config-prettier": "^8.
|
|
44
|
+
"eslint-config-prettier": "^8.5.0",
|
|
45
45
|
"eslint-plugin-adonis": "^2.1.0",
|
|
46
46
|
"eslint-plugin-prettier": "^4.0.0",
|
|
47
47
|
"github-label-sync": "^2.0.2",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"mrm": "^3.0.10",
|
|
51
51
|
"np": "^7.6.0",
|
|
52
52
|
"prettier": "^2.5.1",
|
|
53
|
-
"typescript": "^4.
|
|
53
|
+
"typescript": "^4.6.2"
|
|
54
54
|
},
|
|
55
55
|
"mrmConfig": {
|
|
56
56
|
"core": false,
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"anyBranch": false
|
|
106
106
|
},
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"@japa/core": "^
|
|
108
|
+
"@japa/core": "^6.0.0",
|
|
109
109
|
"@japa/errors-printer": "^1.3.3",
|
|
110
110
|
"@poppinss/hooks": "^6.0.2-0",
|
|
111
111
|
"fast-glob": "^3.2.11",
|