@japa/runner 1.2.0 → 2.0.2

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.
package/build/index.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { TestExecutor, ReporterContract } from '@japa/core';
2
2
  import { Test, TestContext, Group } from './src/Core';
3
- import { PluginFn, ConfigureOptions, RunnerHooksHandler, RunnerHooksCleanupHandler } from './src/Contracts';
4
- export { Test, TestContext, Group, PluginFn, RunnerHooksCleanupHandler, RunnerHooksHandler, ReporterContract, };
3
+ import { Config, PluginFn, RunnerHooksHandler, RunnerHooksCleanupHandler } from './src/Contracts';
4
+ export { Test, Config, Group, PluginFn, TestContext, ReporterContract, RunnerHooksHandler, RunnerHooksCleanupHandler, };
5
5
  /**
6
6
  * Configure the tests runner
7
7
  */
8
- export declare function configure(options: ConfigureOptions): void;
8
+ export declare function configure(options: Config): void;
9
9
  /**
10
10
  * Add a new test
11
11
  */
12
- export declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<TestContext, undefined>;
12
+ export declare function test(title: string, callback?: TestExecutor<TestContext, undefined>): Test<undefined>;
13
13
  export declare namespace test {
14
- var group: (title: string, callback: (group: Group<TestContext>) => void) => void;
14
+ var group: (title: string, callback: (group: Group) => void) => void;
15
15
  }
16
16
  /**
17
17
  * Run japa tests
@@ -29,4 +29,4 @@ export declare function run(): Promise<void>;
29
29
  * * --force-exit=Enable/disable force exit
30
30
  * * --timeout=Define timeout for all the tests
31
31
  */
32
- export declare function processCliArgs(argv: string[]): Partial<ConfigureOptions>;
32
+ export declare function processCliArgs(argv: string[]): Partial<Config>;
package/build/index.js CHANGED
@@ -11,7 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  return (mod && mod.__esModule) ? mod : { "default": mod };
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.processCliArgs = exports.run = exports.test = exports.configure = exports.Group = exports.TestContext = exports.Test = void 0;
14
+ exports.processCliArgs = exports.run = exports.test = exports.configure = exports.TestContext = exports.Group = exports.Test = void 0;
15
15
  const getopts_1 = __importDefault(require("getopts"));
16
16
  const path_1 = require("path");
17
17
  const fast_glob_1 = __importDefault(require("fast-glob"));
@@ -48,7 +48,7 @@ const emitter = new core_1.Emitter();
48
48
  /**
49
49
  * Active suite for tests
50
50
  */
51
- let activeSuite = new core_1.Suite('default', emitter);
51
+ let activeSuite = new Core_1.Suite('default', emitter);
52
52
  /**
53
53
  * Currently active group
54
54
  */
@@ -65,6 +65,23 @@ function ensureIsConfigured(message) {
65
65
  throw new Error(message);
66
66
  }
67
67
  }
68
+ /**
69
+ * Validate suites filter to ensure a wrong suite is not
70
+ * mentioned
71
+ */
72
+ function validateSuitesFilter() {
73
+ if (!('suites' in runnerOptions)) {
74
+ return;
75
+ }
76
+ if (!runnerOptions.filters.suites || !runnerOptions.filters.suites.length) {
77
+ return;
78
+ }
79
+ const suites = runnerOptions.suites.map(({ name }) => name);
80
+ const invalidSuites = runnerOptions.filters.suites.filter((suite) => !suites.includes(suite));
81
+ if (invalidSuites.length) {
82
+ throw new Error(`Unrecognized suite "${invalidSuites[0]}". Make sure to define it in the config first`);
83
+ }
84
+ }
68
85
  /**
69
86
  * End tests. We wait for the "beforeExit" event when
70
87
  * forceExit is not set to true
@@ -227,7 +244,7 @@ async function importFiles(files) {
227
244
  * Run japa tests
228
245
  */
