@japa/runner 2.5.0 → 3.0.0-0

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 (54) hide show
  1. package/LICENSE.md +1 -1
  2. package/build/index.d.ts +8 -29
  3. package/build/index.js +95 -458
  4. package/build/src/cli_parser.d.ts +6 -0
  5. package/build/src/cli_parser.d.ts.map +1 -0
  6. package/build/src/cli_parser.js +49 -0
  7. package/build/src/config_manager.d.ts +7 -0
  8. package/build/src/config_manager.d.ts.map +1 -0
  9. package/build/src/config_manager.js +115 -0
  10. package/build/src/create_test.d.ts +16 -0
  11. package/build/src/create_test.d.ts.map +1 -0
  12. package/build/src/create_test.js +33 -0
  13. package/build/src/debug.d.ts +4 -0
  14. package/build/src/debug.d.ts.map +1 -0
  15. package/build/src/debug.js +2 -0
  16. package/build/src/exceptions_manager.d.ts +7 -0
  17. package/build/src/exceptions_manager.d.ts.map +1 -0
  18. package/build/src/exceptions_manager.js +58 -0
  19. package/build/src/files_manager.d.ts +7 -0
  20. package/build/src/files_manager.d.ts.map +1 -0
  21. package/build/src/files_manager.js +28 -0
  22. package/build/src/helpers.d.ts +23 -0
  23. package/build/src/helpers.d.ts.map +1 -0
  24. package/build/src/helpers.js +2 -0
  25. package/build/src/hooks.d.ts +9 -0
  26. package/build/src/hooks.d.ts.map +1 -0
  27. package/build/src/hooks.js +26 -0
  28. package/build/src/planner.d.ts +18 -0
  29. package/build/src/planner.d.ts.map +1 -0
  30. package/build/src/planner.js +67 -0
  31. package/build/src/plugins/retry.d.ts +8 -0
  32. package/build/src/plugins/retry.d.ts.map +1 -0
  33. package/build/src/plugins/retry.js +42 -0
  34. package/build/src/reporters/dot.d.ts +7 -0
  35. package/build/src/reporters/dot.d.ts.map +1 -0
  36. package/build/src/reporters/dot.js +24 -0
  37. package/build/src/reporters/main.d.ts +5 -0
  38. package/build/src/reporters/main.d.ts.map +1 -0
  39. package/build/src/reporters/main.js +21 -0
  40. package/build/src/reporters/ndjson.d.ts +12 -0
  41. package/build/src/reporters/ndjson.d.ts.map +1 -0
  42. package/build/src/reporters/ndjson.js +61 -0
  43. package/build/src/reporters/spec.d.ts +11 -0
  44. package/build/src/reporters/spec.d.ts.map +1 -0
  45. package/build/src/reporters/spec.js +103 -0
  46. package/build/src/types.d.ts +48 -49
  47. package/build/src/types.d.ts.map +1 -0
  48. package/build/src/types.js +1 -10
  49. package/build/src/validator.d.ts +11 -0
  50. package/build/src/validator.d.ts.map +1 -0
  51. package/build/src/validator.js +46 -0
  52. package/package.json +77 -83
  53. package/build/src/core/main.d.ts +0 -32
  54. package/build/src/core/main.js +0 -65
