@japa/runner 3.0.3 → 3.0.5

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.
Files changed (38) hide show
  1. package/build/chunk-52OY4QRJ.js +284 -0
  2. package/build/chunk-52OY4QRJ.js.map +1 -0
  3. package/build/chunk-CXTCA2MO.js +503 -0
  4. package/build/chunk-CXTCA2MO.js.map +1 -0
  5. package/build/chunk-MWYEWO7K.js +18 -0
  6. package/build/chunk-MWYEWO7K.js.map +1 -0
  7. package/build/chunk-PKOB3ULJ.js +270 -0
  8. package/build/chunk-PKOB3ULJ.js.map +1 -0
  9. package/build/factories/main.js +214 -29
  10. package/build/factories/main.js.map +1 -0
  11. package/build/index.js +243 -202
  12. package/build/index.js.map +1 -0
  13. package/build/modules/core/main.d.ts +0 -1
  14. package/build/modules/core/main.js +22 -121
  15. package/build/modules/core/main.js.map +1 -0
  16. package/build/src/reporters/main.js +12 -37
  17. package/build/src/reporters/main.js.map +1 -0
  18. package/build/src/types.js +15 -9
  19. package/build/src/types.js.map +1 -0
  20. package/package.json +32 -16
  21. package/build/factories/create_diverse_tests.js +0 -106
  22. package/build/factories/runner.js +0 -93
  23. package/build/modules/core/reporters/base.js +0 -183
  24. package/build/modules/core/types.js +0 -9
  25. package/build/src/cli_parser.js +0 -75
  26. package/build/src/config_manager.js +0 -168
  27. package/build/src/create_test.js +0 -53
  28. package/build/src/debug.js +0 -10
  29. package/build/src/exceptions_manager.js +0 -85
  30. package/build/src/files_manager.js +0 -57
  31. package/build/src/helpers.js +0 -34
  32. package/build/src/hooks.js +0 -46
  33. package/build/src/planner.js +0 -98
  34. package/build/src/plugins/retry.js +0 -74
  35. package/build/src/reporters/dot.js +0 -41
  36. package/build/src/reporters/ndjson.js +0 -86
  37. package/build/src/reporters/spec.js +0 -152
  38. package/build/src/validator.js +0 -85