229
246
  async function run() {
230
- const runner = new core_1.Runner(emitter);
247
+ const runner = new Core_1.Runner(emitter);
231
248
  runner.manageUnHandledExceptions();
232
249
  runner.onSuite(runnerOptions.configureSuite);
233
250
  const hooks = new hooks_1.Hooks();
@@ -244,6 +261,7 @@ async function run() {
244
261
  for (let plugin of runnerOptions.plugins) {
245
262
  await plugin(runnerOptions, runner, { Test: Core_1.Test, TestContext: Core_1.TestContext, Group: Core_1.Group });
246
263
  }
264
+ validateSuitesFilter();
247
265
  /**
248
266
  * Step 2: Notify runner about reporters
249
267
  */
@@ -268,8 +286,8 @@ async function run() {
268
286
  * as part of the default suite
269
287
  */
270
288
  if ('files' in runnerOptions && runnerOptions.files.length) {
271
- const files = await collectFiles(runnerOptions.files);
272
289
  globalTimeout = runnerOptions.timeout;
290
+ const files = await collectFiles(runnerOptions.files);
273
291
  runner.add(activeSuite);
274
292
  await importFiles(files);
275
293
  }
@@ -286,7 +304,10 @@ async function run() {
286
304
  else {
287
305
  globalTimeout = runnerOptions.timeout;
288
306
  }
289
- activeSuite = new core_1.Suite(suite.name, emitter);
307
+ activeSuite = new Core_1.Suite(suite.name, emitter);
308
+ if (typeof suite.configure === 'function') {
309
+ suite.configure(activeSuite);
310
+ }
290
311
  const files = await collectFiles(suite.files);
291
312
  runner.add(activeSuite);
292
313
  await importFiles(files);
@@ -359,7 +380,7 @@ exports.run = run;
359
380
  */
360
381
  function processCliArgs(argv) {
361
382
  const parsed = (0, getopts_1.default)(argv, {
362
- string: ['tests', 'tags', 'groups', 'ignoreTags', 'files', 'timeout', 'suites'],
383
+ string: ['tests', 'tags', 'groups', 'ignoreTags', 'files', 'timeout'],
363
384
  boolean: ['forceExit'],
364
385
  alias: {
365
386
  ignoreTags: 'ignore-tags',
@@ -376,13 +397,24 @@ function processCliArgs(argv) {
376
397
  processAsString(parsed, 'groups', (groups) => (config.filters.groups = groups));
377
398
  processAsString(parsed, 'tests', (tests) => (config.filters.tests = tests));
378
399
  processAsString(parsed, 'files', (files) => (config.filters.files = files));
379
- processAsString(parsed, 'suites', (suites) => (config.filters.suites = suites));
400
+ /**
401
+ * Get suites
402
+ */
403
+ if (parsed._.length) {
404
+ processAsString({ suites: parsed._ }, 'suites', (suites) => (config.filters.suites = suites));
405
+ }
406
+ /**
407
+ * Get timeout
408
+ */
380
409
  if (parsed.timeout) {
381
410
  const value = Number(parsed.timeout);
382
411
  if (!isNaN(value)) {
383
412
  config.timeout = value;
384
413
  }
385
414
  }
415
+ /**
416
+ * Get forceExit
417
+ */
386
418
  if (parsed.forceExit) {
387
419
  config.forceExit = true;
388
420
  }
@@ -1,13 +1,13 @@
1
- import { Runner, Refiner, FilteringOptions, ReporterContract, Suite } from '@japa/core';
2
- import { Test, Group, TestContext } from '../Core';
1
+ import { Refiner, FilteringOptions, ReporterContract } from '@japa/core';
2
+ import { Test, Group, TestContext, Runner, Suite } from '../Core';
3
3
  /**
4
4
  * The cleanup function for runner hooks
5
5
  */
6
- export declare type RunnerHooksCleanupHandler = (error: null | any, runner: Runner<TestContext>) => Promise<any> | any;
6
+ export declare type RunnerHooksCleanupHandler = (error: null | any, runner: Runner) => Promise<any> | any;
7
7
  /**
8
8
  * The function that can be registered as a runner hook
9
9
  */
10
- export declare type RunnerHooksHandler = (runner: Runner<TestContext>) => Promise<any> | any | RunnerHooksCleanupHandler | Promise<RunnerHooksCleanupHandler>;
10
+ export declare type RunnerHooksHandler = (runner: Runner) => Promise<any> | any | RunnerHooksCleanupHandler | Promise<RunnerHooksCleanupHandler>;
11
11
  /**
12
12
  * Allowed filters
13
13
  */
@@ -18,35 +18,41 @@ export declare type Filters = FilteringOptions & {
18
18
  /**
19
19
  * Shape of the plugin function
20
20
  */
21
- export declare type PluginFn = (config: Required<ConfigureOptions>, runner: Runner<TestContext>, classes: {
21
+ export declare type PluginFn = (config: Required<Config>, runner: Runner, classes: {
22
22
  Test: typeof Test;
23
23
  TestContext: typeof TestContext;
24
24
  Group: typeof Group;
25
25
  }) => void | Promise<void>;
26
+ /**
27
+ * Runner hooks
28
+ */
29
+ export declare type RunnerHooks = {
30
+ setup: RunnerHooksHandler[];
31
+ teardown: RunnerHooksHandler[];
32
+ };
26
33
  /**
27
34
  * Base configuration options
28
35
  */
29
- export declare type BaseConfigureOptions = {
36
+ export declare type BaseConfig = {
30
37
  timeout?: number;
31
38
  plugins?: PluginFn[];
32
39
  filters?: Filters;
33
- configureSuite?: (suite: Suite<TestContext>) => void;
34
- setup?: RunnerHooksHandler[];
35
- teardown?: RunnerHooksHandler[];
40
+ configureSuite?: (suite: Suite) => void;
36
41
  reporters?: ReporterContract[];
37
42
  importer?: (filePath: string) => void | Promise<void>;
38
43
  refiner?: Refiner;
39
44
  forceExit?: boolean;
40
- };
45
+ } & Partial<RunnerHooks>;
41
46
  /**
42
47
  * Configuration options
43
48
  */
44
- export declare type ConfigureOptions = BaseConfigureOptions & ({
49
+ export declare type Config = BaseConfig & ({
45
50
  files: string[] | (() => string[] | Promise<string[]>);
46
51
  } | {
47
52
  suites: {
48
53
  name: string;
49
54
  files: string | string[] | (() => string[] | Promise<string[]>);
55
+ configure?: (suite: Suite) => void;
50
56
  timeout?: number;
51
57
  }[];
52
58
  });
@@ -1,6 +1,14 @@
1
- import { Test, Group, TestContext as BaseTestContext } from '@japa/core';
1
+ import { DataSetNode, Test as BaseTest, Group as BaseGroup, Suite as BaseSuite, Runner as BaseRunner, TestContext as BaseTestContext } from '@japa/core';
2
2
  export declare class TestContext extends BaseTestContext {
3
- test: Test<TestContext, any>;
4
- constructor(test: Test<TestContext, any>);
3
+ test: Test;
4
+ constructor(test: Test);
5
+ }
6
+ export declare class Test<TestData extends DataSetNode = undefined> extends BaseTest<TestContext, TestData> {
7
+ static disposeCallbacks: never[];
8
+ }
9
+ export declare class Group extends BaseGroup<TestContext> {
10
+ }
11
+ export declare class Suite extends BaseSuite<TestContext> {
12
+ }
13
+ export declare class Runner extends BaseRunner<TestContext> {
5
14
  }
6
- export { Group, Test };
@@ -8,10 +8,8 @@
8
8
  * file that was distributed with this source code.
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Test = exports.Group = exports.TestContext = void 0;
11
+ exports.Runner = exports.Suite = exports.Group = exports.Test = exports.TestContext = void 0;
12
12
  const core_1 = require("@japa/core");
13
- Object.defineProperty(exports, "Test", { enumerable: true, get: function () { return core_1.Test; } });
14
- Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return core_1.Group; } });
15
13
  class TestContext extends core_1.TestContext {
16
14
  constructor(test) {
17
15
  super();
@@ -19,3 +17,16 @@ class TestContext extends core_1.TestContext {
19
17
  }
20
18
  }
21
19
  exports.TestContext = TestContext;
20
+ class Test extends core_1.Test {
21
+ }
22
+ exports.Test = Test;
23
+ Test.disposeCallbacks = [];
24
+ class Group extends core_1.Group {
25
+ }
26
+ exports.Group = Group;
27
+ class Suite extends core_1.Suite {
28
+ }
29
+ exports.Suite = Suite;
30
+ class Runner extends core_1.Runner {
31
+ }
32
+ exports.Runner = Runner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@japa/runner",
3
- "version": "1.2.0",
3
+ "version": "2.0.2",
4
4
  "description": "Runner for Japa testing framework",
5
5
  "main": "build/index.js",
6
6
  "files": [
@@ -41,7 +41,7 @@
41
41
  "cz-conventional-changelog": "^3.3.0",
42
42
  "del-cli": "^4.0.1",
43
43
  "eslint": "^8.10.0",
44
- "eslint-config-prettier": "^8.4.0",
44
+ "eslint-config-prettier": "^8.5.0",
45
45
  "eslint-plugin-adonis": "^2.1.0",
46
46
  "eslint-plugin-prettier": "^4.0.0",
47
47
  "github-label-sync": "^2.0.2",
@@ -50,7 +50,7 @@
50
50
  "mrm": "^3.0.10",
51
51
  "np": "^7.6.0",
52
52
  "prettier": "^2.5.1",
53
- "typescript": "^4.5.5"
53
+ "typescript": "^4.6.2"
54
54
  },
55
55
  "mrmConfig": {
56
56
  "core": false,
@@ -105,7 +105,7 @@
105
105
  "anyBranch": false
106
106
  },
107
107
  "dependencies": {
108
- "@japa/core": "^5.1.1",
108
+ "@japa/core": "^6.0.0",
109
109
  "@japa/errors-printer": "^1.3.3",
110
110
  "@poppinss/hooks": "^6.0.2-0",
111
111
  "fast-glob": "^3.2.11",