@japa/runner 3.0.0-8 → 3.0.0-9
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/examples/dot.d.ts +1 -0
- package/build/examples/dot.js +11 -0
- package/build/examples/ndjson.d.ts +1 -0
- package/build/examples/ndjson.js +11 -0
- package/build/examples/spec.d.ts +1 -0
- package/build/examples/spec.js +11 -0
- package/build/factories/create_diverse_tests.d.ts +6 -0
- package/build/factories/create_diverse_tests.js +106 -0
- package/build/factories/main.d.ts +5 -42
- package/build/factories/main.js +24 -208
- package/build/factories/runner.d.ts +26 -0
- package/build/factories/runner.js +93 -0
- package/build/index.d.ts +9 -14
- package/build/index.js +202 -237
- package/build/modules/core/main.d.ts +63 -3
- package/build/modules/core/main.js +121 -21
- package/build/modules/core/reporters/base.d.ts +41 -0
- package/build/modules/core/reporters/base.js +183 -0
- package/build/modules/core/types.d.ts +5 -0
- package/build/modules/core/types.js +9 -0
- package/build/src/cli_parser.d.ts +14 -0
- package/build/src/cli_parser.js +75 -0
- package/build/src/config_manager.d.ts +18 -0
- package/build/src/config_manager.js +168 -0
- package/build/src/create_test.d.ts +21 -0
- package/build/src/create_test.js +53 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/debug.js +10 -0
- package/build/src/exceptions_manager.d.ts +19 -0
- package/build/src/exceptions_manager.js +85 -0
- package/build/src/files_manager.d.ts +18 -0
- package/build/src/files_manager.js +57 -0
- package/build/src/helpers.d.ts +15 -0
- package/build/src/helpers.js +34 -0
- package/build/src/hooks.d.ts +20 -0
- package/build/src/hooks.js +46 -0
- package/build/src/planner.d.ts +25 -0
- package/build/src/planner.js +98 -0
- package/build/src/plugins/retry.d.ts +20 -0
- package/build/src/plugins/retry.js +66 -0
- package/build/src/reporters/dot.d.ts +15 -0
- package/build/src/reporters/dot.js +41 -0
- package/build/src/reporters/main.d.ts +4 -9
- package/build/src/reporters/main.js +37 -11
- package/build/src/reporters/ndjson.d.ts +15 -0
- package/build/src/reporters/ndjson.js +86 -0
- package/build/src/reporters/spec.d.ts +13 -0
- package/build/src/reporters/spec.js +152 -0
- package/build/src/types.d.ts +19 -23
- package/build/src/types.js +9 -14
- package/build/src/validator.d.ts +30 -0
- package/build/src/validator.js +85 -0
- package/build/tests/base_reporter.spec.d.ts +1 -0
- package/build/tests/base_reporter.spec.js +111 -0
- package/build/tests/cli_parser.spec.d.ts +1 -0
- package/build/tests/cli_parser.spec.js +265 -0
- package/build/tests/config_manager.spec.d.ts +1 -0
- package/build/tests/config_manager.spec.js +741 -0
- package/build/tests/core.spec.d.ts +1 -0
- package/build/tests/core.spec.js +31 -0
- package/build/tests/files_manager.spec.d.ts +1 -0
- package/build/tests/files_manager.spec.js +153 -0
- package/build/tests/planner.spec.d.ts +1 -0
- package/build/tests/planner.spec.js +510 -0
- package/build/tests/runner.spec.d.ts +1 -0
- package/build/tests/runner.spec.js +442 -0
- package/build/tests_helpers/main.d.ts +7 -0
- package/build/tests_helpers/main.js +34 -0
- package/package.json +2 -17
- package/build/chunk-7THDHQFT.js +0 -283
- package/build/chunk-HN4AVHWN.js +0 -17
- package/build/chunk-MCOW34SG.js +0 -269
- package/build/chunk-W5IABAQU.js +0 -502
- package/build/main-63126780.d.ts +0 -109
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { TestEndNode, SuiteEndNode, GroupEndNode, TestStartNode, RunnerSummary, RunnerEndNode, GroupStartNode, SuiteStartNode, RunnerStartNode, BaseReporterOptions } from '../types.js';
|
|
2
|
+
import { Emitter, Runner } from '../main.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base reporter to build custom reporters on top of
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseReporter {
|
|
7
|
+
#private;
|
|
8
|
+
runner?: Runner;
|
|
9
|
+
/**
|
|
10
|
+
* Path to the file for which the tests are getting executed
|
|
11
|
+
*/
|
|
12
|
+
currentFileName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Suite for which the tests are getting executed
|
|
15
|
+
*/
|
|
16
|
+
currentSuiteName?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Group for which the tests are getting executed
|
|
19
|
+
*/
|
|
20
|
+
currentGroupName?: string;
|
|
21
|
+
constructor(options?: BaseReporterOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Handlers to capture events
|
|
24
|
+
*/
|
|
25
|
+
protected onTestStart(_: TestStartNode): void;
|
|
26
|
+
protected onTestEnd(_: TestEndNode): void;
|
|
27
|
+
protected onGroupStart(_: GroupStartNode): void;
|
|
28
|
+
protected onGroupEnd(_: GroupEndNode): void;
|
|
29
|
+
protected onSuiteStart(_: SuiteStartNode): void;
|
|
30
|
+
protected onSuiteEnd(_: SuiteEndNode): void;
|
|
31
|
+
protected start(_: RunnerStartNode): Promise<void>;
|
|
32
|
+
protected end(_: RunnerEndNode): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Print tests summary
|
|
35
|
+
*/
|
|
36
|
+
protected printSummary(summary: RunnerSummary): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Invoked by the tests runner when tests are about to start
|
|
39
|
+
*/
|
|
40
|
+
boot(runner: Runner, emitter: Emitter): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
*/
|
|
9
|
+
import ms from 'ms';
|
|
10
|
+
import colors from '@poppinss/colors';
|
|
11
|
+
import { ErrorsPrinter } from '@japa/errors-printer';
|
|
12
|
+
const ansi = colors.ansi();
|
|
13
|
+
/**
|
|
14
|
+
* Base reporter to build custom reporters on top of
|
|
15
|
+
*/
|
|
16
|
+
export class BaseReporter {
|
|
17
|
+
#options;
|
|
18
|
+
runner;
|
|
19
|
+
/**
|
|
20
|
+
* Path to the file for which the tests are getting executed
|
|
21
|
+
*/
|
|
22
|
+
currentFileName;
|
|
23
|
+
/**
|
|
24
|
+
* Suite for which the tests are getting executed
|
|
25
|
+
*/
|
|
26
|
+
currentSuiteName;
|
|
27
|
+
/**
|
|
28
|
+
* Group for which the tests are getting executed
|
|
29
|
+
*/
|
|
30
|
+
currentGroupName;
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
this.#options = Object.assign({ stackLinesCount: 2 }, options);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pretty prints the aggregates
|
|
36
|
+
*/
|
|
37
|
+
#printAggregates(summary) {
|
|
38
|
+
const tests = [];
|
|
39
|
+
/**
|
|
40
|
+
* Set value for tests row
|
|
41
|
+
*/
|
|
42
|
+
if (summary.aggregates.passed) {
|
|
43
|
+
tests.push(ansi.green(`${summary.aggregates.passed} passed`));
|
|
44
|
+
}
|
|
45
|
+
if (summary.aggregates.failed) {
|
|
46
|
+
tests.push(ansi.red(`${summary.aggregates.failed} failed`));
|
|
47
|
+
}
|
|
48
|
+
if (summary.aggregates.todo) {
|
|
49
|
+
tests.push(ansi.cyan(`${summary.aggregates.todo} todo`));
|
|
50
|
+
}
|
|
51
|
+
if (summary.aggregates.skipped) {
|
|
52
|
+
tests.push(ansi.yellow(`${summary.aggregates.skipped} skipped`));
|
|
53
|
+
}
|
|
54
|
+
if (summary.aggregates.regression) {
|
|
55
|
+
tests.push(ansi.magenta(`${summary.aggregates.regression} regression`));
|
|
56
|
+
}
|
|
57
|
+
this.runner.summaryBuilder.use(() => {
|
|
58
|
+
return [
|
|
59
|
+
{
|
|
60
|
+
key: ansi.dim('Tests'),
|
|
61
|
+
value: `${tests.join(', ')} ${ansi.dim(`(${summary.aggregates.total})`)}`,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: ansi.dim('Time'),
|
|
65
|
+
value: ansi.dim(ms(summary.duration)),
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
});
|
|
69
|
+
console.log(this.runner.summaryBuilder.build().join('\n'));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Aggregates errors tree to a flat array
|
|
73
|
+
*/
|
|
74
|
+
#aggregateErrors(summary) {
|
|
75
|
+
const errorsList = [];
|
|
76
|
+
summary.failureTree.forEach((suite) => {
|
|
77
|
+
suite.errors.forEach((error) => errorsList.push({ title: suite.name, ...error }));
|
|
78
|
+
suite.children.forEach((testOrGroup) => {
|
|
79
|
+
/**
|
|
80
|
+
* Suite child is a test
|
|
81
|
+
*/
|
|
82
|
+
if (testOrGroup.type === 'test') {
|
|
83
|
+
testOrGroup.errors.forEach((error) => {
|
|
84
|
+
errorsList.push({ title: `${suite.name} / ${testOrGroup.title}`, ...error });
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Suite child is a group
|
|
90
|
+
*/
|
|
91
|
+
testOrGroup.errors.forEach((error) => {
|
|
92
|
+
errorsList.push({ title: testOrGroup.name, ...error });
|
|
93
|
+
});
|
|
94
|
+
testOrGroup.children.forEach((test) => {
|
|
95
|
+
test.errors.forEach((error) => {
|
|
96
|
+
errorsList.push({ title: `${testOrGroup.name} / ${test.title}`, ...error });
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
return errorsList;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Pretty print errors
|
|
105
|
+
*/
|
|
106
|
+
async #printErrors(summary) {
|
|
107
|
+
if (!summary.failureTree.length) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const errorPrinter = new ErrorsPrinter({
|
|
111
|
+
stackLinesCount: this.#options.stackLinesCount,
|
|
112
|
+
framesMaxLimit: this.#options.framesMaxLimit,
|
|
113
|
+
});
|
|
114
|
+
errorPrinter.printSectionHeader('ERRORS');
|
|
115
|
+
await errorPrinter.printErrors(this.#aggregateErrors(summary));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handlers to capture events
|
|
119
|
+
*/
|
|
120
|
+
onTestStart(_) { }
|
|
121
|
+
onTestEnd(_) { }
|
|
122
|
+
onGroupStart(_) { }
|
|
123
|
+
onGroupEnd(_) { }
|
|
124
|
+
onSuiteStart(_) { }
|
|
125
|
+
onSuiteEnd(_) { }
|
|
126
|
+
async start(_) { }
|
|
127
|
+
async end(_) { }
|
|
128
|
+
/**
|
|
129
|
+
* Print tests summary
|
|
130
|
+
*/
|
|
131
|
+
async printSummary(summary) {
|
|
132
|
+
await this.#printErrors(summary);
|
|
133
|
+
console.log('');
|
|
134
|
+
if (summary.aggregates.total === 0 && !summary.hasError) {
|
|
135
|
+
console.log(ansi.bgYellow().black(' NO TESTS EXECUTED '));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (summary.hasError) {
|
|
139
|
+
console.log(ansi.bgRed().black(' FAILED '));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
console.log(ansi.bgGreen().black(' PASSED '));
|
|
143
|
+
}
|
|
144
|
+
console.log('');
|
|
145
|
+
this.#printAggregates(summary);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Invoked by the tests runner when tests are about to start
|
|
149
|
+
*/
|
|
150
|
+
boot(runner, emitter) {
|
|
151
|
+
this.runner = runner;
|
|
152
|
+
emitter.on('test:start', (payload) => {
|
|
153
|
+
this.currentFileName = payload.meta.fileName;
|
|
154
|
+
this.onTestStart(payload);
|
|
155
|
+
});
|
|
156
|
+
emitter.on('test:end', (payload) => {
|
|
157
|
+
this.onTestEnd(payload);
|
|
158
|
+
});
|
|
159
|
+
emitter.on('group:start', (payload) => {
|
|
160
|
+
this.currentGroupName = payload.title;
|
|
161
|
+
this.currentFileName = payload.meta.fileName;
|
|
162
|
+
this.onGroupStart(payload);
|
|
163
|
+
});
|
|
164
|
+
emitter.on('group:end', (payload) => {
|
|
165
|
+
this.currentGroupName = undefined;
|
|
166
|
+
this.onGroupEnd(payload);
|
|
167
|
+
});
|
|
168
|
+
emitter.on('suite:start', (payload) => {
|
|
169
|
+
this.currentSuiteName = payload.name;
|
|
170
|
+
this.onSuiteStart(payload);
|
|
171
|
+
});
|
|
172
|
+
emitter.on('suite:end', (payload) => {
|
|
173
|
+
this.currentSuiteName = undefined;
|
|
174
|
+
this.onSuiteEnd(payload);
|
|
175
|
+
});
|
|
176
|
+
emitter.on('runner:start', async (payload) => {
|
|
177
|
+
await this.start(payload);
|
|
178
|
+
});
|
|
179
|
+
emitter.on('runner:end', async (payload) => {
|
|
180
|
+
await this.end(payload);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CLIArgs } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* CLI Parser is used to parse the commandline argument
|
|
4
|
+
*/
|
|
5
|
+
export declare class CliParser {
|
|
6
|
+
/**
|
|
7
|
+
* Parses command-line arguments
|
|
8
|
+
*/
|
|
9
|
+
parse(argv: string[]): CLIArgs;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the help string
|
|
12
|
+
*/
|
|
13
|
+
getHelp(): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
*/
|
|
9
|
+
// @ts-ignore-error
|
|
10
|
+
import getopts from 'getopts';
|
|
11
|
+
import colors from '@poppinss/colors';
|
|
12
|
+
const ansi = colors.ansi();
|
|
13
|
+
/**
|
|
14
|
+
* Known commandline options. The user can still define additional flags and they
|
|
15
|
+
* will be parsed aswell, but without any normalization
|
|
16
|
+
*/
|
|
17
|
+
const OPTIONS = {
|
|
18
|
+
string: ['tests', 'groups', 'tags', 'files', 'timeout', 'retries', 'reporter', 'failed'],
|
|
19
|
+
boolean: ['help', 'matchAll', 'failed'],
|
|
20
|
+
alias: {
|
|
21
|
+
forceExit: 'force-exit',
|
|
22
|
+
matchAll: 'match-all',
|
|
23
|
+
help: 'h',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Help string to display when the `--help flag is used`
|
|
28
|
+
*/
|
|
29
|
+
const GET_HELP = () => `
|
|
30
|
+
${ansi.yellow('@japa/runner v2.3.0')}
|
|
31
|
+
|
|
32
|
+
${ansi.green('--tests')} ${ansi.dim('Filter tests by the test title')}
|
|
33
|
+
${ansi.green('--groups')} ${ansi.dim('Filter tests by the group title')}
|
|
34
|
+
${ansi.green('--tags')} ${ansi.dim('Filter tests by tags')}
|
|
35
|
+
${ansi.green('--files')} ${ansi.dim('Filter tests by the file name')}
|
|
36
|
+
${ansi.green('--force-exit')} ${ansi.dim('Forcefully exit the process')}
|
|
37
|
+
${ansi.green('--timeout')} ${ansi.dim('Define default timeout for all tests')}
|
|
38
|
+
${ansi.green('--retries')} ${ansi.dim('Define default retries for all tests')}
|
|
39
|
+
${ansi.green('--reporter')} ${ansi.dim('Activate one or more test reporters')}
|
|
40
|
+
${ansi.green('--failed')} ${ansi.dim('Run tests failed during the last run')}
|
|
41
|
+
${ansi.green('-h, --help')} ${ansi.dim('View help')}
|
|
42
|
+
|
|
43
|
+
${ansi.yellow('Examples:')}
|
|
44
|
+
${ansi.dim('node bin/test.js --tags="@github"')}
|
|
45
|
+
${ansi.dim('node bin/test.js --tags="~@github"')}
|
|
46
|
+
${ansi.dim('node bin/test.js --tags="@github,@slow,@integration" --match-all')}
|
|
47
|
+
${ansi.dim('node bin/test.js --force-exit')}
|
|
48
|
+
${ansi.dim('node bin/test.js --files="user"')}
|
|
49
|
+
${ansi.dim('node bin/test.js --files="functional/user"')}
|
|
50
|
+
${ansi.dim('node bin/test.js --files="unit/user"')}
|
|
51
|
+
|
|
52
|
+
${ansi.yellow('Notes:')}
|
|
53
|
+
- When groups and tests filters are applied together. We will first filter the
|
|
54
|
+
tests by group title and then apply the tests title filter.
|
|
55
|
+
- The timeout defined on test object takes precedence over the ${ansi.green('--timeout')} flag.
|
|
56
|
+
- The retries defined on test object takes precedence over the ${ansi.green('--retries')} flag.
|
|
57
|
+
- The ${ansi.green('--files')} flag checks for the file names ending with the filter substring.
|
|
58
|
+
`;
|
|
59
|
+
/**
|
|
60
|
+
* CLI Parser is used to parse the commandline argument
|
|
61
|
+
*/
|
|
62
|
+
export class CliParser {
|
|
63
|
+
/**
|
|
64
|
+
* Parses command-line arguments
|
|
65
|
+
*/
|
|
66
|
+
parse(argv) {
|
|
67
|
+
return getopts(argv, OPTIONS);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns the help string
|
|
71
|
+
*/
|
|
72
|
+
getHelp() {
|
|
73
|
+
return GET_HELP();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CLIArgs, Config, NormalizedConfig } from './types.js';
|
|
2
|
+
export declare const NOOP: () => void;
|
|
3
|
+
/**
|
|
4
|
+
* Config manager is used to hydrate the configuration by merging
|
|
5
|
+
* the defaults, user defined config and the command line
|
|
6
|
+
* flags.
|
|
7
|
+
*
|
|
8
|
+
* The command line flags have the upmost priority
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConfigManager {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(config: Config, cliArgs: CLIArgs);
|
|
13
|
+
/**
|
|
14
|
+
* Hydrates the config with user defined options and the
|
|
15
|
+
* command-line flags.
|
|
16
|
+
*/
|
|
17
|
+
hydrate(): NormalizedConfig;
|
|
18
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
*/
|
|
9
|
+
import debug from './debug.js';
|
|
10
|
+
import { Refiner } from '../modules/core/main.js';
|
|
11
|
+
import { dot, ndjson, spec } from './reporters/main.js';
|
|
12
|
+
export const NOOP = () => { };
|
|
13
|
+
/**
|
|
14
|
+
* Defaults to use for configuration
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULTS = {
|
|
17
|
+
files: [],
|
|
18
|
+
timeout: 2000,
|
|
19
|
+
retries: 0,
|
|
20
|
+
forceExit: false,
|
|
21
|
+
plugins: [],
|
|
22
|
+
reporters: {
|
|
23
|
+
activated: ['spec'],
|
|
24
|
+
list: [spec(), ndjson(), dot()],
|
|
25
|
+
},
|
|
26
|
+
importer: (filePath) => import(filePath.href),
|
|
27
|
+
configureSuite: () => { },
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Config manager is used to hydrate the configuration by merging
|
|
31
|
+
* the defaults, user defined config and the command line
|
|
32
|
+
* flags.
|
|
33
|
+
*
|
|
34
|
+
* The command line flags have the upmost priority
|
|
35
|
+
*/
|
|
36
|
+
export class ConfigManager {
|
|
37
|
+
#config;
|
|
38
|
+
#cliArgs;
|
|
39
|
+
constructor(config, cliArgs) {
|
|
40
|
+
this.#config = config;
|
|
41
|
+
this.#cliArgs = cliArgs;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Processes a CLI argument and converts it to an
|
|
45
|
+
* array of strings
|
|
46
|
+
*/
|
|
47
|
+
#processAsArray(value) {
|
|
48
|
+
return Array.isArray(value) ? value : value.split(',').map((item) => item.trim());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns a copy of filters based upon the CLI
|
|
52
|
+
* arguments.
|
|
53
|
+
*/
|
|
54
|
+
#getCLIFilters() {
|
|
55
|
+
const filters = {};
|
|
56
|
+
if (this.#cliArgs.tags) {
|
|
57
|
+
filters.tags = this.#processAsArray(this.#cliArgs.tags);
|
|
58
|
+
}
|
|
59
|
+
if (this.#cliArgs.tests) {
|
|
60
|
+
filters.tests = this.#processAsArray(this.#cliArgs.tests);
|
|
61
|
+
}
|
|
62
|
+
if (this.#cliArgs.files) {
|
|
63
|
+
filters.files = this.#processAsArray(this.#cliArgs.files);
|
|
64
|
+
}
|
|
65
|
+
if (this.#cliArgs.groups) {
|
|
66
|
+
filters.groups = this.#processAsArray(this.#cliArgs.groups);
|
|
67
|
+
}
|
|
68
|
+
if (this.#cliArgs._ && this.#cliArgs._.length) {
|
|
69
|
+
filters.suites = this.#processAsArray(this.#cliArgs._);
|
|
70
|
+
}
|
|
71
|
+
return filters;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the timeout from the CLI args
|
|
75
|
+
*/
|
|
76
|
+
#getCLITimeout() {
|
|
77
|
+
if (this.#cliArgs.timeout) {
|
|
78
|
+
const value = Number(this.#cliArgs.timeout);
|
|
79
|
+
if (!Number.isNaN(value)) {
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns the retries from the CLI args
|
|
86
|
+
*/
|
|
87
|
+
#getCLIRetries() {
|
|
88
|
+
if (this.#cliArgs.retries) {
|
|
89
|
+
const value = Number(this.#cliArgs.retries);
|
|
90
|
+
if (!Number.isNaN(value)) {
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the forceExit property from the CLI args
|
|
97
|
+
*/
|
|
98
|
+
#getCLIForceExit() {
|
|
99
|
+
if (this.#cliArgs.forceExit) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns reporters selected using the commandline
|
|
105
|
+
* --reporter flag
|
|
106
|
+
*/
|
|
107
|
+
#getCLIReporters() {
|
|
108
|
+
if (this.#cliArgs.reporter) {
|
|
109
|
+
return this.#processAsArray(this.#cliArgs.reporter);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Hydrates the config with user defined options and the
|
|
114
|
+
* command-line flags.
|
|
115
|
+
*/
|
|
116
|
+
hydrate() {
|
|
117
|
+
const cliFilters = this.#getCLIFilters();
|
|
118
|
+
const cliRetries = this.#getCLIRetries();
|
|
119
|
+
const cliTimeout = this.#getCLITimeout();
|
|
120
|
+
const cliReporters = this.#getCLIReporters();
|
|
121
|
+
const cliForceExit = this.#getCLIForceExit();
|
|
122
|
+
debug('filters applied using CLI flags %O', cliFilters);
|
|
123
|
+
const baseConfig = {
|
|
124
|
+
cwd: this.#config.cwd ?? process.cwd(),
|
|
125
|
+
filters: Object.assign({}, this.#config.filters ?? {}, cliFilters),
|
|
126
|
+
importer: this.#config.importer ?? DEFAULTS.importer,
|
|
127
|
+
refiner: this.#config.refiner ?? new Refiner(),
|
|
128
|
+
retries: cliRetries ?? this.#config.retries ?? DEFAULTS.retries,
|
|
129
|
+
timeout: cliTimeout ?? this.#config.timeout ?? DEFAULTS.timeout,
|
|
130
|
+
plugins: this.#config.plugins ?? DEFAULTS.plugins,
|
|
131
|
+
forceExit: cliForceExit ?? this.#config.forceExit ?? DEFAULTS.forceExit,
|
|
132
|
+
reporters: this.#config.reporters
|
|
133
|
+
? {
|
|
134
|
+
activated: this.#config.reporters.activated,
|
|
135
|
+
list: this.#config.reporters.list || DEFAULTS.reporters.list,
|
|
136
|
+
}
|
|
137
|
+
: DEFAULTS.reporters,
|
|
138
|
+
configureSuite: this.#config.configureSuite ?? DEFAULTS.configureSuite,
|
|
139
|
+
setup: this.#config.setup || [],
|
|
140
|
+
teardown: this.#config.teardown || [],
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Overwrite activated reporters when defined using CLI
|
|
144
|
+
* flag
|
|
145
|
+
*/
|
|
146
|
+
if (cliReporters) {
|
|
147
|
+
baseConfig.reporters.activated = cliReporters;
|
|
148
|
+
}
|
|
149
|
+
if ('files' in this.#config) {
|
|
150
|
+
return {
|
|
151
|
+
files: this.#config.files,
|
|
152
|
+
...baseConfig,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
suites: this.#config.suites.map((suite) => {
|
|
157
|
+
return {
|
|
158
|
+
name: suite.name,
|
|
159
|
+
files: suite.files,
|
|
160
|
+
timeout: cliTimeout ?? suite.timeout ?? baseConfig.timeout,
|
|
161
|
+
retries: cliRetries ?? suite.retries ?? baseConfig.retries,
|
|
162
|
+
configure: suite.configure || NOOP,
|
|
163
|
+
};
|
|
164
|
+
}),
|
|
165
|
+
...baseConfig,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Emitter, Group, Refiner, Suite, Test } from '../modules/core/main.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new instance of the Test
|
|
4
|
+
*/
|
|
5
|
+
export declare function createTest(title: string, emitter: Emitter, refiner: Refiner, options: {
|
|
6
|
+
group?: Group;
|
|
7
|
+
suite?: Suite;
|
|
8
|
+
file?: string;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
retries?: number;
|
|
11
|
+
}): Test<undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of the Group
|
|
14
|
+
*/
|
|
15
|
+
export declare function createTestGroup(title: string, emitter: Emitter, refiner: Refiner, options: {
|
|
16
|
+
group?: Group;
|
|
17
|
+
suite?: Suite;
|
|
18
|
+
file?: string;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
retries?: number;
|
|
21
|
+
}): Group;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
*/
|
|
9
|
+
import { Group, Test, TestContext } from '../modules/core/main.js';
|
|
10
|
+
/**
|
|
11
|
+
* Function to create the test context for the test
|
|
12
|
+
*/
|
|
13
|
+
const contextBuilder = (testInstance) => new TestContext(testInstance);
|
|
14
|
+
/**
|
|
15
|
+
* Create a new instance of the Test
|
|
16
|
+
*/
|
|
17
|
+
export function createTest(title, emitter, refiner, options) {
|
|
18
|
+
const testInstance = new Test(title, contextBuilder, emitter, refiner, options.group);
|
|
19
|
+
testInstance.options.meta.suite = options.suite;
|
|
20
|
+
testInstance.options.meta.group = options.group;
|
|
21
|
+
testInstance.options.meta.fileName = options.file;
|
|
22
|
+
if (options.timeout !== undefined) {
|
|
23
|
+
testInstance.timeout(options.timeout);
|
|
24
|
+
}
|
|
25
|
+
if (options.retries !== undefined) {
|
|
26
|
+
testInstance.retry(options.retries);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Register test as a child either with the group or the suite
|
|
30
|
+
*/
|
|
31
|
+
if (options.group) {
|
|
32
|
+
options.group.add(testInstance);
|
|
33
|
+
}
|
|
34
|
+
else if (options.suite) {
|
|
35
|
+
options.suite.add(testInstance);
|
|
36
|
+
}
|
|
37
|
+
return testInstance;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a new instance of the Group
|
|
41
|
+
*/
|
|
42
|
+
export function createTestGroup(title, emitter, refiner, options) {
|
|
43
|
+
if (options.group) {
|
|
44
|
+
throw new Error('Nested groups are not supported by Japa');
|
|
45
|
+
}
|
|
46
|
+
const group = new Group(title, emitter, refiner);
|
|
47
|
+
group.options.meta.suite = options.suite;
|
|
48
|
+
group.options.meta.fileName = options.file;
|
|
49
|
+
if (options.suite) {
|
|
50
|
+
options.suite.add(group);
|
|
51
|
+
}
|
|
52
|
+
return group;
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles uncaught exceptions and prints them to the
|
|
3
|
+
* console
|
|
4
|
+
*/
|
|
5
|
+
export declare class ExceptionsManager {
|
|
6
|
+
#private;
|
|
7
|
+
hasErrors: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Monitors unhandled exceptions and rejections. The exceptions
|
|
10
|
+
* are stacked in a buffer, so that we do not clutter the
|
|
11
|
+
* tests output and once the tests are over, we will
|
|
12
|
+
* print them to the console.
|
|
13
|
+
*
|
|
14
|
+
* In case the tests are completed, we will print errors as they
|
|
15
|
+
* happen.
|
|
16
|
+
*/
|
|
17
|
+
monitor(): void;
|
|
18
|
+
flow(): Promise<void>;
|
|
19
|
+
}
|