@japa/runner 3.0.0-7 → 3.0.0-8

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 (50) hide show
  1. package/build/chunk-7THDHQFT.js +283 -0
  2. package/build/chunk-HN4AVHWN.js +17 -0
  3. package/build/chunk-MCOW34SG.js +269 -0
  4. package/build/chunk-W5IABAQU.js +502 -0
  5. package/build/factories/main.d.ts +42 -2
  6. package/build/factories/main.js +209 -13
  7. package/build/index.d.ts +14 -9
  8. package/build/index.js +237 -202
  9. package/build/main-63126780.d.ts +109 -0
  10. package/build/modules/core/main.d.ts +3 -62
  11. package/build/modules/core/main.js +21 -121
  12. package/build/src/reporters/main.d.ts +9 -4
  13. package/build/src/reporters/main.js +11 -37
  14. package/build/src/types.d.ts +23 -19
  15. package/build/src/types.js +14 -9
  16. package/package.json +26 -17
  17. package/build/factories/runner.d.ts +0 -27
  18. package/build/factories/runner.js +0 -206
  19. package/build/modules/core/reporters/base.d.ts +0 -41
  20. package/build/modules/core/reporters/base.js +0 -183
  21. package/build/modules/core/types.d.ts +0 -5
  22. package/build/modules/core/types.js +0 -9
  23. package/build/src/cli_parser.d.ts +0 -14
  24. package/build/src/cli_parser.js +0 -75
  25. package/build/src/config_manager.d.ts +0 -18
  26. package/build/src/config_manager.js +0 -168
  27. package/build/src/create_test.d.ts +0 -21
  28. package/build/src/create_test.js +0 -53
  29. package/build/src/debug.d.ts +0 -3
  30. package/build/src/debug.js +0 -10
  31. package/build/src/exceptions_manager.d.ts +0 -19
  32. package/build/src/exceptions_manager.js +0 -85
  33. package/build/src/files_manager.d.ts +0 -18
  34. package/build/src/files_manager.js +0 -57
  35. package/build/src/helpers.d.ts +0 -22
  36. package/build/src/helpers.js +0 -10
  37. package/build/src/hooks.d.ts +0 -20
  38. package/build/src/hooks.js +0 -46
  39. package/build/src/planner.d.ts +0 -25
  40. package/build/src/planner.js +0 -98
  41. package/build/src/plugins/retry.d.ts +0 -20
  42. package/build/src/plugins/retry.js +0 -66
  43. package/build/src/reporters/dot.d.ts +0 -15
  44. package/build/src/reporters/dot.js +0 -41
  45. package/build/src/reporters/ndjson.d.ts +0 -15
  46. package/build/src/reporters/ndjson.js +0 -86
  47. package/build/src/reporters/spec.d.ts +0 -13
  48. package/build/src/reporters/spec.js +0 -154
  49. package/build/src/validator.d.ts +0 -30
  50. package/build/src/validator.js +0 -85