@@ -0,0 +1,12 @@
1
+ import { BaseReporter } from '../../modules/core/main.js';
2
+ import type { TestEndNode, SuiteEndNode, GroupEndNode, SuiteStartNode, GroupStartNode } from '../../modules/core/types.js';
3
+ export declare class NdJSONReporter extends BaseReporter {
4
+ #private;
5
+ protected onTestEnd(payload: TestEndNode): void;
6
+ protected onGroupStart(payload: GroupStartNode): void;
7
+ protected onGroupEnd(payload: GroupEndNode): void;
8
+ protected onSuiteStart(payload: SuiteStartNode): void;
9
+ protected onSuiteEnd(payload: SuiteEndNode): void;
10
+ protected end(): Promise<void>;
11
+ }
12
+ //# sourceMappingURL=ndjson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson.d.ts","sourceRoot":"","sources":["../../../src/reporters/ndjson.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,cAAc,EACf,MAAM,6BAA6B,CAAA;AAMpC,qBAAa,cAAe,SAAQ,YAAY;;IAQ9C,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAuB/C,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IASrD,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAQjD,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IASrD,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;cASjC,GAAG;CAWpB"}
@@ -0,0 +1,61 @@
1
+ import { relative } from 'node:path';
2
+ import { BaseReporter } from '../../modules/core/main.js';
3
+ export class NdJSONReporter extends BaseReporter {
4
+ #getRelativeFilename(fileName) {
5
+ return relative(process.cwd(), fileName);
6
+ }
7
+ onTestEnd(payload) {
8
+ console.log(JSON.stringify({
9
+ event: 'test:end',
10
+ filePath: this.currentFileName,
11
+ relativePath: this.currentFileName
12
+ ? this.#getRelativeFilename(this.currentFileName)
13
+ : undefined,
14
+ title: payload.title,
15
+ duration: payload.duration,
16
+ failReason: payload.failReason,
17
+ isFailing: payload.isFailing,
18
+ skipReason: payload.skipReason,
19
+ isSkipped: payload.isSkipped,
20
+ isTodo: payload.isTodo,
21
+ isPinned: payload.isPinned,
22
+ retryAttempt: payload.retryAttempt,
23
+ retries: payload.retries,
24
+ errors: payload.errors,
25
+ }));
26
+ }
27
+ onGroupStart(payload) {
28
+ console.log(JSON.stringify({
29
+ event: 'group:start',
30
+ title: payload.title,
31
+ }));
32
+ }
33
+ onGroupEnd(payload) {
34
+ JSON.stringify({
35
+ event: 'group:end',
36
+ title: payload.title,
37
+ errors: payload.errors,
38
+ });
39
+ }
40
+ onSuiteStart(payload) {
41
+ console.log(JSON.stringify({
42
+ event: 'suite:start',
43
+ ...payload,
44
+ }));
45
+ }
46
+ onSuiteEnd(payload) {
47
+ console.log(JSON.stringify({
48
+ event: 'suite:end',
49
+ ...payload,
50
+ }));
51
+ }
52
+ async end() {
53
+ const summary = this.runner.getSummary();
54
+ console.log(JSON.stringify({
55
+ aggregates: summary.aggregates,
56
+ duration: summary.duration,
57
+ failedTestsTitles: summary.failedTestsTitles,
58
+ hasError: summary.hasError,
59
+ }));
60
+ }
61
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseReporter } from '../../modules/core/main.js';
2
+ import { GroupStartNode, TestEndNode } from '../../modules/core/types.js';
3
+ export declare class SpecReporter extends BaseReporter {
4
+ #private;
5
+ protected onTestStart(): void;
6
+ protected onTestEnd(payload: TestEndNode): void;
7
+ protected onGroupStart(payload: GroupStartNode): void;
8
+ protected onGroupEnd(): void;
9
+ protected end(): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spec.d.ts","sourceRoot":"","sources":["../../../src/reporters/spec.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAKzE,qBAAa,YAAa,SAAQ,YAAY;;IA8H5C,SAAS,CAAC,WAAW,IAAI,IAAI;IAc7B,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IAI/C,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IASrD,SAAS,CAAC,UAAU,IAAI,IAAI;cAWZ,GAAG;CAIpB"}
@@ -0,0 +1,103 @@
1
+ import ms from 'ms';
2
+ import { relative } from 'node:path';
3
+ import cliui from '../helpers.js';
4
+ import { BaseReporter } from '../../modules/core/main.js';
5
+ export class SpecReporter extends BaseReporter {
6
+ #isFirstLoneTest = true;
7
+ #getTestIcon(payload) {
8
+ if (payload.isTodo) {
9
+ return cliui.colors.cyan(cliui.icons.info);
10
+ }
11
+ if (payload.isFailing) {
12
+ return payload.hasError
13
+ ? cliui.colors.magenta(cliui.icons.squareSmallFilled)
14
+ : cliui.colors.red(cliui.icons.cross);
15
+ }
16
+ if (payload.hasError) {
17
+ return cliui.colors.red(cliui.icons.cross);
18
+ }
19
+ if (payload.isSkipped) {
20
+ return cliui.colors.yellow(cliui.icons.bullet);
21
+ }
22
+ return cliui.colors.green(cliui.icons.tick);
23
+ }
24
+ #getTestMessage(payload) {
25
+ const message = typeof payload.title === 'string' ? payload.title : payload.title.expanded;
26
+ if (payload.isTodo) {
27
+ return cliui.colors.blue(message);
28
+ }
29
+ if (payload.isFailing) {
30
+ return payload.hasError ? cliui.colors.magenta(message) : cliui.colors.red(message);
31
+ }
32
+ if (payload.hasError) {
33
+ return cliui.colors.red(message);
34
+ }
35
+ if (payload.isSkipped) {
36
+ return cliui.colors.yellow(message);
37
+ }
38
+ return cliui.colors.grey(message);
39
+ }
40
+ #getSubText(payload) {
41
+ if (payload.isSkipped && payload.skipReason) {
42
+ return cliui.colors.yellow(payload.skipReason);
43
+ }
44
+ if (!payload.isFailing) {
45
+ return;
46
+ }
47
+ if (!payload.hasError) {
48
+ return cliui.colors.magenta(`Test marked with ".fails()" must finish with an error`);
49
+ }
50
+ if (payload.failReason) {
51
+ return cliui.colors.magenta(payload.failReason);
52
+ }
53
+ const testErrorMessage = payload.errors.find((error) => error.phase === 'test');
54
+ if (testErrorMessage && testErrorMessage.error) {
55
+ return cliui.colors.magenta(testErrorMessage.error.message);
56
+ }
57
+ }
58
+ #getRelativeFilename(fileName) {
59
+ return relative(process.cwd(), fileName);
60
+ }
61
+ #printTest(payload) {
62
+ const icon = this.#getTestIcon(payload);
63
+ const message = this.#getTestMessage(payload);
64
+ const prefix = payload.isPinned ? cliui.colors.yellow('[PINNED] ') : '';
65
+ const indentation = this.currentFileName || this.currentGroupName ? ' ' : '';
66
+ const duration = cliui.colors.dim(`(${ms(payload.duration)})`);
67
+ const retries = payload.retryAttempt && payload.retryAttempt > 1
68
+ ? cliui.colors.dim(`(x${payload.retryAttempt}) `)
69
+ : '';
70
+ let subText = this.#getSubText(payload);
71
+ subText = subText ? `\n${indentation} ${subText}` : '';
72
+ console.log(`${indentation}${icon} ${prefix}${retries}${message} ${duration}${subText}`);
73
+ }
74
+ #printGroup(payload) {
75
+ const title = this.currentSuiteName !== 'default'
76
+ ? `${this.currentSuiteName} / ${payload.title}`
77
+ : payload.title;
78
+ const suffix = this.currentFileName
79
+ ? cliui.colors.dim(` (${this.#getRelativeFilename(this.currentFileName)})`)
80
+ : '';
81
+ console.log(`\n${title}${suffix}`);
82
+ }
83
+ onTestStart() {
84
+ if (this.currentFileName && this.#isFirstLoneTest) {
85
+ console.log(`\n${cliui.colors.dim(this.#getRelativeFilename(this.currentFileName))}`);
86
+ }
87
+ this.#isFirstLoneTest = false;
88
+ }
89
+ onTestEnd(payload) {
90
+ this.#printTest(payload);
91
+ }
92
+ onGroupStart(payload) {
93
+ this.#isFirstLoneTest = false;
94
+ this.#printGroup(payload);
95
+ }
96
+ onGroupEnd() {
97
+ this.#isFirstLoneTest = true;
98
+ }
99
+ async end() {
100
+ const summary = this.runner.getSummary();
101
+ await this.printSummary(summary);
102
+ }
103
+ }
@@ -1,68 +1,67 @@
1
- import { Refiner, FilteringOptions, ReporterContract } from '@japa/core';
2
- import { Test, Group, TestContext, Runner, Suite } from './core/main';
3
- /**
4
- * The cleanup function for runner hooks
5
- */
6
- export declare type RunnerHooksCleanupHandler = (error: null | any, runner: Runner) => Promise<any> | any;
7
- /**
8
- * The function that can be registered as a runner hook
9
- */
10
- export declare type RunnerHooksHandler = (runner: Runner) => Promise<any> | any | RunnerHooksCleanupHandler | Promise<RunnerHooksCleanupHandler>;
11
- /**
12
- * Allowed filters
13
- */
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
+ import type { HookHandler } from '@poppinss/hooks/types';
3
+ import type { Emitter, Refiner, Runner, Suite } from '../modules/core/main.js';
4
+ import type { FilteringOptions, NamedReporterContract } from '../modules/core/types.js';
5
+ export * from '../modules/core/types.js';
6
+ export type SetupHookState = [[runner: Runner], [error: Error | null, runner: Runner]];
7
+ export type SetupHookHandler = HookHandler<SetupHookState[0], SetupHookState[1]>;
8
+ export type TeardownHookState = [[runner: Runner], [error: Error | null, runner: Runner]];
9
+ export type TeardownHookHandler = HookHandler<TeardownHookState[0], TeardownHookState[1]>;
10
+ export type HooksEvents = {
11
+ setup: SetupHookState;
12
+ teardown: TeardownHookState;
13
+ };
14
+ export type CLIArgs = {
15
+ _?: string[];
16
+ tags?: string | string[];
17
+ files?: string | string[];
18
+ tests?: string | string[];
19
+ groups?: string | string[];
20
+ timeout?: string;
21
+ retries?: string;
22
+ reporter?: string | string[];
23
+ forceExit?: boolean;
24
+ help?: boolean;
25
+ matchAll?: boolean;
26
+ } & Record<string, string | string[] | boolean>;
14
27
  export type Filters = FilteringOptions & {
15
28
  files?: string[];
16
29
  suites?: string[];
17
30
  };
