@japa/runner 3.0.0-1 → 3.0.0-3

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 (66) hide show
  1. package/build/factories/main.d.ts +3 -1
  2. package/build/factories/main.js +11 -0
  3. package/build/factories/runner.d.ts +18 -1
  4. package/build/factories/runner.js +45 -0
  5. package/build/index.d.ts +22 -1
  6. package/build/index.js +95 -0
  7. package/build/modules/core/main.d.ts +34 -1
  8. package/build/modules/core/main.js +53 -0
  9. package/build/modules/core/reporters/base.d.ts +21 -1
  10. package/build/modules/core/reporters/base.js +47 -0
  11. package/build/modules/core/types.d.ts +0 -1
  12. package/build/modules/core/types.js +8 -0
  13. package/build/src/cli_parser.d.ts +9 -1
  14. package/build/src/cli_parser.js +25 -0
  15. package/build/src/config_manager.d.ts +11 -1
  16. package/build/src/config_manager.js +47 -0
  17. package/build/src/create_test.d.ts +6 -1
  18. package/build/src/create_test.js +20 -0
  19. package/build/src/debug.d.ts +0 -1
  20. package/build/src/debug.js +8 -0
  21. package/build/src/exceptions_manager.d.ts +13 -1
  22. package/build/src/exceptions_manager.js +27 -0
  23. package/build/src/files_manager.d.ts +12 -1
  24. package/build/src/files_manager.js +31 -2
  25. package/build/src/helpers.d.ts +0 -1
  26. package/build/src/helpers.js +8 -0
  27. package/build/src/hooks.d.ts +12 -1
  28. package/build/src/hooks.js +20 -0
  29. package/build/src/planner.d.ts +8 -1
  30. package/build/src/planner.js +31 -0
  31. package/build/src/plugins/retry.d.ts +13 -1
  32. package/build/src/plugins/retry.js +24 -0
  33. package/build/src/reporters/dot.d.ts +9 -1
  34. package/build/src/reporters/dot.js +17 -0
  35. package/build/src/reporters/main.d.ts +9 -1
  36. package/build/src/reporters/main.js +17 -0
  37. package/build/src/reporters/ndjson.d.ts +4 -1
  38. package/build/src/reporters/ndjson.js +15 -0
  39. package/build/src/reporters/spec.d.ts +3 -1
  40. package/build/src/reporters/spec.js +52 -1
  41. package/build/src/types.d.ts +91 -1
  42. package/build/src/types.js +8 -0
  43. package/build/src/validator.d.ts +20 -1
  44. package/build/src/validator.js +39 -0
  45. package/package.json +14 -13
  46. package/build/factories/main.d.ts.map +0 -1
  47. package/build/factories/runner.d.ts.map +0 -1
  48. package/build/modules/core/main.d.ts.map +0 -1
  49. package/build/modules/core/reporters/base.d.ts.map +0 -1
  50. package/build/modules/core/types.d.ts.map +0 -1
  51. package/build/src/cli_parser.d.ts.map +0 -1
  52. package/build/src/config_manager.d.ts.map +0 -1
  53. package/build/src/create_test.d.ts.map +0 -1
  54. package/build/src/debug.d.ts.map +0 -1
  55. package/build/src/exceptions_manager.d.ts.map +0 -1
  56. package/build/src/files_manager.d.ts.map +0 -1
  57. package/build/src/helpers.d.ts.map +0 -1
  58. package/build/src/hooks.d.ts.map +0 -1
  59. package/build/src/planner.d.ts.map +0 -1
  60. package/build/src/plugins/retry.d.ts.map +0 -1
  61. package/build/src/reporters/dot.d.ts.map +0 -1
  62. package/build/src/reporters/main.d.ts.map +0 -1
  63. package/build/src/reporters/ndjson.d.ts.map +0 -1
  64. package/build/src/reporters/spec.d.ts.map +0 -1
  65. package/build/src/types.d.ts.map +0 -1
  66. package/build/src/validator.d.ts.map +0 -1
@@ -3,4 +3,3 @@ export type BaseReporterOptions = {
3
3
  stackLinesCount?: number;
4
4
  framesMaxLimit?: number;
5
5
  };
6
- //# sourceMappingURL=types.d.ts.map
@@ -1 +1,9 @@
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
  export * from '@japa/core/types';
@@ -1,6 +1,14 @@
1
1
  import type { CLIArgs } from './types.js';