@@ -1,38 +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
- */
9
- import { DotReporter } from './dot.js';
10
- import { SpecReporter } from './spec.js';
11
- import { NdJSONReporter } from './ndjson.js';
12
- /**
13
- * Create an instance of the spec reporter
14
- */
15
- export const spec = (options) => {
16
- return {
17
- name: 'spec',
18
- handler: (...args) => new SpecReporter(options).boot(...args),
19
- };
20
- };
21
- /**
22
- * Create an instance of the dot reporter
23
- */
24
- export const dot = (options) => {
25
- return {
26
- name: 'dot',
27
- handler: (...args) => new DotReporter(options).boot(...args),
28
- };
29
- };
30
- /**
31
- * Create an instance of the ndjson reporter
32
- */
33
- export const ndjson = (options) => {
34
- return {
35
- name: 'ndjson',
36
- handler: (...args) => new NdJSONReporter(options).boot(...args),
37
- };
1
+ import {
2
+ dot,
3
+ ndjson,
4
+ spec
5
+ } from "../../chunk-52OY4QRJ.js";
6
+ import "../../chunk-PKOB3ULJ.js";
7
+ import "../../chunk-MWYEWO7K.js";
8
+ export {
9
+ dot,
10
+ ndjson,
11
+ spec
38
12
  };
13
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,9 +1,15 @@
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
- export * from '../modules/core/types.js';
1
+ import {
2
+ __reExport
3
+ } from "../chunk-MWYEWO7K.js";
4
+
5
+ // src/types.ts
6
+ var types_exports2 = {};
7
+
8
+ // modules/core/types.ts
9
+ var types_exports = {};
10
+ __reExport(types_exports, types_star);
11
+ import * as types_star from "@japa/core/types";
12
+
13
+ // src/types.ts
14
+ __reExport(types_exports2, types_exports);
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types.ts","../../modules/core/types.ts"],"sourcesContent":["/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { HookHandler } from '@poppinss/hooks/types'\n\nimport type { Emitter, Refiner, Runner, Suite } from '../modules/core/main.js'\nimport type { FilteringOptions, NamedReporterContract } from '../modules/core/types.js'\n\nexport * from '../modules/core/types.js'\n\n/**\n * Global setup hook\n */\nexport type SetupHookState = [[runner: Runner], [error: Error | null, runner: Runner]]\nexport type SetupHookHandler = HookHandler<SetupHookState[0], SetupHookState[1]>\n\n/**\n * Global teardown hook\n */\nexport type TeardownHookState = [[runner: Runner], [error: Error | null, runner: Runner]]\nexport type TeardownHookHandler = HookHandler<TeardownHookState[0], TeardownHookState[1]>\n\n/**\n * Global set of available hooks\n */\nexport type HooksEvents = {\n setup: SetupHookState\n teardown: TeardownHookState\n}\n\n/**\n * Parsed command-line arguments\n */\nexport type CLIArgs = {\n _?: string[]\n tags?: string | string[]\n files?: string | string[]\n tests?: string | string[]\n groups?: string | string[]\n timeout?: string\n retries?: string\n reporters?: string | string[]\n forceExit?: boolean\n failed?: boolean\n help?: boolean\n matchAll?: boolean\n} & Record<string, string | string[] | boolean>\n\n/**\n * Set of filters you can apply to run only specific tests\n */\nexport type Filters = FilteringOptions & {\n files?: string[]\n suites?: string[]\n}\n\n/**\n * Plugin function receives an instance of the runner,\n * emitter, config and the hooks\n */\nexport type PluginFn = (japa: {\n config: NormalizedConfig\n cliArgs: CLIArgs\n runner: Runner\n emitter: Emitter\n}) => void | Promise<void>\n\n/**\n * Base configuration options\n */\nexport type BaseConfig = {\n /**\n * Current working directory. It is required to search for\n * the test files\n */\n cwd?: string\n\n /**\n * The timeout to apply on all the tests, unless overwritten explicitly\n */\n timeout?: number\n\n /**\n * The retries to apply on all the tests, unless overwritten explicitly\n */\n retries?: number\n\n /**\n * Test filters to apply\n */\n filters?: Filters\n\n /**\n * A hook to configure suites. The callback will be called for each\n * suite before it gets executed.\n */\n configureSuite?: (suite: Suite) => void\n\n /**\n * A collection of registered reporters. Reporters are not activated by\n * default. Either you have to activate them using the commandline,\n * or using the `activated` property.\n */\n reporters?: {\n activated: string[]\n list?: NamedReporterContract[]\n }\n\n /**\n * A collection of registered plugins\n */\n plugins?: PluginFn[]\n\n /**\n * A custom implementation to import test files.\n */\n importer?: (filePath: URL) => void | Promise<void>\n\n /**\n * Overwrite tests refiner. Check documentation for refiner\n * usage\n */\n refiner?: Refiner\n\n /**\n * Enable/disable force exiting.\n */\n forceExit?: boolean\n\n /**\n * Global hooks to execute before importing\n * the test files\n */\n setup?: SetupHookHandler[]\n\n /**\n * Global hooks to execute on teardown\n */\n teardown?: TeardownHookHandler[]\n}\n\n/**\n * A collection of test files defined as a glob or a callback\n * function that returns an array of URLs\n */\nexport type TestFiles = string | string[] | (() => URL[] | Promise<URL[]>)\n\n/**\n * A test suite to register tests under a named suite\n */\nexport type TestSuite = {\n /**\n * A unique name for the suite\n */\n name: string\n\n /**\n * Collection of files associated with the suite. Files should be\n * defined as a glob or a callback function that returns an array of URLs\n */\n files: TestFiles\n\n /**\n * A callback functon to configure the suite. The callback is invoked only\n * when the runner is going to run the tests for the given suite.\n */\n configure?: (suite: Suite) => void\n\n /**\n * The timeout to apply on all the tests in this suite, unless overwritten explicitly\n */\n timeout?: number\n\n /**\n * The retries to apply on all the tests in this suite, unless overwritten explicitly\n */\n retries?: number\n}\n\n/**\n * BaseConfig after normalized by the config manager\n */\nexport type NormalizedBaseConfig = Required<Omit<BaseConfig, 'reporters'>> & {\n reporters: {\n activated: string[]\n list: NamedReporterContract[]\n }\n}\n\n/**\n * Configuration options\n */\nexport type Config = BaseConfig &\n (\n | {\n files: TestFiles\n }\n | {\n suites: TestSuite[]\n }\n )\n\n/**\n * Config after normalized by the config manager\n */\nexport type NormalizedConfig = NormalizedBaseConfig &\n (\n | {\n files: TestFiles\n }\n | {\n suites: Required<TestSuite>[]\n }\n )\n","/*\n * @japa/runner\n *\n * (c) Japa\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * from '@japa/core/types'\n\nexport type BaseReporterOptions = {\n stackLinesCount?: number\n framesMaxLimit?: number\n}\n"],"mappings":";;;;;AAAA,IAAAA,iBAAA;;;ACAA;AASA;AAAA,4BAAc;;;ADKd,WAAAC,gBAAc;","names":["types_exports","types_exports"]}
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@japa/runner",
3
3
  "description": "Runner for Japa testing framework",
4
- "version": "3.0.3",
4
+ "version": "3.0.5",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
8
8
  "main": "build/index.js",
9
9
  "type": "module",
10
10
  "files": [
11
- "build/factories",
12
- "build/modules",
13
- "build/src",
14
- "build/index.d.ts",
15
- "build/index.js"
11
+ "build",
12
+ "!build/examples",
13
+ "!build/tests",
14
+ "!build/tests_helpers"
16
15
  ],
17
16
  "exports": {
18
17
  ".": "./build/index.js",
@@ -27,7 +26,8 @@
27
26
  "quick:test": "glob -c \"node --enable-source-maps --loader=ts-node/esm --test-reporter=spec --test\" \"tests/*.spec.ts\"",
28
27
  "clean": "del-cli build",
29
28
  "typecheck": "tsc --noEmit",
30
- "compile": "npm run lint && npm run clean && tsc",
29
+ "precompile": "npm run lint && npm run clean",
30
+ "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
31
31
  "build": "npm run compile",
32
32
  "release": "np",
33
33
  "prepublishOnly": "npm run build",
@@ -40,33 +40,34 @@
40
40
  "@adonisjs/eslint-config": "^1.1.8",
41
41
  "@adonisjs/prettier-config": "^1.1.8",
42
42
  "@adonisjs/tsconfig": "^1.1.8",
43
- "@commitlint/cli": "^17.7.2",
44
- "@commitlint/config-conventional": "^17.7.0",
45
- "@swc/core": "1.3.82",
43
+ "@commitlint/cli": "^18.2.0",
44
+ "@commitlint/config-conventional": "^18.1.0",
45
+ "@swc/core": "^1.3.96",
46
46
  "@types/chai": "^4.3.9",
47
47
  "@types/chai-subset": "^1.3.4",
48
48
  "@types/find-cache-dir": "^5.0.0",
49
49
  "@types/ms": "^0.7.33",
50
- "@types/node": "^20.8.7",
50
+ "@types/node": "^20.8.10",
51
51
  "c8": "^8.0.1",
52
52
  "chai": "^4.3.10",
53
53
  "chai-subset": "^1.6.0",
54
54
  "cross-env": "^7.0.3",
55
55
  "del-cli": "^5.1.0",
56
- "eslint": "^8.51.0",
56
+ "eslint": "^8.53.0",
57
57
  "github-label-sync": "^2.3.1",
58
58
  "glob": "^10.3.10",
59
59
  "husky": "^8.0.3",
60
60
  "np": "^8.0.4",
61
61
  "prettier": "^3.0.3",
62
62
  "ts-node": "^10.9.1",
63
+ "tsup": "^7.2.0",
63
64
  "typescript": "^5.2.2"
64
65
  },
65
66
  "dependencies": {
66
- "@japa/core": "^8.1.0",
67
- "@japa/errors-printer": "^3.0.0",
68
- "@poppinss/colors": "^4.1.0",
69
- "@poppinss/hooks": "^7.2.0",
67
+ "@japa/core": "^8.1.1",
68
+ "@japa/errors-printer": "^3.0.1",
69
+ "@poppinss/colors": "^4.1.1",
70
+ "@poppinss/hooks": "^7.2.1",
70
71
  "fast-glob": "^3.3.1",
71
72
  "find-cache-dir": "^5.0.0",
72
73
  "getopts": "^2.3.0",
@@ -123,5 +124,20 @@
123
124
  "modules/core/**",
124
125
  "src/reporters/**"
125
126
  ]
127
+ },
128
+ "tsup": {
129
+ "entry": [
130
+ "./index.ts",
131
+ "./src/types.ts",
132
+ "./src/reporters/main.ts",
133
+ "./factories/main.ts",
134
+ "./modules/core/main.ts"
135
+ ],
136
+ "outDir": "./build",
137
+ "clean": true,
138
+ "format": "esm",
139
+ "dts": false,
140
+ "sourcemap": true,
141
+ "target": "esnext"
126
142
  }
127
143
  }
@@ -1,106 +0,0 @@
1
- import assert from 'node:assert';
2
- import { Suite } from '../modules/core/main.js';
3
- import { createTest, createTestGroup } from '../src/create_test.js';
4
- /**
5
- * Creates a unit tests suite with bunch of dummy tests
6
- * reproducing different tests behavior
7
- */
8
- function createUnitTestsSuite(emitter, refiner, file) {
9
- const suite = new Suite('unit', emitter, refiner);
10
- const group = createTestGroup('Maths#add', emitter, refiner, {
11
- suite,
12
- file,
13
- });
14
- createTest('A top level test inside a suite', emitter, refiner, {
15
- suite,
16
- file,
17
- }).run(() => { });
18
- createTest('add two numbers', emitter, refiner, { group, file }).run(() => {
19
- assert.equal(2 + 2, 4);
20
- });
21
- createTest('add three numbers', emitter, refiner, {
22
- group,
23
- file,
24
- }).run(() => {
25
- assert.equal(2 + 2 + 2, 6);
26
- });
27
- createTest('add group of numbers', emitter, refiner, { group, file });
28
- createTest('use math.js lib', emitter, refiner, { group, file }).skip(true, 'Library work pending');
29
- createTest('add multiple numbers', emitter, refiner, {
30
- file,
31
- group,
32
- }).run(() => {
33
- assert.equal(2 + 2 + 2 + 2, 6);
34
- });
35
- createTest('add floating numbers', emitter, refiner, { group, file })
36
- .run(() => {
37
- assert.equal(2 + 2.2 + 2.1, 6);
38
- })
39
- .fails('Have to add support for floating numbers');
40
- createTest('A test with an error that is not an AssertionError', emitter, refiner, {
41
- group,
42
- file,
43
- }).run(() => {
44
- throw new Error('This is an error');
45
- });
46
- return suite;
47
- }
48
- /**
49
- * Creates a unit functional suite with bunch of dummy tests
50
- * reproducing different tests behavior
51
- */
52
- function createFunctionalTestsSuite(emitter, refiner, file) {
53
- const suite = new Suite('functional', emitter, refiner);
54
- const group = createTestGroup('Users/store', emitter, refiner, {
55
- suite,
56
- file: file,
57
- });
58
- createTest('Validate user data', emitter, refiner, {
59
- group,
60
- file: file,
61
- }).run(() => { });
62
- createTest('Disallow duplicate emails', emitter, refiner, {
63
- group,
64
- file: file,
65
- }).run(() => { });
66
- createTest('Disallow duplicate emails across tenants', emitter, refiner, {
67
- group,
68
- file: file,
69
- }).run(() => {
70
- const users = ['', ''];
71
- assert.equal(users.length, 1);
72
- });
73
- createTest('Normalize email before persisting it', emitter, refiner, {
74
- group,
75
- file: file,
76
- }).skip(true, 'Have to build a normalizer');
77
- createTest('Send email verification mail', emitter, refiner, {
78
- group,
79
- file: file,
80
- });
81
- const usersListGroup = createTestGroup('Users/list', emitter, refiner, {
82
- suite,
83
- file: file,
84
- });
85
- usersListGroup.setup(() => {
86
- throw new Error('Unable to cleanup database');
87
- });
88
- createTest('A test that will never because the group hooks fails', emitter, refiner, {
89
- group: usersListGroup,
90
- });
91
- createTest('A top level test inside functional suite', emitter, refiner, {
92
- suite,
93
- file: file,
94
- }).run(() => { });
95
- return suite;
96
- }
97
- /**
98
- * Returns an array of suites with dummy tests reproducting
99
- * different test behavior
100
- */
101
- export function createDiverseTests(emitter, refiner, file) {
102
- return [
103
- createUnitTestsSuite(emitter, refiner, file),
104
- createFunctionalTestsSuite(emitter, refiner, file),
105
- ];
106
- }
@@ -1,93 +0,0 @@
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 { fileURLToPath } from 'node:url';
10
- import { Planner } from '../src/planner.js';
11
- import { GlobalHooks } from '../src/hooks.js';
12
- import { CliParser } from '../src/cli_parser.js';
13
- import { createTest } from '../src/create_test.js';
14
- import { ConfigManager } from '../src/config_manager.js';
15
- import { Suite, Runner, Emitter } from '../modules/core/main.js';
16
- /**
17
- * Runner factory exposes the API to run dummy suites, groups and tests.
18
- * You might want to use the factory for testing reporters and
19
- * plugins usage
20
- */
21
- export class RunnerFactory {
22
- #emitter = new Emitter();
23
- #config;
24
- #cliArgs;
25
- #file = fileURLToPath(import.meta.url);
26
- get #refiner() {
27
- return this.#config.refiner;
28
- }
29
- /**
30
- * Registers plugins
31
- */
32
- async #registerPlugins(runner) {
33
- for (let plugin of this.#config.plugins) {
34
- await plugin({
35
- config: this.#config,
36
- runner,
37
- emitter: this.#emitter,
38
- cliArgs: this.#cliArgs,
39
- });
40
- }
41
- }
42
- /**
43
- * Configure runner
44
- */
45
- configure(config, argv) {
46
- this.#cliArgs = new CliParser().parse(argv || []);
47
- this.#config = new ConfigManager(config, this.#cliArgs).hydrate();
48
- return this;
49
- }
50
- /**
51
- * Define a custom emitter instance to use
52
- */
53
- useEmitter(emitter) {
54
- this.#emitter = emitter;
55
- return this;
56
- }
57
- /**
58
- * Run a test using the runner
59
- */
60
- async runTest(title, callback) {
61
- return this.runSuites((emitter, refiner, file) => {
62
- const defaultSuite = new Suite('default', emitter, refiner);
63
- createTest(title, emitter, refiner, {
64
- suite: defaultSuite,
65
- file: file,
66
- }).run(callback);
67
- return [defaultSuite];
68
- });
69
- }
70
- /**
71
- * Run dummy tests. You might use
72
- */
73
- async runSuites(suites) {
74
- const runner = new Runner(this.#emitter);
75
- await this.#registerPlugins(runner);
76
- const { config, reporters, refinerFilters } = await new Planner(this.#config).plan();
77
- const globalHooks = new GlobalHooks();
78
- globalHooks.apply(config);
79
- reporters.forEach((reporter) => {
80
- runner.registerReporter(reporter);
81
- });
82
- refinerFilters.forEach((filter) => {
83
- config.refiner.add(filter.layer, filter.filters);
84
- });
85
- suites(this.#emitter, this.#refiner, this.#file).forEach((suite) => runner.add(suite));
86
- await globalHooks.setup(runner);
87
- await runner.start();
88
- await runner.exec();
89
- await runner.end();
90
- await globalHooks.teardown(null, runner);
91
- return runner.getSummary();
92
- }
93
- }
@@ -1,183 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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
- export * from '@japa/core/types';
@@ -1,75 +0,0 @@
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', 'reporters', '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('--reporters')} ${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
- }