@@ -1,154 +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 { relative } from 'node:path';
11
- import cliui from '../helpers.js';
12
- import { BaseReporter } from '../../modules/core/main.js';
13
- /**
14
- * Pretty prints the tests on the console
15
- */
16
- export class SpecReporter extends BaseReporter {
17
- /**
18
- * Tracking if the first event we get is for a test without any parent group
19
- * We need this to decide the display style for tests without groups.
20
- */
21
- #isFirstLoneTest = true;
22
- /**
23
- * Returns the icon for the test
24
- */
25
- #getTestIcon(payload) {
26
- if (payload.isTodo) {
27
- return cliui.colors.cyan(cliui.icons.info);
28
- }
29
- if (payload.isFailing) {
30
- return payload.hasError
31
- ? cliui.colors.magenta(cliui.icons.squareSmallFilled)
32
- : cliui.colors.red(cliui.icons.cross);
33
- }
34
- if (payload.hasError) {
35
- return cliui.colors.red(cliui.icons.cross);
36
- }
37
- if (payload.isSkipped) {
38
- return cliui.colors.yellow(cliui.icons.bullet);
39
- }
40
- return cliui.colors.green(cliui.icons.tick);
41
- }
42
- /**
43
- * Returns the test message
44
- */
45
- #getTestMessage(payload) {
46
- const message = typeof payload.title === 'string' ? payload.title : payload.title.expanded;
47
- if (payload.isTodo) {
48
- return cliui.colors.blue(message);
49
- }
50
- if (payload.isFailing) {
51
- return payload.hasError ? cliui.colors.magenta(message) : cliui.colors.red(message);
52
- }
53
- if (payload.hasError) {
54
- return cliui.colors.red(message);
55
- }
56
- if (payload.isSkipped) {
57
- return cliui.colors.yellow(message);
58
- }
59
- return cliui.colors.grey(message);
60
- }
61
- /**
62
- * Returns the subtext message for the test
63
- */
64
- #getSubText(payload) {
65
- if (payload.isSkipped && payload.skipReason) {
66
- return cliui.colors.yellow(payload.skipReason);
67
- }
68
- if (!payload.isFailing) {
69
- return;
70
- }
71
- if (!payload.hasError) {
72
- return cliui.colors.magenta(`Test marked with ".fails()" must finish with an error`);
73
- }
74
- if (payload.failReason) {
75
- return cliui.colors.magenta(payload.failReason);
76
- }
77
- const testErrorMessage = payload.errors.find((error) => error.phase === 'test');
78
- if (testErrorMessage && testErrorMessage.error) {
79
- return cliui.colors.magenta(testErrorMessage.error.message);
80
- }
81
- }
82
- /**
83
- * Returns the filename relative from the current working dir
84
- */
85
- #getRelativeFilename(fileName) {
86
- return relative(process.cwd(), fileName);
87
- }
88
- /**
89
- * Prints the test details
90
- */
91
- #printTest(payload) {
92
- const icon = this.#getTestIcon(payload);
93
- const message = this.#getTestMessage(payload);
94
- const prefix = payload.isPinned ? cliui.colors.yellow('[PINNED] ') : '';
95
- const indentation = this.currentFileName || this.currentGroupName ? ' ' : '';
96
- const duration = cliui.colors.dim(`(${ms(Number(payload.duration.toFixed(2)))})`);
97
- const retries = payload.retryAttempt && payload.retryAttempt > 1
98
- ? cliui.colors.dim(`(x${payload.retryAttempt}) `)
99
- : '';
100
- let subText = this.#getSubText(payload);
101
- subText = subText ? `\n${indentation} ${subText}` : '';
102
- console.log(`${indentation}${icon} ${prefix}${retries}${message} ${duration}${subText}`);
103
- }
104
- /**
105
- * Prints the group name
106
- */
107
- #printGroup(payload) {
108
- const title = this.currentSuiteName !== 'default'
109
- ? `${this.currentSuiteName} / ${payload.title}`
110
- : payload.title;
111
- const suffix = this.currentFileName
112
- ? cliui.colors.dim(` (${this.#getRelativeFilename(this.currentFileName)})`)
113
- : '';
114
- console.log(`\n${title}${suffix}`);
115
- }
116
- onTestStart() {
117
- /**
118
- * Display the filename when
119
- *
120
- * - The filename exists
121
- * - The test is not under a group
122
- * - Test is first in a sequence
123
- */
124
- if (this.currentFileName && this.#isFirstLoneTest) {
125
- console.log(`\n${cliui.colors.dim(this.#getRelativeFilename(this.currentFileName))}`);
126
- }
127
- this.#isFirstLoneTest = false;
128
- }
129
- onTestEnd(payload) {
130
- this.#printTest(payload);
131
- }
132
- onGroupStart(payload) {
133
- /**
134
- * When a group starts, we mark the upcoming test as NOT a
135
- * lone test
136
- */
137
- this.#isFirstLoneTest = false;
138
- this.#printGroup(payload);
139
- }
140
- onGroupEnd() {
141
- /**
142
- * When the group ends we assume that the next test can
143
- * be out of the group, hence a lone test.
144
- *
145
- * If this assumption is false, then the `onGroupStart` method
146
- * will toggle the boolean
147
- */
148
- this.#isFirstLoneTest = true;
149
- }
150
- async end() {
151
- const summary = this.runner.getSummary();
152
- await this.printSummary(summary);
153
- }
154
- }
@@ -1,30 +0,0 @@
1
- import { NormalizedConfig } from './types.js';
2
- /**
3
- * Validator encapsulates the validations to perform before running
4
- * the tests
5
- */
6
- declare class Validator {
7
- /**
8
- * Ensures the japa is configured. Otherwise raises an exception
9
- */
10
- ensureIsConfigured(config: NormalizedConfig | undefined): void;
11
- /**
12
- * Ensures the japa is in planning phase
13
- */
14
- ensureIsInPlanningPhase(phase: 'idle' | 'planning' | 'executing'): void;
15
- /**
16
- * Ensures the suites filter uses a subset of the user configured suites.
17
- */
18
- validateSuitesFilter(config: NormalizedConfig): void;
19
- /**
20
- * Ensure there are unique suites
21
- */
22
- validateSuitesForUniqueness(config: NormalizedConfig): void;
23
- /**
24
- * Ensure the activated reporters are in the list of defined
25
- * reporters
26
- */
27
- validateActivatedReporters(config: NormalizedConfig): void;
28
- }
29
- declare const _default: Validator;
30
- export default _default;
@@ -1,85 +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
- /**
10
- * Validator encapsulates the validations to perform before running
11
- * the tests
12
- */
13
- class Validator {
14
- /**
15
- * Ensures the japa is configured. Otherwise raises an exception
16
- */
17
- ensureIsConfigured(config) {
18
- if (!config) {
19
- throw new Error(`Cannot run tests. Make sure to call "configure" method before the "run" method`);
20
- }
21
- }
22
- /**
23
- * Ensures the japa is in planning phase
24
- */
25
- ensureIsInPlanningPhase(phase) {
26
- if (phase !== 'planning') {
27
- throw new Error(`Cannot import japa test file directly. It must be imported by calling the "japa.run" method`);
28
- }
29
- }
30
- /**
31
- * Ensures the suites filter uses a subset of the user configured suites.
32
- */
33
- validateSuitesFilter(config) {
34
- /**
35
- * Do not perform any validation if no filters are applied
36
- * in the first place
37
- */
38
- if (!config.filters.suites || !config.filters.suites.length) {
39
- return;
40
- }
41
- /**
42
- * Notify user they have applied the suites filter but forgot to define
43
- * suites
44
- */
45
- if (!('suites' in config) || !config.suites.length) {
46
- throw new Error(`Cannot apply suites filter. You have not configured any test suites`);
47
- }
48
- const suites = config.suites.map(({ name }) => name);
49
- /**
50
- * Find unknown suites and report the error
51
- */
52
- const unknownSuites = config.filters.suites.filter((suite) => !suites.includes(suite));
53
- if (unknownSuites.length) {
54
- throw new Error(`Cannot apply suites filter. "${unknownSuites[0]}" suite is not configured`);
55
- }
56
- }
57
- /**
58
- * Ensure there are unique suites
59
- */
60
- validateSuitesForUniqueness(config) {
61
- if (!('suites' in config)) {
62
- return;
63
- }
64
- const suites = new Set();
65
- config.suites.forEach(({ name }) => {
66
- if (suites.has(name)) {
67
- throw new Error(`Duplicate suite "${name}"`);
68
- }
69
- suites.add(name);
70
- });
71
- suites.clear();
72
- }
73
- /**
74
- * Ensure the activated reporters are in the list of defined
75
- * reporters
76
- */
77
- validateActivatedReporters(config) {
78
- const reportersList = config.reporters.list.map(({ name }) => name);
79
- const unknownReporters = config.reporters.activated.filter((name) => !reportersList.includes(name));
80
- if (unknownReporters.length) {
81
- throw new Error(`Invalid reporter "${unknownReporters[0]}". Make sure to register it first inside the "reporters.list" array`);
82
- }
83
- }
84
- }
85
- export default new Validator();