2
+ /**
3
+ * CLI Parser is used to parse the commandline argument
4
+ */
2
5
  export declare class CliParser {
6
+ /**
7
+ * Parses command-line arguments
8
+ */
3
9
  parse(argv: string[]): CLIArgs;
10
+ /**
11
+ * Returns the help string
12
+ */
4
13
  getHelp(): string;
5
14
  }
6
- //# sourceMappingURL=cli_parser.d.ts.map
@@ -1,6 +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
+ */
9
+ // @ts-ignore-error
1
10
  import getopts from 'getopts';
2
11
  import colors from '@poppinss/colors';
3
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
+ */
4
17
  const OPTIONS = {
5
18
  string: ['tests', 'groups', 'tags', 'files', 'timeout', 'retries', 'reporter'],
6
19
  boolean: ['help', 'matchAll'],
@@ -10,6 +23,9 @@ const OPTIONS = {
10
23
  help: 'h',
11
24
  },
12
25
  };
26
+ /**
27
+ * Help string to display when the `--help flag is used`
28
+ */
13
29
  const GET_HELP = () => `
14
30
  ${ansi.yellow('@japa/runner v2.3.0')}
15
31
 
@@ -39,10 +55,19 @@ ${ansi.yellow('Notes:')}
39
55
  - The retries defined on test object takes precedence over the ${ansi.green('--retries')} flag.
40
56
  - The ${ansi.green('--files')} flag checks for the file names ending with the filter substring.
41
57
  `;
58
+ /**
59
+ * CLI Parser is used to parse the commandline argument
60
+ */
42
61
  export class CliParser {
62
+ /**
63
+ * Parses command-line arguments
64
+ */
43
65
  parse(argv) {
44
66
  return getopts(argv, OPTIONS);
45
67
  }
68
+ /**
69
+ * Returns the help string
70
+ */
46
71
  getHelp() {
47
72
  return GET_HELP();
48
73
  }
@@ -1,7 +1,17 @@
1
1
  import type { CLIArgs, Config } from './types.js';
2
+ /**
3
+ * Config manager is used to hydrate the configuration by merging
4
+ * the defaults, user defined config and the command line
5
+ * flags.
6
+ *
7
+ * The command line flags have the upmost priority
8
+ */
2
9
  export declare class ConfigManager {
3
10
  #private;
4
11
  constructor(config: Config, cliArgs: CLIArgs);
12
+ /**
13
+ * Hydrates the config with user defined options and the
14
+ * command-line flags.
15
+ */
5
16
  hydrate(): Required<Config>;
6
17
  }
7
- //# sourceMappingURL=config_manager.d.ts.map
@@ -1,6 +1,17 @@
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 debug from './debug.js';
2
10
  import { spec } from './reporters/main.js';
3
11
  import { Refiner } from '../modules/core/main.js';
12
+ /**
13
+ * Defaults to use for configuration
14
+ */
4
15
  const DEFAULTS = {
5
16
  files: [],
6
17
  timeout: 2000,
@@ -14,6 +25,13 @@ const DEFAULTS = {
14
25
  importer: (filePath) => import(filePath.href),
15
26
  configureSuite: () => { },
16
27
  };
28
+ /**
29
+ * Config manager is used to hydrate the configuration by merging
30
+ * the defaults, user defined config and the command line
31
+ * flags.
32
+ *
33
+ * The command line flags have the upmost priority
34
+ */
17
35
  export class ConfigManager {
18
36
  #config;
19
37
  #cliArgs;
@@ -21,9 +39,17 @@ export class ConfigManager {
21
39
  this.#config = config;
22
40
  this.#cliArgs = cliArgs;
23
41
  }
42
+ /**
43
+ * Processes a CLI argument and converts it to an
44
+ * array of strings
45
+ */
24
46
  #processAsArray(value) {
25
47
  return Array.isArray(value) ? value : value.split(',').map((item) => item.trim());
26
48
  }
49
+ /**
50
+ * Returns a copy of filters based upon the CLI
51
+ * arguments.
52
+ */
27
53
  #getCLIFilters() {
28
54
  const filters = {};
29
55
  if (this.#cliArgs.tags) {
@@ -43,6 +69,9 @@ export class ConfigManager {
43
69
  }
44
70
  return filters;
45
71
  }
72
+ /**
73
+ * Returns the timeout from the CLI args
74
+ */
46
75
  #getCLITimeout() {
47
76
  if (this.#cliArgs.timeout) {
48
77
  const value = Number(this.#cliArgs.timeout);
@@ -51,6 +80,9 @@ export class ConfigManager {
51
80
  }
52
81
  }
53
82
  }
83
+ /**
84
+ * Returns the retries from the CLI args
85
+ */
54
86
  #getCLIRetries() {
55
87
  if (this.#cliArgs.retries) {
56
88
  const value = Number(this.#cliArgs.retries);
@@ -59,16 +91,27 @@ export class ConfigManager {
59
91
  }
60
92
  }
61
93
  }
94
+ /**
95
+ * Returns the forceExit property from the CLI args
96
+ */
62
97
  #getCLIForceExit() {
63
98
  if (this.#cliArgs.forceExit) {
64
99
  return true;
65
100
  }
66
101
  }
102
+ /**
103
+ * Returns reporters selected using the commandline
104
+ * --reporter flag
105
+ */
67
106
  #getCLIReporters() {
68
107
  if (this.#cliArgs.reporter) {
69
108
  return this.#processAsArray(this.#cliArgs.reporter);
70
109
  }
71
110
  }
