@japa/runner 3.0.0-2 → 3.0.0-4
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/factories/main.d.ts +3 -1
- package/build/factories/main.js +11 -0
- package/build/factories/runner.d.ts +18 -1
- package/build/factories/runner.js +45 -0
- package/build/index.d.ts +22 -1
- package/build/index.js +95 -0
- package/build/modules/core/main.d.ts +34 -1
- package/build/modules/core/main.js +53 -0
- package/build/modules/core/reporters/base.d.ts +21 -1
- package/build/modules/core/reporters/base.js +47 -0
- package/build/modules/core/types.d.ts +0 -1
- package/build/modules/core/types.js +8 -0
- package/build/src/cli_parser.d.ts +9 -1
- package/build/src/cli_parser.js +25 -0
- package/build/src/config_manager.d.ts +11 -1
- package/build/src/config_manager.js +49 -2
- package/build/src/create_test.d.ts +6 -1
- package/build/src/create_test.js +20 -0
- package/build/src/debug.d.ts +0 -1
- package/build/src/debug.js +8 -0
- package/build/src/exceptions_manager.d.ts +13 -1
- package/build/src/exceptions_manager.js +27 -0
- package/build/src/files_manager.d.ts +12 -1
- package/build/src/files_manager.js +24 -0
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +8 -0
- package/build/src/hooks.d.ts +12 -1
- package/build/src/hooks.js +20 -0
- package/build/src/planner.d.ts +8 -1
- package/build/src/planner.js +31 -0
- package/build/src/plugins/retry.d.ts +13 -1
- package/build/src/plugins/retry.js +24 -0
- package/build/src/reporters/dot.d.ts +9 -1
- package/build/src/reporters/dot.js +17 -0
- package/build/src/reporters/main.d.ts +9 -1
- package/build/src/reporters/main.js +17 -0
- package/build/src/reporters/ndjson.d.ts +4 -1
- package/build/src/reporters/ndjson.js +15 -0
- package/build/src/reporters/spec.d.ts +3 -1
- package/build/src/reporters/spec.js +51 -0
- package/build/src/types.d.ts +91 -1
- package/build/src/types.js +8 -0
- package/build/src/validator.d.ts +20 -1
- package/build/src/validator.js +39 -0
- package/package.json +33 -33
- package/build/factories/main.d.ts.map +0 -1
- package/build/factories/runner.d.ts.map +0 -1
- package/build/modules/core/main.d.ts.map +0 -1
- package/build/modules/core/reporters/base.d.ts.map +0 -1
- package/build/modules/core/types.d.ts.map +0 -1
- package/build/src/cli_parser.d.ts.map +0 -1
- package/build/src/config_manager.d.ts.map +0 -1
- package/build/src/create_test.d.ts.map +0 -1
- package/build/src/debug.d.ts.map +0 -1
- package/build/src/exceptions_manager.d.ts.map +0 -1
- package/build/src/files_manager.d.ts.map +0 -1
- package/build/src/helpers.d.ts.map +0 -1
- package/build/src/hooks.d.ts.map +0 -1
- package/build/src/planner.d.ts.map +0 -1
- package/build/src/plugins/retry.d.ts.map +0 -1
- package/build/src/reporters/dot.d.ts.map +0 -1
- package/build/src/reporters/main.d.ts.map +0 -1
- package/build/src/reporters/ndjson.d.ts.map +0 -1
- package/build/src/reporters/spec.d.ts.map +0 -1
- package/build/src/types.d.ts.map +0 -1
- package/build/src/validator.d.ts.map +0 -1
package/build/factories/main.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @japa/runner
|
|
3
|
+
*
|
|
4
|
+
* (c) Japa
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import { RunnerFactory } from './runner.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create an instance of the runner factory
|
|
12
|
+
*/
|
|
2
13
|
export const runner = () => new RunnerFactory();
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { Config } from '../src/types.js';
|
|
2
2
|
import { Suite, Emitter } from '../modules/core/main.js';
|
|
3
|
+
/**
|
|
4
|
+
* Runner factory exposes the API to run dummy suites, groups and tests.
|
|
5
|
+
* You might want to use the factory for testing reporters and
|
|
6
|
+
* plugins usage
|
|
7
|
+
*/
|
|
3
8
|
export declare class RunnerFactory {
|
|
4
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Configure runner
|
|
12
|
+
*/
|
|
5
13
|
configure(config: Config, argv?: string[]): this;
|
|
14
|
+
/**
|
|
15
|
+
* Register custom suites to execute instead
|
|
16
|
+
* of the dummy one's
|
|
17
|
+
*/
|
|
6
18
|
withSuites(suites: Suite[]): this;
|
|
19
|
+
/**
|
|
20
|
+
* Define a custom emitter instance to use
|
|
21
|
+
*/
|
|
7
22
|
useEmitter(emitter: Emitter): this;
|
|
23
|
+
/**
|
|
24
|
+
* Run dummy tests. You might use
|
|
25
|
+
*/
|
|
8
26
|
run(): Promise<import("@japa/core/types").RunnerSummary>;
|
|
9
27
|
}
|
|
10
|
-
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @japa/runner
|
|
3
|
+
*
|
|
4
|
+
* (c) Japa
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import assert from 'node:assert';
|
|
2
10
|
import { fileURLToPath } from 'node:url';
|
|
3
11
|
import { Planner } from '../src/planner.js';
|
|
@@ -6,6 +14,11 @@ import { CliParser } from '../src/cli_parser.js';
|
|
|
6
14
|
import { ConfigManager } from '../src/config_manager.js';
|
|
7
15
|
import { createTest, createTestGroup } from '../src/create_test.js';
|
|
8
16
|
import { Suite, Runner, Emitter } from '../modules/core/main.js';
|
|
17
|
+
/**
|
|
18
|
+
* Runner factory exposes the API to run dummy suites, groups and tests.
|
|
19
|
+
* You might want to use the factory for testing reporters and
|
|
20
|
+
* plugins usage
|
|
21
|
+
*/
|
|
9
22
|
export class RunnerFactory {
|
|
10
23
|
#emitter = new Emitter();
|
|
11
24
|
#config;
|
|
@@ -15,12 +28,18 @@ export class RunnerFactory {
|
|
|
15
28
|
get #refiner() {
|
|
16
29
|
return this.#config.refiner;
|
|
17
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Creating unit and functional suites
|
|
33
|
+
*/
|
|
18
34
|
#createSuites() {
|
|
19
35
|
return [
|
|
20
36
|
new Suite('unit', this.#emitter, this.#refiner),
|
|
21
37
|
new Suite('functional', this.#emitter, this.#refiner),
|
|
22
38
|
];
|
|
23
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a variety of tests for Maths.add method
|
|
42
|
+
*/
|
|
24
43
|
#createAdditionTests(group) {
|
|
25
44
|
createTest('add two numbers', this.#emitter, this.#refiner, { group, file: this.#file }).run(() => {
|
|
26
45
|
assert.equal(2 + 2, 4);
|
|
@@ -45,6 +64,10 @@ export class RunnerFactory {
|
|
|
45
64
|
})
|
|
46
65
|
.fails('Have to add support for floating numbers');
|
|
47
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a variety of dummy tests for creating
|
|
69
|
+
* a new user
|
|
70
|
+
*/
|
|
48
71
|
#createUserStoreTests(group) {
|
|
49
72
|
createTest('Validate user data', this.#emitter, this.#refiner, {
|
|
50
73
|
group,
|
|
@@ -70,6 +93,9 @@ export class RunnerFactory {
|
|
|
70
93
|
file: this.#file,
|
|
71
94
|
});
|
|
72
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates tests for the unit tests suite
|
|
98
|
+
*/
|
|
73
99
|
#createUnitTests(suite) {
|
|
74
100
|
const additionGroup = createTestGroup('Maths#add', this.#emitter, this.#refiner, {
|
|
75
101
|
suite,
|
|
@@ -81,6 +107,9 @@ export class RunnerFactory {
|
|
|
81
107
|
file: this.#file,
|
|
82
108
|
}).run(() => { });
|
|
83
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates tests for the functional tests suite
|
|
112
|
+
*/
|
|
84
113
|
#createFunctionalTests(suite) {
|
|
85
114
|
const usersStoreGroup = createTestGroup('Users/store', this.#emitter, this.#refiner, {
|
|
86
115
|
suite,
|
|
@@ -100,6 +129,9 @@ export class RunnerFactory {
|
|
|
100
129
|
file: this.#file,
|
|
101
130
|
}).run(() => { });
|
|
102
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Registers plugins
|
|
134
|
+
*/
|
|
103
135
|
async #registerPlugins(runner) {
|
|
104
136
|
for (let plugin of this.#config.plugins) {
|
|
105
137
|
await plugin({
|
|
@@ -110,19 +142,32 @@ export class RunnerFactory {
|
|
|
110
142
|
});
|
|
111
143
|
}
|
|
112
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Configure runner
|
|
147
|
+
*/
|
|
113
148
|
configure(config, argv) {
|
|
114
149
|
this.#cliArgs = new CliParser().parse(argv || []);
|
|
115
150
|
this.#config = new ConfigManager(config, this.#cliArgs).hydrate();
|
|
116
151
|
return this;
|
|
117
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Register custom suites to execute instead
|
|
155
|
+
* of the dummy one's
|
|
156
|
+
*/
|
|
118
157
|
withSuites(suites) {
|
|
119
158
|
this.#suites = suites;
|
|
120
159
|
return this;
|
|
121
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Define a custom emitter instance to use
|
|
163
|
+
*/
|
|
122
164
|
useEmitter(emitter) {
|
|
123
165
|
this.#emitter = emitter;
|
|
124
166
|
return this;
|
|
125
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Run dummy tests. You might use
|
|
170
|
+
*/
|
|
126
171
|
async run() {
|
|
127
172
|
const runner = new Runner(this.#emitter);
|
|
128
173
|
await this.#registerPlugins(runner);
|
package/build/index.d.ts
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
import type { TestExecutor } from '@japa/core/types';
|
|
2
2
|
import type { Config } from './src/types.js';
|
|
3
3
|
import { Group, Test, TestContext } from './modules/core/main.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a Japa test. Defining a test without the callback
|
|
6
|
+
* will create a todo test.
|
|
7
|
+
*/
|
|
4
8
|
export declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<undefined>;
|
|
5
9
|
export declare namespace test {
|
|
6
10
|
var group: (title: string, callback: (group: Group) => void) => void;
|
|
7
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Get the test of currently running test
|
|
14
|
+
*/
|
|
8
15
|
export declare function getActiveTest(): Test<any> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Make Japa process command line arguments. Later the parsed output
|
|
18
|
+
* will be used by Japa to compute the configuration
|
|
19
|
+
*/
|
|
9
20
|
export declare function processCLIArgs(argv: string[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Configure the tests runner with inline configuration. You must
|
|
23
|
+
* call configure method before the run method.
|
|
24
|
+
*
|
|
25
|
+
* Do note: The CLI flags will overwrite the options provided
|
|
26
|
+
* to the configure method.
|
|
27
|
+
*/
|
|
10
28
|
export declare function configure(options: Config): void;
|
|
29
|
+
/**
|
|
30
|
+
* Execute Japa tests. Calling this function will import the test
|
|
31
|
+
* files behind the scenes
|
|
32
|
+
*/
|
|
11
33
|
export declare function run(): Promise<void>;
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
package/build/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @japa/runner
|
|
3
|
+
*
|
|
4
|
+
* (c) Japa
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import { fileURLToPath } from 'node:url';
|
|
2
10
|
import { ErrorsPrinter } from '@japa/errors-printer';
|
|
3
11
|
import debug from './src/debug.js';
|
|
@@ -10,13 +18,34 @@ import { ConfigManager } from './src/config_manager.js';
|
|
|
10
18
|
import { ExceptionsManager } from './src/exceptions_manager.js';
|
|
11
19
|
import { createTest, createTestGroup } from './src/create_test.js';
|
|
12
20
|
import { Emitter, Runner, Suite } from './modules/core/main.js';
|
|
21
|
+
/**
|
|
22
|
+
* Global emitter instance used by the test
|
|
23
|
+
*/
|
|
13
24
|
const emitter = new Emitter();
|
|
25
|
+
/**
|
|
26
|
+
* The current active test
|
|
27
|
+
*/
|
|
14
28
|
let activeTest;
|
|
29
|
+
/**
|
|
30
|
+
* Parsed commandline arguments
|
|
31
|
+
*/
|
|
15
32
|
let cliArgs = {};
|
|
33
|
+
/**
|
|
34
|
+
* Hydrated config
|
|
35
|
+
*/
|
|
16
36
|
let runnerConfig;
|
|
37
|
+
/**
|
|
38
|
+
* The state refers to the phase where we configure suites and import
|
|
39
|
+
* test files. We stick this metadata to the test instance one can
|
|
40
|
+
* later reference within the test.
|
|
41
|
+
*/
|
|
17
42
|
const executionPlanState = {
|
|
18
43
|
phase: 'idle',
|
|
19
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Create a Japa test. Defining a test without the callback
|
|
47
|
+
* will create a todo test.
|
|
48
|
+
*/
|
|
20
49
|
export function test(title, callback) {
|
|
21
50
|
validator.ensureIsInPlanningPhase(executionPlanState.phase);
|
|
22
51
|
const testInstance = createTest(title, emitter, runnerConfig.refiner, executionPlanState);
|
|
@@ -31,22 +60,46 @@ export function test(title, callback) {
|
|
|
31
60
|
}
|
|
32
61
|
return testInstance;
|
|
33
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a Japa test group
|
|
65
|
+
*/
|
|
34
66
|
test.group = function (title, callback) {
|
|
35
67
|
validator.ensureIsInPlanningPhase(executionPlanState.phase);
|
|
36
68
|
executionPlanState.group = createTestGroup(title, emitter, runnerConfig.refiner, executionPlanState);
|
|
37
69
|
callback(executionPlanState.group);
|
|
38
70
|
executionPlanState.group = undefined;
|
|
39
71
|
};
|
|
72
|
+
/**
|
|
73
|
+
* Get the test of currently running test
|
|
74
|
+
*/
|
|
40
75
|
export function getActiveTest() {
|
|
41
76
|
return activeTest;
|
|
42
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Make Japa process command line arguments. Later the parsed output
|
|
80
|
+
* will be used by Japa to compute the configuration
|
|
81
|
+
*/
|
|
43
82
|
export function processCLIArgs(argv) {
|
|
44
83
|
cliArgs = new CliParser().parse(argv);
|
|
45
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Configure the tests runner with inline configuration. You must
|
|
87
|
+
* call configure method before the run method.
|
|
88
|
+
*
|
|
89
|
+
* Do note: The CLI flags will overwrite the options provided
|
|
90
|
+
* to the configure method.
|
|
91
|
+
*/
|
|
46
92
|
export function configure(options) {
|
|
47
93
|
runnerConfig = new ConfigManager(options, cliArgs).hydrate();
|
|
48
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Execute Japa tests. Calling this function will import the test
|
|
97
|
+
* files behind the scenes
|
|
98
|
+
*/
|
|
49
99
|
export async function run() {
|
|
100
|
+
/**
|
|
101
|
+
* Display help when help flag is used
|
|
102
|
+
*/
|
|
50
103
|
if (cliArgs.help) {
|
|
51
104
|
console.log(new CliParser().getHelp());
|
|
52
105
|
return;
|
|
@@ -57,12 +110,26 @@ export async function run() {
|
|
|
57
110
|
const globalHooks = new GlobalHooks();
|
|
58
111
|
const exceptionsManager = new ExceptionsManager();
|
|
59
112
|
try {
|
|
113
|
+
/**
|
|
114
|
+
* Executing the retry plugin as the first thing
|
|
115
|
+
*/
|
|
60
116
|
await retryPlugin({ config: runnerConfig, runner, emitter, cliArgs });
|
|
117
|
+
/**
|
|
118
|
+
* Step 1: Executing plugins before creating a plan, so that it can mutate
|
|
119
|
+
* the config
|
|
120
|
+
*/
|
|
61
121
|
for (let plugin of runnerConfig.plugins) {
|
|
62
122
|
debug('executing "%s" plugin', plugin.name || 'anonymous');
|
|
63
123
|
await plugin({ runner, emitter, cliArgs, config: runnerConfig });
|
|
64
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Step 2: Creating an execution plan. The output is the result of
|
|
127
|
+
* applying all the filters and validations.
|
|
128
|
+
*/
|
|
65
129
|
const { config, reporters, suites, refinerFilters } = await new Planner(runnerConfig).plan();
|
|
130
|
+
/**
|
|
131
|
+
* Step 3: Registering reporters and filters with the runner
|
|
132
|
+
*/
|
|
66
133
|
reporters.forEach((reporter) => {
|
|
67
134
|
debug('registering "%s" reporter', reporter.name);
|
|
68
135
|
runner.registerReporter(reporter);
|
|
@@ -73,10 +140,19 @@ export async function run() {
|
|
|
73
140
|
});
|
|
74
141
|
config.refiner.matchAllTags(cliArgs.matchAll ?? false);
|
|
75
142
|
runner.onSuite(config.configureSuite);
|
|
143
|
+
/**
|
|
144
|
+
* Step 4: Running the setup hooks
|
|
145
|
+
*/
|
|
76
146
|
debug('executing global hooks');
|
|
77
147
|
globalHooks.apply(config);
|
|
78
148
|
await globalHooks.setup(runner);
|
|
149
|
+
/**
|
|
150
|
+
* Step 5: Register suites and import test files
|
|
151
|
+
*/
|
|
79
152
|
for (let suite of suites) {
|
|
153
|
+
/**
|
|
154
|
+
* Creating and configuring the suite
|
|
155
|
+
*/
|
|
80
156
|
executionPlanState.suite = new Suite(suite.name, emitter, config.refiner);
|
|
81
157
|
executionPlanState.retries = suite.retries;
|
|
82
158
|
executionPlanState.timeout = suite.timeout;
|
|
@@ -84,19 +160,34 @@ export async function run() {
|
|
|
84
160
|
suite.configure(executionPlanState.suite);
|
|
85
161
|
}
|
|
86
162
|
runner.add(executionPlanState.suite);
|
|
163
|
+
/**
|
|
164
|
+
* Importing suite files
|
|
165
|
+
*/
|
|
87
166
|
for (let fileURL of suite.filesURLs) {
|
|
88
167
|
executionPlanState.file = fileURLToPath(fileURL);
|
|
89
168
|
debug('importing test file %s', executionPlanState.file);
|
|
90
169
|
await config.importer(fileURL);
|
|
91
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Resetting global state
|
|
173
|
+
*/
|
|
92
174
|
executionPlanState.suite = undefined;
|
|
93
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Onto execution phase
|
|
178
|
+
*/
|
|
94
179
|
executionPlanState.phase = 'executing';
|
|
180
|
+
/**
|
|
181
|
+
* Monitor for unhandled erorrs and rejections
|
|
182
|
+
*/
|
|
95
183
|
exceptionsManager.monitor();
|
|
96
184
|
await runner.start();
|
|
97
185
|
await runner.exec();
|
|
98
186
|
await globalHooks.teardown(null, runner);
|
|
99
187
|
await runner.end();
|
|
188
|
+
/**
|
|
189
|
+
* Print unhandled errors
|
|
190
|
+
*/
|
|
100
191
|
await exceptionsManager.flow();
|
|
101
192
|
const summary = runner.getSummary();
|
|
102
193
|
if (summary.hasError || exceptionsManager.hasErrors) {
|
|
@@ -110,6 +201,10 @@ export async function run() {
|
|
|
110
201
|
await globalHooks.teardown(error, runner);
|
|
111
202
|
const printer = new ErrorsPrinter();
|
|
112
203
|
await printer.printError(error);
|
|
204
|
+
/**
|
|
205
|
+
* Print unhandled errors in case the code inside
|
|
206
|
+
* the try block never got triggered
|
|
207
|
+
*/
|
|
113
208
|
await exceptionsManager.flow();
|
|
114
209
|
process.exitCode = 1;
|
|
115
210
|
if (runnerConfig.forceExit) {
|
|
@@ -10,20 +10,53 @@ declare module '@japa/core' {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
export { Emitter, Refiner, BaseReporter };
|
|
13
|
+
/**
|
|
14
|
+
* Test context carries context data for a given test.
|
|
15
|
+
*/
|
|
13
16
|
export declare class TestContext extends BaseTestContext {
|
|
14
17
|
test: Test;
|
|
18
|
+
/**
|
|
19
|
+
* Register a cleanup function that runs after the test finishes
|
|
20
|
+
* successfully or with an error.
|
|
21
|
+
*/
|
|
15
22
|
cleanup: (cleanupCallback: TestHooksCleanupHandler<TestContext>) => void;
|
|
16
23
|
constructor(test: Test);
|
|
17
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Test class represents an individual test and exposes API to tweak
|
|
27
|
+
* its runtime behavior.
|
|
28
|
+
*/
|
|
18
29
|
export declare class Test<TestData extends DataSetNode = undefined> extends BaseTest<TestContext, TestData> {
|
|
30
|
+
/**
|
|
31
|
+
* @inheritdoc
|
|
32
|
+
*/
|
|
19
33
|
static executedCallbacks: never[];
|
|
34
|
+
/**
|
|
35
|
+
* @inheritdoc
|
|
36
|
+
*/
|
|
20
37
|
static executingCallbacks: never[];
|
|
38
|
+
/**
|
|
39
|
+
* Assert the test callback throws an exception when a certain
|
|
40
|
+
* error message and optionally is an instance of a given
|
|
41
|
+
* Error class.
|
|
42
|
+
*/
|
|
21
43
|
throws(message: string | RegExp, errorConstructor?: any): this;
|
|
22
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* TestGroup is used to bulk configure a collection of tests and
|
|
47
|
+
* define lifecycle hooks for them
|
|
48
|
+
*/
|
|
23
49
|
export declare class Group extends BaseGroup<TestContext> {
|
|
24
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A suite is a collection of tests created around a given
|
|
53
|
+
* testing type. For example: A suite for unit tests, a
|
|
54
|
+
* suite for functional tests and so on.
|
|
55
|
+
*/
|
|
25
56
|
export declare class Suite extends BaseSuite<TestContext> {
|
|
26
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Runner class is used to execute the tests
|
|
60
|
+
*/
|
|
27
61
|
export declare class Runner extends BaseRunner<TestContext> {
|
|
28
62
|
}
|
|
29
|
-
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @japa/runner
|
|
3
|
+
*
|
|
4
|
+
* (c) Japa
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import { Emitter, Refiner, Test as BaseTest, Suite as BaseSuite, Group as BaseGroup, Runner as BaseRunner, TestContext as BaseTestContext, } from '@japa/core';
|
|
2
10
|
import { inspect } from 'node:util';
|
|
3
11
|
import { AssertionError } from 'node:assert';
|
|
4
12
|
import { BaseReporter } from './reporters/base.js';
|
|
5
13
|
export { Emitter, Refiner, BaseReporter };
|
|
14
|
+
/**
|
|
15
|
+
* Test context carries context data for a given test.
|
|
16
|
+
*/
|
|
6
17
|
export class TestContext extends BaseTestContext {
|
|
7
18
|
test;
|
|
8
19
|
constructor(test) {
|
|
@@ -13,15 +24,33 @@ export class TestContext extends BaseTestContext {
|
|
|
13
24
|
};
|
|
14
25
|
}
|
|
15
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Test class represents an individual test and exposes API to tweak
|
|
29
|
+
* its runtime behavior.
|
|
30
|
+
*/
|
|
16
31
|
export class Test extends BaseTest {
|
|
32
|
+
/**
|
|
33
|
+
* @inheritdoc
|
|
34
|
+
*/
|
|
17
35
|
static executedCallbacks = [];
|
|
36
|
+
/**
|
|
37
|
+
* @inheritdoc
|
|
38
|
+
*/
|
|
18
39
|
static executingCallbacks = [];
|
|
40
|
+
/**
|
|
41
|
+
* Assert the test callback throws an exception when a certain
|
|
42
|
+
* error message and optionally is an instance of a given
|
|
43
|
+
* Error class.
|
|
44
|
+
*/
|
|
19
45
|
throws(message, errorConstructor) {
|
|
20
46
|
const errorInPoint = new AssertionError({});
|
|
21
47
|
const existingExecutor = this.options.executor;
|
|
22
48
|
if (!existingExecutor) {
|
|
23
49
|
throw new Error('Cannot use "test.throws" method without a test callback');
|
|
24
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Overwriting existing callback
|
|
53
|
+
*/
|
|
25
54
|
this.options.executor = async (...args) => {
|
|
26
55
|
let raisedException;
|
|
27
56
|
try {
|
|
@@ -30,19 +59,31 @@ export class Test extends BaseTest {
|
|
|
30
59
|
catch (error) {
|
|
31
60
|
raisedException = error;
|
|
32
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Notify no exception has been raised
|
|
64
|
+
*/
|
|
33
65
|
if (!raisedException) {
|
|
34
66
|
errorInPoint.message = 'Expected test to throw an exception';
|
|
35
67
|
throw errorInPoint;
|
|
36
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Constructor mis-match
|
|
71
|
+
*/
|
|
37
72
|
if (errorConstructor && !(raisedException instanceof errorConstructor)) {
|
|
38
73
|
errorInPoint.message = `Expected test to throw "${inspect(errorConstructor)}"`;
|
|
39
74
|
throw errorInPoint;
|
|
40
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Error does not have a message property
|
|
78
|
+
*/
|
|
41
79
|
const exceptionMessage = raisedException.message;
|
|
42
80
|
if (!exceptionMessage || typeof exceptionMessage !== 'string') {
|
|
43
81
|
errorInPoint.message = 'Expected test to throw an exception with message property';
|
|
44
82
|
throw errorInPoint;
|
|
45
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Message does not match
|
|
86
|
+
*/
|
|
46
87
|
if (typeof message === 'string') {
|
|
47
88
|
if (exceptionMessage !== message) {
|
|
48
89
|
errorInPoint.message = `Expected test to throw "${message}". Instead received "${raisedException.message}"`;
|
|
@@ -60,9 +101,21 @@ export class Test extends BaseTest {
|
|
|
60
101
|
return this;
|
|
61
102
|
}
|
|
62
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* TestGroup is used to bulk configure a collection of tests and
|
|
106
|
+
* define lifecycle hooks for them
|
|
107
|
+
*/
|
|
63
108
|
export class Group extends BaseGroup {
|
|
64
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* A suite is a collection of tests created around a given
|
|
112
|
+
* testing type. For example: A suite for unit tests, a
|
|
113
|
+
* suite for functional tests and so on.
|
|
114
|
+
*/
|
|
65
115
|
export class Suite extends BaseSuite {
|
|
66
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Runner class is used to execute the tests
|
|
119
|
+
*/
|
|
67
120
|
export class Runner extends BaseRunner {
|
|
68
121
|
}
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import type { TestEndNode, SuiteEndNode, GroupEndNode, TestStartNode, RunnerSummary, RunnerEndNode, GroupStartNode, SuiteStartNode, RunnerStartNode, BaseReporterOptions } from '../types.js';
|
|
2
2
|
import { Emitter, Runner } from '../main.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base reporter to build custom reporters on top of
|
|
5
|
+
*/
|
|
3
6
|
export declare abstract class BaseReporter {
|
|
4
7
|
#private;
|
|
5
8
|
runner?: Runner;
|
|
9
|
+
/**
|
|
10
|
+
* Path to the file for which the tests are getting executed
|
|
11
|
+
*/
|
|
6
12
|
currentFileName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Suite for which the tests are getting executed
|
|
15
|
+
*/
|
|
7
16
|
currentSuiteName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Group for which the tests are getting executed
|
|
19
|
+
*/
|
|
8
20
|
currentGroupName?: string;
|
|
9
21
|
constructor(options?: BaseReporterOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Handlers to capture events
|
|
24
|
+
*/
|
|
10
25
|
protected onTestStart(_: TestStartNode): void;
|
|
11
26
|
protected onTestEnd(_: TestEndNode): void;
|
|
12
27
|
protected onGroupStart(_: GroupStartNode): void;
|
|
@@ -15,7 +30,12 @@ export declare abstract class BaseReporter {
|
|
|
15
30
|
protected onSuiteEnd(_: SuiteEndNode): void;
|
|
16
31
|
protected start(_: RunnerStartNode): Promise<void>;
|
|
17
32
|
protected end(_: RunnerEndNode): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Print tests summary
|
|
35
|
+
*/
|
|
18
36
|
protected printSummary(summary: RunnerSummary): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Invoked by the tests runner when tests are about to start
|
|
39
|
+
*/
|
|
19
40
|
boot(runner: Runner, emitter: Emitter): void;
|
|
20
41
|
}
|
|
21
|
-
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1,18 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @japa/runner
|
|
3
|
+
*
|
|
4
|
+
* (c) Japa
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import ms from 'ms';
|
|
2
10
|
import colors from '@poppinss/colors';
|
|
3
11
|
import { ErrorsPrinter } from '@japa/errors-printer';
|
|
4
12
|
const ansi = colors.ansi();
|
|
13
|
+
/**
|
|
14
|
+
* Base reporter to build custom reporters on top of
|
|
15
|
+
*/
|
|
5
16
|
export class BaseReporter {
|
|
6
17
|
#options;
|
|
7
18
|
runner;
|
|
19
|
+
/**
|
|
20
|
+
* Path to the file for which the tests are getting executed
|
|
21
|
+
*/
|
|
8
22
|
currentFileName;
|
|
23
|
+
/**
|
|
24
|
+
* Suite for which the tests are getting executed
|
|
25
|
+
*/
|
|
9
26
|
currentSuiteName;
|
|
27
|
+
/**
|
|
28
|
+
* Group for which the tests are getting executed
|
|
29
|
+
*/
|
|
10
30
|
currentGroupName;
|
|
11
31
|
constructor(options = {}) {
|
|
12
32
|
this.#options = Object.assign({ stackLinesCount: 2 }, options);
|
|
13
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Pretty prints the aggregates
|
|
36
|
+
*/
|
|
14
37
|
#printAggregates(summary) {
|
|
15
38
|
const tests = [];
|
|
39
|
+
/**
|
|
40
|
+
* Set value for tests row
|
|
41
|
+
*/
|
|
16
42
|
if (summary.aggregates.passed) {
|
|
17
43
|
tests.push(ansi.green(`${summary.aggregates.passed} passed`));
|
|
18
44
|
}
|
|
@@ -42,17 +68,26 @@ export class BaseReporter {
|
|
|
42
68
|
});
|
|
43
69
|
console.log(this.runner.summaryBuilder.build().join('\n'));
|
|
44
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Aggregates errors tree to a flat array
|
|
73
|
+
*/
|
|
45
74
|
#aggregateErrors(summary) {
|
|
46
75
|
const errorsList = [];
|
|
47
76
|
summary.failureTree.forEach((suite) => {
|
|
48
77
|
suite.errors.forEach((error) => errorsList.push({ title: suite.name, ...error }));
|
|
49
78
|
suite.children.forEach((testOrGroup) => {
|
|
79
|
+
/**
|
|
80
|
+
* Suite child is a test
|
|
81
|
+
*/
|
|
50
82
|
if (testOrGroup.type === 'test') {
|
|
51
83
|
testOrGroup.errors.forEach((error) => {
|
|
52
84
|
errorsList.push({ title: `${suite.name} / ${testOrGroup.title}`, ...error });
|
|
53
85
|
});
|
|
54
86
|
return;
|
|
55
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Suite child is a group
|
|
90
|
+
*/
|
|
56
91
|
testOrGroup.errors.forEach((error) => {
|
|
57
92
|
errorsList.push({ title: testOrGroup.name, ...error });
|
|
58
93
|
});
|
|
@@ -65,6 +100,9 @@ export class BaseReporter {
|
|
|
65
100
|
});
|
|
66
101
|
return errorsList;
|
|
67
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Pretty print errors
|
|
105
|
+
*/
|
|
68
106
|
async #printErrors(summary) {
|
|
69
107
|
if (!summary.failureTree.length) {
|
|
70
108
|
return;
|
|
@@ -76,6 +114,9 @@ export class BaseReporter {
|
|
|
76
114
|
errorPrinter.printSectionHeader('ERRORS');
|
|
77
115
|
await errorPrinter.printErrors(this.#aggregateErrors(summary));
|
|
78
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Handlers to capture events
|
|
119
|
+
*/
|
|
79
120
|
onTestStart(_) { }
|
|
80
121
|
onTestEnd(_) { }
|
|
81
122
|
onGroupStart(_) { }
|
|
@@ -84,6 +125,9 @@ export class BaseReporter {
|
|
|
84
125
|
onSuiteEnd(_) { }
|
|
85
126
|
async start(_) { }
|
|
86
127
|
async end(_) { }
|
|
128
|
+
/**
|
|
129
|
+
* Print tests summary
|
|
130
|
+
*/
|
|
87
131
|
async printSummary(summary) {
|
|
88
132
|
await this.#printErrors(summary);
|
|
89
133
|
console.log('');
|
|
@@ -100,6 +144,9 @@ export class BaseReporter {
|
|
|
100
144
|
console.log('');
|
|
101
145
|
this.#printAggregates(summary);
|
|
102
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Invoked by the tests runner when tests are about to start
|
|
149
|
+
*/
|
|
103
150
|
boot(runner, emitter) {
|
|
104
151
|
this.runner = runner;
|
|
105
152
|
emitter.on('test:start', (payload) => {
|