@japa/runner 3.0.0-4 → 3.0.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.
@@ -15,8 +15,8 @@ const ansi = colors.ansi();
15
15
  * will be parsed aswell, but without any normalization
16
16
  */
17
17
  const OPTIONS = {
18
- string: ['tests', 'groups', 'tags', 'files', 'timeout', 'retries', 'reporter'],
19
- boolean: ['help', 'matchAll'],
18
+ string: ['tests', 'groups', 'tags', 'files', 'timeout', 'retries', 'reporter', 'failed'],
19
+ boolean: ['help', 'matchAll', 'failed'],
20
20
  alias: {
21
21
  forceExit: 'force-exit',
22
22
  matchAll: 'match-all',
@@ -37,6 +37,7 @@ ${ansi.green('--force-exit')} ${ansi.dim('Forcefully exit the pro
37
37
  ${ansi.green('--timeout')} ${ansi.dim('Define default timeout for all tests')}
38
38
  ${ansi.green('--retries')} ${ansi.dim('Define default retries for all tests')}
39
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')}
40
41
  ${ansi.green('-h, --help')} ${ansi.dim('View help')}
41
42
 
42
43
  ${ansi.yellow('Examples:')}
@@ -1,4 +1,5 @@
1
- import type { CLIArgs, Config } from './types.js';
1
+ import type { CLIArgs, Config, NormalizedConfig } from './types.js';
2
+ export declare const NOOP: () => void;
2
3
  /**
3
4
  * Config manager is used to hydrate the configuration by merging
4
5
  * the defaults, user defined config and the command line
@@ -13,5 +14,5 @@ export declare class ConfigManager {
13
14
  * Hydrates the config with user defined options and the
14
15
  * command-line flags.
15
16
  */
16
- hydrate(): Required<Config>;
17
+ hydrate(): NormalizedConfig;
17
18
  }
@@ -9,6 +9,7 @@
9
9
  import debug from './debug.js';
10
10
  import { dot, ndjson, spec } from './reporters/main.js';
11
11
  import { Refiner } from '../modules/core/main.js';
12
+ export const NOOP = () => { };
12
13
  /**
13
14
  * Defaults to use for configuration
14
15
  */
@@ -128,7 +129,12 @@ export class ConfigManager {
128
129
  timeout: cliTimeout ?? this.#config.timeout ?? DEFAULTS.timeout,
129
130
  plugins: this.#config.plugins ?? DEFAULTS.plugins,
130
131
  forceExit: cliForceExit ?? this.#config.forceExit ?? DEFAULTS.forceExit,
131
- reporters: this.#config.reporters ?? DEFAULTS.reporters,
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,
132
138
  configureSuite: this.#config.configureSuite ?? DEFAULTS.configureSuite,
133
139
  setup: this.#config.setup || [],
134
140
  teardown: this.#config.teardown || [],
@@ -153,7 +159,7 @@ export class ConfigManager {
153
159
  files: suite.files,
154
160
  timeout: cliTimeout ?? suite.timeout ?? baseConfig.timeout,
155
161
  retries: cliRetries ?? suite.retries ?? baseConfig.retries,
156
- configure: suite.configure,
162
+ configure: suite.configure || NOOP,
157
163
  };
158
164
  }),
159
165
  ...baseConfig,
@@ -1,5 +1,5 @@
1
1
  import { Runner } from '../modules/core/main.js';
2
- import type { Config } from './types.js';
2
+ import type { NormalizedConfig } from './types.js';
3
3
  /**
4
4
  * Exposes API for working with global hooks
5
5
  */
@@ -8,7 +8,7 @@ export declare class GlobalHooks {
8
8
  /**
9
9
  * Apply hooks from the config
10
10
  */
11
- apply(config: Required<Config>): void;
11
+ apply(config: NormalizedConfig): void;
12
12
  /**
13
13
  * Perform setup
14
14
  */
@@ -1,5 +1,5 @@
1
1
  /// <reference types="@types/node" resolution-mode="require"/>
2
- import type { Config, TestSuite } from './types.js';
2
+ import type { NormalizedConfig, TestSuite } from './types.js';
3
3
  /**
4
4
  * The tests planner is used to plan the tests by doing all
5
5
  * the heavy lifting of executing plugins, registering
@@ -7,7 +7,7 @@ import type { Config, TestSuite } from './types.js';
7
7
  */
8
8
  export declare class Planner {
9
9
  #private;
10
- constructor(config: Required<Config>);
10
+ constructor(config: NormalizedConfig);
11
11
  /**
12
12
  * Creates a plan for running the tests
13
13
  */
@@ -20,6 +20,6 @@ export declare class Planner {
20
20
  layer: "tags" | "tests" | "groups";
21
21
  filters: string[];
22
22
  }[];
23
- config: Required<Config>;
23
+ config: NormalizedConfig;
24
24
  }>;
25
25
  }
@@ -15,6 +15,6 @@ export declare function cacheFailedTests(tests: string[]): Promise<void>;
15
15
  */
16
16
  export declare function clearCache(): Promise<void>;
17
17
  /**
18
- * Exposes the API to run failing tests using the "retry" CLI flag.
18
+ * Exposes the API to run failing tests using the "failed" CLI flag.
19
19
  */
20
20
  export declare const retryPlugin: PluginFn;
@@ -45,7 +45,7 @@ export async function clearCache() {
45
45
  await unlink(SUMMARY_FILE);
46
46
  }
47
47
  /**
48
- * Exposes the API to run failing tests using the "retry" CLI flag.
48
+ * Exposes the API to run failing tests using the "failed" CLI flag.
49
49
  */
50
50
  export const retryPlugin = async function retry({ config, cliArgs }) {
51
51
  if (!SUMMARY_FILE) {
@@ -55,7 +55,7 @@ export const retryPlugin = async function retry({ config, cliArgs }) {
55
55
  const summary = runner.getSummary();
56
56
  await cacheFailedTests(summary.failedTestsTitles);
57
57
  });
58
- if (cliArgs.retry) {
58
+ if (cliArgs.failed) {
59
59
  const { tests } = await getFailedTests();
60
60
  if (!tests || !tests.length) {
61
61
  console.log(cliui.colors.bgYellow().black(' No failing tests found. Running all the tests '));
@@ -33,6 +33,7 @@ export type CLIArgs = {
33
33
  retries?: string;
34
34
  reporter?: string | string[];
35
35
  forceExit?: boolean;
36
+ failed?: boolean;
36
37
  help?: boolean;
37
38
  matchAll?: boolean;
38
39
  } & Record<string, string | string[] | boolean>;
@@ -48,7 +49,7 @@ export type Filters = FilteringOptions & {
48
49
  * emitter, config and the hooks
49
50
  */
50
51
  export type PluginFn = (japa: {
51
- config: Required<Config>;
52
+ config: NormalizedConfig;
52
53
  cliArgs: CLIArgs;
53
54
  runner: Runner;
54
55
  emitter: Emitter;
@@ -86,7 +87,7 @@ export type BaseConfig = {
86
87
  */
87
88
  reporters?: {
88
89
  activated: string[];
89
- list: NamedReporterContract[];
90
+ list?: NamedReporterContract[];
90
91
  };
91
92
  /**
92
93
  * A collection of registered plugins
@@ -147,6 +148,15 @@ export type TestSuite = {
147
148
  */
148
149
  retries?: number;
149
150
  };
151
+ /**
152
+ * BaseConfig after normalized by the config manager
153
+ */
154
+ export type NormalizedBaseConfig = Required<Omit<BaseConfig, 'reporters'>> & {
155
+ reporters: {
156
+ activated: string[];
157
+ list: NamedReporterContract[];
158
+ };
159
+ };
150
160
  /**
151
161
  * Configuration options
152
162
  */
@@ -155,3 +165,11 @@ export type Config = BaseConfig & ({
155
165
  } | {
156
166
  suites: TestSuite[];
157
167
  });
168
+ /**
169
+ * Config after normalized by the config manager
170
+ */
171
+ export type NormalizedConfig = NormalizedBaseConfig & ({
172
+ files: TestFiles;
173
+ } | {
174
+ suites: Required<TestSuite>[];
175
+ });
@@ -1,4 +1,4 @@
1
- import { Config } from './types.js';
1
+ import { NormalizedConfig } from './types.js';
2
2
  /**
3
3
  * Validator encapsulates the validations to perform before running
4
4
  * the tests
@@ -7,7 +7,7 @@ declare class Validator {
7
7
  /**
8
8
  * Ensures the japa is configured. Otherwise raises an exception
9
9
  */
10
- ensureIsConfigured(config: Required<Config> | undefined): void;
10
+ ensureIsConfigured(config: NormalizedConfig | undefined): void;
11
11
  /**
12
12
  * Ensures the japa is in planning phase
13
13
  */
@@ -15,16 +15,16 @@ declare class Validator {
15
15
  /**
16
16
  * Ensures the suites filter uses a subset of the user configured suites.
17
17
  */
18
- validateSuitesFilter(config: Required<Config>): void;
18
+ validateSuitesFilter(config: NormalizedConfig): void;
19
19
  /**
20
20
  * Ensure there are unique suites
21
21
  */
22
- validateSuitesForUniqueness(config: Required<Config>): void;
22
+ validateSuitesForUniqueness(config: NormalizedConfig): void;
23
23
  /**
24
24
  * Ensure the activated reporters are in the list of defined
25
25
  * reporters
26
26
  */
27
- validateActivatedReporters(config: Required<Config>): void;
27
+ validateActivatedReporters(config: NormalizedConfig): void;
28
28
  }
29
29
  declare const _default: Validator;
30
30
  export default _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@japa/runner",
3
3
  "description": "Runner for Japa testing framework",
4
- "version": "3.0.0-4",
4
+ "version": "3.0.0-5",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -48,7 +48,7 @@
48
48
  "@types/chai-subset": "^1.3.3",
49
49
  "@types/find-cache-dir": "^3.2.1",
50
50
  "@types/ms": "^0.7.31",
51
- "@types/node": "^20.3.3",
51
+ "@types/node": "^20.4.1",
52
52
  "c8": "^8.0.0",
53
53
  "chai": "^4.3.7",
54
54
  "chai-subset": "^1.6.0",
@@ -56,7 +56,7 @@
56
56
  "del-cli": "^5.0.0",
57
57
  "eslint": "^8.44.0",
58
58
  "github-label-sync": "^2.3.1",
59
- "glob": "^10.3.1",
59
+ "glob": "^10.3.2",
60
60
  "husky": "^8.0.3",
61
61
  "japa": "^4.0.0",
62
62
  "np": "^8.0.4",
@@ -65,7 +65,7 @@
65
65
  "typescript": "^5.1.6"
66
66
  },
67
67
  "dependencies": {
68
- "@japa/core": "^8.0.0-8",
68
+ "@japa/core": "^8.0.0-9",
69
69
  "@japa/errors-printer": "^3.0.0-4",
70
70
  "@poppinss/cliui": "^6.1.1-2",
71
71
  "@poppinss/hooks": "^7.1.1-3",