111
+ /**
112
+ * Hydrates the config with user defined options and the
113
+ * command-line flags.
114
+ */
72
115
  hydrate() {
73
116
  const cliFilters = this.#getCLIFilters();
74
117
  const cliRetries = this.#getCLIRetries();
@@ -90,6 +133,10 @@ export class ConfigManager {
90
133
  setup: this.#config.setup || [],
91
134
  teardown: this.#config.teardown || [],
92
135
  };
136
+ /**
137
+ * Overwrite activated reporters when defined using CLI
138
+ * flag
139
+ */
93
140
  if (cliReporters) {
94
141
  baseConfig.reporters.activated = cliReporters;
95
142
  }
@@ -1,4 +1,7 @@
1
1
  import { Emitter, Group, Refiner, Suite, Test } from '../modules/core/main.js';
2
+ /**
3
+ * Create a new instance of the Test
4
+ */
2
5
  export declare function createTest(title: string, emitter: Emitter, refiner: Refiner, options: {
3
6
  group?: Group;
4
7
  suite?: Suite;
@@ -6,6 +9,9 @@ export declare function createTest(title: string, emitter: Emitter, refiner: Ref
6
9
  timeout?: number;
7
10
  retries?: number;
8
11
  }): Test<undefined>;
12
+ /**
13
+ * Create a new instance of the Group
14
+ */
9
15
  export declare function createTestGroup(title: string, emitter: Emitter, refiner: Refiner, options: {
10
16
  group?: Group;
11
17
  suite?: Suite;
@@ -13,4 +19,3 @@ export declare function createTestGroup(title: string, emitter: Emitter, refiner
13
19
  timeout?: number;
14
20
  retries?: number;
15
21
  }): Group;
16
- //# sourceMappingURL=create_test.d.ts.map
@@ -1,5 +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 { Group, Test, TestContext } from '../modules/core/main.js';
10
+ /**
11
+ * Function to create the test context for the test
12
+ */
2
13
  const contextBuilder = (testInstance) => new TestContext(testInstance);
14
+ /**
15
+ * Create a new instance of the Test
16
+ */
3
17
  export function createTest(title, emitter, refiner, options) {
4
18
  const testInstance = new Test(title, contextBuilder, emitter, refiner, options.group);
5
19
  testInstance.options.meta.suite = options.suite;
@@ -11,6 +25,9 @@ export function createTest(title, emitter, refiner, options) {
11
25
  if (options.retries !== undefined) {
12
26
  testInstance.retry(options.retries);
13
27
  }
28
+ /**
29
+ * Register test as a child either with the group or the suite
30
+ */
14
31
  if (options.group) {
15
32
  options.group.add(testInstance);
16
33
  }
@@ -19,6 +36,9 @@ export function createTest(title, emitter, refiner, options) {
19
36
  }
20
37
  return testInstance;
21
38
  }
39
+ /**
40
+ * Create a new instance of the Group
41
+ */
22
42
  export function createTestGroup(title, emitter, refiner, options) {
23
43
  if (options.group) {
24
44
  throw new Error('Nested groups are not supported by Japa');
@@ -1,4 +1,3 @@
1
1
  /// <reference types="@types/node" resolution-mode="require"/>
2
2
  declare const _default: import("util").DebugLogger;
3
3
  export default _default;
4
- //# sourceMappingURL=debug.d.ts.map
@@ -1,2 +1,10 @@
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 { debuglog } from 'node:util';
2
10
  export default debuglog('japa:runner');
@@ -1,7 +1,19 @@
1
+ /**
2
+ * Handles uncaught exceptions and prints them to the
3
+ * console
4
+ */
1
5
  export declare class ExceptionsManager {
2
6
  #private;
3
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
+ */
4
17
  monitor(): void;
5
18
  flow(): Promise<void>;
6
19
  }
7
- //# sourceMappingURL=exceptions_manager.d.ts.map
@@ -1,10 +1,31 @@
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 { ErrorsPrinter } from '@japa/errors-printer';
10
+ /**
11
+ * Handles uncaught exceptions and prints them to the
12
+ * console
13
+ */
2
14
  export class ExceptionsManager {
3
15
  #exceptionsBuffer = [];
4
16
  #rejectionsBuffer = [];
5
17
  #state = 'watching';
6
18
  #errorsPrinter = new ErrorsPrinter({ stackLinesCount: 2, framesMaxLimit: 4 });
7
19
  hasErrors = false;
20
+ /**
21
+ * Monitors unhandled exceptions and rejections. The exceptions
22
+ * are stacked in a buffer, so that we do not clutter the
23
+ * tests output and once the tests are over, we will
24
+ * print them to the console.
25
+ *
26
+ * In case the tests are completed, we will print errors as they
27
+ * happen.
28
+ */
8
29
  monitor() {
9
30
  process.on('uncaughtException', async (error) => {
10
31
  this.hasErrors = true;
@@ -34,6 +55,9 @@ export class ExceptionsManager {
34
55
  return;
35
56
  }
36
57
  this.#state = 'flowing';
58
+ /**
59
+ * Print exceptions
60
+ */
37
61
  if (this.#exceptionsBuffer.length) {
38
62
  let exceptionsCount = this.#exceptionsBuffer.length;
39
63
  let exceptionsIndex = this.#exceptionsBuffer.length;
@@ -44,6 +68,9 @@ export class ExceptionsManager {
44
68
  }
45
69
  this.#exceptionsBuffer = [];
46
70
  }
71
+ /**
72
+ * Print rejections
73
+ */
47
74
  if (this.#rejectionsBuffer.length) {
48
75
  let rejectionsCount = this.#exceptionsBuffer.length;
49
76
  let rejectionsIndex = this.#exceptionsBuffer.length;
@@ -1,7 +1,18 @@
1
1
  /// <reference types="@types/node" resolution-mode="require"/>
2
2
  import type { TestFiles } from './types.js';
3
+ /**
4
+ * Files manager exposes the API to collect, filter and import test
5
+ * files based upon the config
6
+ */
3
7
  export declare class FilesManager {
8
+ /**
9
+ * Returns a collection of files from the user defined
10
+ * glob or the implementation function
11
+ */
4
12
  getFiles(cwd: string, files: TestFiles): Promise<URL[]>;
13
+ /**
14
+ * Applies file name filter on a collection of file
15
+ * URLs
16
+ */
5
17
  grep(files: URL[], filters: string[]): URL[];
6
18
  }
7
- //# sourceMappingURL=files_manager.d.ts.map
@@ -1,8 +1,28 @@
1
- import { sep } from 'node:path';
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 slash from 'slash';
2
10
  import fastGlob from 'fast-glob';
3
11
  import { pathToFileURL } from 'node:url';
12
+ /**
13
+ * The expression to remove file extension and optionally
14
+ * .spec|.test from the test file name
15
+ */
4
16
  const FILE_SUFFIX_EXPRESSION = /(\.spec|\.test)?\.[js|ts|jsx|tsx|mjs|mts|cjs|cts]+$/;
17
+ /**
18
+ * Files manager exposes the API to collect, filter and import test
19
+ * files based upon the config
20
+ */
5
21
  export class FilesManager {
22
+ /**
23
+ * Returns a collection of files from the user defined
24
+ * glob or the implementation function
25
+ */
6
26
  async getFiles(cwd, files) {
7
27
  if (Array.isArray(files) || typeof files === 'string') {
8
28
  const testFiles = await fastGlob(files, {
@@ -14,11 +34,20 @@ export class FilesManager {
14
34
  }
15
35
  return await files();
16
36
  }
37
+ /**
38
+ * Applies file name filter on a collection of file
39
+ * URLs
40
+ */
17
41
  grep(files, filters) {
18
42
  return files.filter((file) => {
43
+ const filename = slash(file.pathname);
44
+ const filenameWithoutTestSuffix = filename.replace(FILE_SUFFIX_EXPRESSION, '');
19
45
  return !!filters.find((filter) => {
46
+ if (filename.endsWith(filter)) {
47
+ return true;
48
+ }
20
49
  const filterSegments = filter.split('/').reverse();
21
- const fileSegments = file.pathname.replace(FILE_SUFFIX_EXPRESSION, '').split(sep).reverse();
50
+ const fileSegments = filenameWithoutTestSuffix.split('/').reverse();
22
51
  return filterSegments.every((segment, index) => {
23
52
  return fileSegments[index] && (segment === '*' || fileSegments[index].endsWith(segment));
24
53
  });
@@ -20,4 +20,3 @@ declare const _default: {
20
20
  useColors(colorsToUse: import("@poppinss/colors/types").Colors): void;
21
21
  };
22
22
  export default _default;
23
- //# sourceMappingURL=helpers.d.ts.map
@@ -1,2 +1,10 @@
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 { cliui } from '@poppinss/cliui';
2
10
  export default cliui();
@@ -1,9 +1,20 @@
1
1
  import { Runner } from '../modules/core/main.js';
2
2
  import type { Config } from './types.js';
3
+ /**
4
+ * Exposes API for working with global hooks
5
+ */
3
6
  export declare class GlobalHooks {
4
7
  #private;
8
+ /**
9
+ * Apply hooks from the config
10
+ */
5
11
  apply(config: Required<Config>): void;
12
+ /**
13
+ * Perform setup
14
+ */
6
15
  setup(runner: Runner): Promise<void>;
16
+ /**
17
+ * Perform cleanup
18
+ */
7
19
  teardown(error: Error | null, runner: Runner): Promise<void>;
8
20
  }
9
- //# sourceMappingURL=hooks.d.ts.map
@@ -1,17 +1,37 @@
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 Hooks from '@poppinss/hooks';
10
+ /**
11
+ * Exposes API for working with global hooks
12
+ */
2
13
  export class GlobalHooks {
3
14
  #hooks = new Hooks();
4
15
  #setupRunner;
5
16
  #teardownRunner;
17
+ /**
18
+ * Apply hooks from the config
19
+ */
6
20
  apply(config) {
7
21
  config.setup.forEach((hook) => this.#hooks.add('setup', hook));
8
22
  config.teardown.forEach((hook) => this.#hooks.add('teardown', hook));
9
23
  }
24
+ /**
25
+ * Perform setup
26
+ */
10
27
  async setup(runner) {
11
28
  this.#setupRunner = this.#hooks.runner('setup');
12
29
  this.#teardownRunner = this.#hooks.runner('teardown');
13
30
  await this.#setupRunner.run(runner);
14
31
  }
32
+ /**
33
+ * Perform cleanup
34
+ */
15
35
  async teardown(error, runner) {
16
36
  if (this.#setupRunner) {
17
37
  await this.#setupRunner.cleanup(error, runner);
@@ -1,8 +1,16 @@
1
1
  /// <reference types="@types/node" resolution-mode="require"/>
2
2
  import type { Config, TestSuite } from './types.js';
3
+ /**
4
+ * The tests planner is used to plan the tests by doing all
5
+ * the heavy lifting of executing plugins, registering
6
+ * reporters, filtering tests and so on.
7
+ */
3
8
  export declare class Planner {
4
9
  #private;
5
10
  constructor(config: Required<Config>);
11
+ /**
12
+ * Creates a plan for running the tests
13
+ */
6
14
  plan(): Promise<{
7
15
  reporters: import("@japa/core/types").NamedReporterContract[];
8
16
  suites: (TestSuite & {
@@ -15,4 +23,3 @@ export declare class Planner {
15
23
  config: Required<Config>;
16
24
  }>;
17
25
  }
18
- //# sourceMappingURL=planner.d.ts.map
@@ -1,5 +1,18 @@
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 validator from './validator.js';
2
10
  import { FilesManager } from './files_manager.js';
11
+ /**
12
+ * The tests planner is used to plan the tests by doing all
13
+ * the heavy lifting of executing plugins, registering
14
+ * reporters, filtering tests and so on.
15
+ */
3
16
  export class Planner {
4
17
  #config;
5
18
  #fileManager = new FilesManager();
@@ -9,11 +22,19 @@ export class Planner {
9
22
  validator.validateSuitesForUniqueness(config);
10
23
  this.#config = config;
11
24
  }
25
+ /**
26
+ * Returns a list of reporters based upon the activated
27
+ * reporters list.
28
+ */
12
29
  #getActivatedReporters() {
13
30
  return this.#config.reporters.activated.map((activated) => {
14
31
  return this.#config.reporters.list.find(({ name }) => activated === name);
15
32
  });
16
33
  }
34
+ /**
35
+ * A generic method to collect files from the user defined
36
+ * files glob and apply the files filter
37
+ */
17
38
  async #collectFiles(files) {
18
39
  let filesURLs = await this.#fileManager.getFiles(this.#config.cwd, files);
19
40
  if (this.#config.filters.files && this.#config.filters.files.length) {
@@ -21,6 +42,10 @@ export class Planner {
21
42
  }
22
43
  return filesURLs;
23
44
  }
45
+ /**
46
+ * Returns a collection of suites and their associated
47
+ * test files by applying all the filters
48
+ */
24
49
  async #getSuites() {
25
50
  let suites = [];
26
51
  let suitesFilters = this.#config.filters.suites || [];
@@ -45,6 +70,9 @@ export class Planner {
45
70
  }
46
71
  return suites;
47
72
  }
73
+ /**
74
+ * Returns a list of filters to the passed to the refiner
75
+ */
48
76
  #getRefinerFilters() {
49
77
  return Object.keys(this.#config.filters).reduce((result, layer) => {
50
78
  if (layer === 'tests' || layer === 'tags' || layer === 'groups') {
@@ -53,6 +81,9 @@ export class Planner {
53
81
  return result;
54
82
  }, []);
55
83
  }
84
+ /**
85
+ * Creates a plan for running the tests
86
+ */
56
87
  async plan() {
57
88
  const suites = await this.#getSuites();
58
89
  const reporters = this.#getActivatedReporters();
@@ -1,8 +1,20 @@
1
1
  import type { PluginFn } from '../types.js';
2
+ /**
3
+ * Returns an object with the title of the tests failed during
4
+ * the last run.
5
+ */
2
6
  export declare function getFailedTests(): Promise<{
3
7
  tests?: string[];
4
8
  }>;
9
+ /**
10
+ * Writes failing tests to the cache directory
11
+ */
5
12
  export declare function cacheFailedTests(tests: string[]): Promise<void>;
13
+ /**
14
+ * Clears the cache dir
15
+ */
6
16
  export declare function clearCache(): Promise<void>;
17
+ /**
18
+ * Exposes the API to run failing tests using the "retry" CLI flag.
19
+ */
7
20
  export declare const retryPlugin: PluginFn;
8
- //# sourceMappingURL=retry.d.ts.map
@@ -1,9 +1,24 @@
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 { join } from 'node:path';
2
10
  import findCacheDirectory from 'find-cache-dir';
3
11
  import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
4
12
  import cliui from '../helpers.js';
13
+ /**
14
+ * Paths to the cache directory and the summary file
15
+ */
5
16
  const CACHE_DIR = findCacheDirectory({ name: '@japa/runner' });
6
17
  const SUMMARY_FILE = CACHE_DIR ? join(CACHE_DIR, 'summary.json') : undefined;
18
+ /**
19
+ * Returns an object with the title of the tests failed during
20
+ * the last run.
21
+ */
7
22
  export async function getFailedTests() {
8
23
  try {
9
24
  const summary = await readFile(SUMMARY_FILE, 'utf-8');
@@ -16,13 +31,22 @@ export async function getFailedTests() {
16
31
  throw new Error('Unable to read failed tests cache file', { cause: error });
17
32
  }
18
33
  }
34
+ /**
35
+ * Writes failing tests to the cache directory
36
+ */
19
37
  export async function cacheFailedTests(tests) {
20
38
  await mkdir(CACHE_DIR, { recursive: true });
21
39
  await writeFile(SUMMARY_FILE, JSON.stringify({ tests: tests }));
22
40
  }
41
+ /**
42
+ * Clears the cache dir
43
+ */
23
44
  export async function clearCache() {
24
45
  await unlink(SUMMARY_FILE);
25
46
  }
47
+ /**
48
+ * Exposes the API to run failing tests using the "retry" CLI flag.
49
+ */
26
50
  export const retryPlugin = async function retry({ config, cliArgs }) {
27
51
  if (!SUMMARY_FILE) {
28
52
  return;