18
- /**
19
- * Shape of the plugin function
20
- */
21
- export type PluginFn = (config: Required<Config>, runner: Runner, classes: {
22
- Test: typeof Test;
23
- TestContext: typeof TestContext;
24
- Group: typeof Group;
31
+ export type PluginFn = (japa: {
32
+ config: Required<Config>;
33
+ cliArgs: CLIArgs;
34
+ runner: Runner;
35
+ emitter: Emitter;
25
36
  }) => void | Promise<void>;
26
- /**
27
- * Runner hooks
28
- */
29
- export type RunnerHooks = {
30
- setup: RunnerHooksHandler[];
31
- teardown: RunnerHooksHandler[];
32
- };
33
- /**
34
- * Base configuration options
35
- */
36
37
  export type BaseConfig = {
37
- cliArgs?: Record<string, any>;
38
38
  cwd?: string;
39
39
  timeout?: number;
40
- plugins?: PluginFn[];
40
+ retries?: number;
41
41
  filters?: Filters;
42
42
  configureSuite?: (suite: Suite) => void;
43
- reporters?: ReporterContract[];
44
- importer?: (filePath: string) => void | Promise<void>;
43
+ reporters?: {
44
+ activated: string[];
45
+ list: NamedReporterContract[];
46
+ };
47
+ plugins?: PluginFn[];
48
+ importer?: (filePath: URL) => void | Promise<void>;
45
49
  refiner?: Refiner;
46
50
  forceExit?: boolean;
47
- } & Partial<RunnerHooks>;
48
- /**
49
- * Type for the "config.files" property
50
- */
51
- export type ConfigFiles = string[] | (() => string[] | Promise<string[]>);
52
- /**
53
- * Type for the "config.suite" property
54
- */
55
- export type ConfigSuite = {
51
+ setup?: SetupHookHandler[];
52
+ teardown?: TeardownHookHandler[];
53
+ };
54
+ export type TestFiles = string | string[] | (() => URL[] | Promise<URL[]>);
55
+ export type TestSuite = {
56
56
  name: string;
57
- files: string | string[] | (() => string[] | Promise<string[]>);
57
+ files: TestFiles;
58
58
  configure?: (suite: Suite) => void;
59
59
  timeout?: number;
60
+ retries?: number;
60
61
  };
61
- /**
62
- * Configuration options
63
- */
64
62
  export type Config = BaseConfig & ({
65
- files: ConfigFiles;
63
+ files: TestFiles;
66
64
  } | {
67
- suites: ConfigSuite[];
65
+ suites: TestSuite[];
68
66
  });
67
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AACvF,cAAc,0BAA0B,CAAA;AAKxC,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AACtF,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;AAKhF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AACzF,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;AAKzF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,cAAc,CAAA;IACrB,QAAQ,EAAE,iBAAiB,CAAA;CAC5B,CAAA;AAKD,MAAM,MAAM,OAAO,GAAG;IACpB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,CAAA;AAK/C,MAAM,MAAM,OAAO,GAAG,gBAAgB,GAAG;IACvC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAMD,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE;IAC5B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAK1B,MAAM,MAAM,UAAU,GAAG;IAKvB,GAAG,CAAC,EAAE,MAAM,CAAA;IAKZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAKhB,OAAO,CAAC,EAAE,MAAM,CAAA;IAKhB,OAAO,CAAC,EAAE,OAAO,CAAA;IAMjB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAOvC,SAAS,CAAC,EAAE;QACV,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,IAAI,EAAE,qBAAqB,EAAE,CAAA;KAC9B,CAAA;IAKD,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAA;IAKpB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAMlD,OAAO,CAAC,EAAE,OAAO,CAAA;IAKjB,SAAS,CAAC,EAAE,OAAO,CAAA;IAMnB,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAK1B,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAA;CACjC,CAAA;AAMD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;AAK1E,MAAM,MAAM,SAAS,GAAG;IAItB,IAAI,EAAE,MAAM,CAAA;IAMZ,KAAK,EAAE,SAAS,CAAA;IAMhB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAKlC,OAAO,CAAC,EAAE,MAAM,CAAA;IAKhB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAKD,MAAM,MAAM,MAAM,GAAG,UAAU,GAC7B,CACI;IACE,KAAK,EAAE,SAAS,CAAA;CACjB,GACD;IACE,MAAM,EAAE,SAAS,EAAE,CAAA;CACpB,CACJ,CAAA"}
@@ -1,10 +1 @@
1
- "use strict";
2
- /*
3
- * @japa/runner
4
- *
5
- * (c) Japa.dev
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export * from '../modules/core/types.js';
@@ -0,0 +1,11 @@
1
+ import { Config } from './types.js';
2
+ declare class Validator {
3
+ ensureIsConfigured(config: Required<Config> | undefined): void;
4
+ ensureIsInPlanningPhase(phase: 'idle' | 'planning' | 'executing'): void;
5
+ validateSuitesFilter(config: Required<Config>): void;
6
+ validateSuitesForUniqueness(config: Required<Config>): void;
7
+ validateActivatedReporters(config: Required<Config>): void;
8
+ }
9
+ declare const _default: Validator;
10
+ export default _default;
11
+ //# sourceMappingURL=validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMnC,cAAM,SAAS;IAIb,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS;IAWvD,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW;IAWhE,oBAAoB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IA+B7C,2BAA2B,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;IAoBpD,0BAA0B,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;CAYpD;;AAED,wBAA8B"}
@@ -0,0 +1,46 @@
1
+ class Validator {
2
+ ensureIsConfigured(config) {
3
+ if (!config) {
4
+ throw new Error(`Cannot run tests. Make sure to call "configure" method before the "run" method`);
5
+ }
6
+ }
7
+ ensureIsInPlanningPhase(phase) {
8
+ if (phase !== 'planning') {
9
+ throw new Error(`Cannot import japa test file directly. It must be imported by calling the "japa.run" method`);
10
+ }
11
+ }
12
+ validateSuitesFilter(config) {
13
+ if (!config.filters.suites || !config.filters.suites.length) {
14
+ return;
15
+ }
16
+ if (!('suites' in config) || !config.suites.length) {
17
+ throw new Error(`Cannot apply suites filter. You have not configured any test suites`);
18
+ }
19
+ const suites = config.suites.map(({ name }) => name);
20
+ const unknownSuites = config.filters.suites.filter((suite) => !suites.includes(suite));
21
+ if (unknownSuites.length) {
22
+ throw new Error(`Cannot apply suites filter. "${unknownSuites[0]}" suite is not configured`);
23
+ }
24
+ }
25
+ validateSuitesForUniqueness(config) {
26
+ if (!('suites' in config)) {
27
+ return;
28
+ }
29
+ const suites = new Set();
30
+ config.suites.forEach(({ name }) => {
31
+ if (suites.has(name)) {
32
+ throw new Error(`Duplicate suite "${name}"`);
33
+ }
34
+ suites.add(name);
35
+ });
36
+ suites.clear();
37
+ }
38
+ validateActivatedReporters(config) {
39
+ const reportersList = config.reporters.list.map(({ name }) => name);
40
+ const unknownReporters = config.reporters.activated.filter((name) => !reportersList.includes(name));
41
+ if (unknownReporters.length) {
42
+ throw new Error(`Invalid reporter "${unknownReporters[0]}". Make sure to register it first inside the "reporters.list" array`);
43
+ }
44
+ }
45
+ }
46
+ export default new Validator();
package/package.json CHANGED
@@ -1,30 +1,38 @@
1
1
  {
2
2
  "name": "@japa/runner",
3
- "version": "2.5.0",
3
+ "version": "3.0.0-0",
4
4
  "description": "Runner for Japa testing framework",
5
5
  "main": "build/index.js",
6
+ "type": "module",
6
7
  "files": [
7
8
  "build/src",
8
9
  "build/index.d.ts",
9
10
  "build/index.js"
10
11
  ],
12
+ "engines": {
13
+ "node": ">=18.16.0"
14
+ },
11
15
  "exports": {
12
- ".": "./build/index.js"
16
+ ".": "./build/index.js",
17
+ "./types": "./build/src/types.js",
18
+ "./reporters": "./build/src/reporters/main.js",
19
+ "./factories": "./build/factories/main.js",
20
+ "./core": "./build/modules/core/main.js"
13
21
  },
14
22
  "scripts": {
15
- "mrm": "mrm --preset=@adonisjs/mrm-preset",
16
23
  "pretest": "npm run lint",
17
- "test": "node .bin/test.js",
18
- "clean": "del-cli build",
24
+ "test": "cross-env NODE_ENV=japa:runner c8 npm run quick:test",
25
+ "quick:test": "glob -c \"node --enable-source-maps --loader=ts-node/esm --test\" \"tests/*.spec.ts\"",
26
+ "clean": "del build",
27
+ "typecheck": "tsc --noEmit",
19
28
  "compile": "npm run lint && npm run clean && tsc",
20
29
  "build": "npm run compile",
30
+ "release": "np",
21
31
  "prepublishOnly": "npm run build",
22
32
  "lint": "eslint . --ext=.ts",
23
33
  "format": "prettier --write .",
24
- "commit": "git-cz",
25
- "release": "np --message=\"chore(release): %s\"",
26
34
  "version": "npm run build",
27
- "sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json japa/runner"
35
+ "sync-labels": "github-label-sync --labels .github/labels.json japa/runner"
28
36
  },
29
37
  "keywords": [
30
38
  "japa",
@@ -34,88 +42,42 @@
34
42
  "author": "virk,japa",
35
43
  "license": "MIT",
36
44
  "devDependencies": {
37
- "@adonisjs/mrm-preset": "^5.0.3",
45
+ "@adonisjs/eslint-config": "^1.1.5",
46
+ "@adonisjs/prettier-config": "^1.1.5",
38
47
  "@adonisjs/require-ts": "^2.0.13",
39
- "@types/node": "^18.14.0",
40
- "commitizen": "^4.3.0",
41
- "cz-conventional-changelog": "^3.3.0",
48
+ "@adonisjs/tsconfig": "^1.1.5",
49
+ "@commitlint/cli": "^17.6.6",
50
+ "@commitlint/config-conventional": "^17.6.6",
51
+ "@swc/core": "^1.3.66",
52
+ "@types/chai": "^4.3.5",
53
+ "@types/chai-subset": "^1.3.3",
54
+ "@types/find-cache-dir": "^3.2.1",
55
+ "@types/ms": "^0.7.31",
56
+ "@types/node": "^20.3.2",
57
+ "c8": "^8.0.0",
58
+ "chai": "^4.3.7",
59
+ "chai-subset": "^1.6.0",
60
+ "cross-env": "^7.0.3",
42
61
  "del-cli": "^5.0.0",
43
- "eslint": "^8.33.0",
44
- "eslint-config-prettier": "^8.6.0",
45
- "eslint-plugin-adonis": "^2.1.1",
46
- "eslint-plugin-prettier": "^4.2.1",
47
- "github-label-sync": "^2.2.0",
62
+ "eslint": "^8.36.0",
63
+ "github-label-sync": "^2.3.1",
64
+ "glob": "^10.3.0",
48
65
  "husky": "^8.0.3",
49
66
  "japa": "^4.0.0",
50
- "mrm": "^4.1.13",
51
- "np": "^7.6.3",
52
- "prettier": "^2.8.4",
53
- "typescript": "^4.9.5"
54
- },
55
- "mrmConfig": {
56
- "core": false,
57
- "license": "MIT",
58
- "services": [
59
- "github-actions"
60
- ],
61
- "minNodeVersion": "16.13.1",
62
- "probotApps": [
63
- "stale",
64
- "lock"
65
- ],
66
- "runGhActionsOnWindows": true
67
- },
68
- "eslintConfig": {
69
- "extends": [
70
- "plugin:adonis/typescriptPackage",
71
- "prettier"
72
- ],
73
- "plugins": [
74
- "prettier"
75
- ],
76
- "rules": {
77
- "prettier/prettier": [
78
- "error",
79
- {
80
- "endOfLine": "auto"
81
- }
82
- ]
83
- }
84
- },
85
- "eslintIgnore": [
86
- "build"
87
- ],
88
- "prettier": {
89
- "trailingComma": "es5",
90
- "semi": false,
91
- "singleQuote": true,
92
- "useTabs": false,
93
- "quoteProps": "consistent",
94
- "bracketSpacing": true,
95
- "arrowParens": "always",
96
- "printWidth": 100
97
- },
98
- "config": {
99
- "commitizen": {
100
- "path": "cz-conventional-changelog"
101
- }
102
- },
103
- "np": {
104
- "contents": ".",
105
- "anyBranch": false
67
+ "np": "^8.0.4",
68
+ "prettier": "^2.8.8",
69
+ "ts-node": "^10.9.1",
70
+ "typescript": "^5.1.3"
106
71
  },
107
72
  "dependencies": {
108
- "@japa/core": "^7.3.1",
109
- "@japa/errors-printer": "^2.1.0",
110
- "@poppinss/cliui": "^3.0.5",
111
- "@poppinss/hooks": "^6.0.2-0",
73
+ "@japa/core": "^8.0.0-6",
74
+ "@japa/errors-printer": "^3.0.0-4",
75
+ "@poppinss/cliui": "^6.1.1-2",
76
+ "@poppinss/hooks": "^7.1.1-3",
112
77
  "fast-glob": "^3.2.12",
78
+ "find-cache-dir": "^4.0.0",
113
79
  "getopts": "^2.3.0",
114
- "inclusion": "^1.0.1"
115
- },
116
- "publishConfig": {
117
- "access": "public",
118
- "tag": "latest"
80
+ "ms": "^2.1.3"
119
81
  },
120
82
  "directories": {
121
83
  "test": "test"
@@ -127,5 +89,37 @@
127
89
  "bugs": {
128
90
  "url": "https://github.com/japa/runner/issues"
129
91
  },
130
- "homepage": "https://github.com/japa/runner#readme"
92
+ "homepage": "https://github.com/japa/runner#readme",
93
+ "publishConfig": {
94
+ "access": "public",
95
+ "tag": "next"
96
+ },
97
+ "np": {
98
+ "message": "chore(release): %s",
99
+ "tag": "next",
100
+ "branch": "main",
101
+ "anyBranch": false
102
+ },
103
+ "commitlint": {
104
+ "extends": [
105
+ "@commitlint/config-conventional"
106
+ ]
107
+ },
108
+ "prettier": "@adonisjs/prettier-config",
109
+ "eslintConfig": {
110
+ "extends": "@adonisjs/eslint-config/package"
111
+ },
112
+ "c8": {
113
+ "reporter": [
114
+ "text",
115
+ "html"
116
+ ],
117
+ "exclude": [
118
+ "tests/**",
119
+ "tests_helpers/**",
120
+ "factories/**",
121
+ "modules/core/**",
122
+ "src/reporters/**"
123
+ ]
124
+ }
131
125
  }
@@ -1,32 +0,0 @@
1
- import { DataSetNode, Test as BaseTest, Group as BaseGroup, Suite as BaseSuite, Runner as BaseRunner, TestHooksCleanupHandler, TestContext as BaseTestContext } from '@japa/core';
2
- export declare class TestContext extends BaseTestContext {
3
- test: Test;
4
- /**
5
- * Methods to call after the test context instance
6
- * is created
7
- */
8
- static createdCallbacks: ((context: TestContext) => void)[];
9
- /**
10
- * Register a function to get notified when an instance of test
11
- * context is created. The callback must be synchronous
12
- */
13
- static created(callback: (context: TestContext) => void): typeof TestContext;
14
- /**
15
- * Register a cleanup function. Cleanup functions are called after
16
- * the test finishes
17
- */
18
- cleanup: (handler: TestHooksCleanupHandler<this>) => void;
19
- constructor(test: Test);
20
- }
21
- export declare class Test<TestData extends DataSetNode = undefined> extends BaseTest<TestContext, TestData> {
22
- static disposeCallbacks: never[];
23
- }
24
- export declare class Group extends BaseGroup<TestContext> {
25
- }
26
- export declare class Suite extends BaseSuite<TestContext> {
27
- onGroup(callback: (group: Group) => void): this;
28
- onTest(callback: (test: Test<any>) => void): this;
29
- }
30
- export declare class Runner extends BaseRunner<TestContext> {
31
- onSuite(callback: (suite: Suite) => void): this;
32
- }