ava 7.0.0 → 8.0.1

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 (61) hide show
  1. package/entrypoints/{eslint-plugin-helper.cjs → eslint-plugin-helper.js} +10 -13
  2. package/entrypoints/{internal.d.mts → internal.d.ts} +1 -1
  3. package/entrypoints/{main.d.mts → main.d.ts} +5 -5
  4. package/entrypoints/{main.mjs → main.js} +1 -1
  5. package/entrypoints/{plugin.d.cts → plugin.d.ts} +2 -2
  6. package/entrypoints/plugin.js +1 -0
  7. package/index.d.ts +2 -2
  8. package/lib/api-event-iterator.js +2 -2
  9. package/lib/api.js +6 -6
  10. package/lib/assert.js +6 -5
  11. package/lib/cli.js +7 -27
  12. package/lib/create-chain.js +68 -25
  13. package/lib/extensions.js +5 -7
  14. package/lib/fork.js +3 -3
  15. package/lib/{glob-helpers.cjs → glob-helpers.js} +16 -30
  16. package/lib/globs.js +3 -3
  17. package/lib/{ipc-flow-control.cjs → ipc-flow-control.js} +1 -4
  18. package/lib/load-config.js +2 -3
  19. package/lib/{now-and-timers.cjs → now-and-timers.js} +11 -8
  20. package/lib/pkg.js +1 -0
  21. package/lib/plugin-support/shared-worker-loader.js +2 -2
  22. package/lib/plugin-support/shared-workers.js +3 -3
  23. package/lib/provider-manager.js +6 -5
  24. package/lib/reporters/default.js +1 -1
  25. package/lib/reporters/improper-usage-messages.js +1 -1
  26. package/lib/reporters/tap.js +10 -4
  27. package/lib/runner.js +5 -5
  28. package/lib/scheduler.js +1 -1
  29. package/lib/snapshot-manager.js +43 -12
  30. package/lib/test.js +15 -8
  31. package/lib/watcher.js +10 -18
  32. package/lib/worker/base.js +17 -41
  33. package/lib/worker/{channel.cjs → channel.js} +21 -25
  34. package/lib/worker/completion-handlers.js +3 -3
  35. package/lib/worker/{guard-environment.cjs → guard-environment.js} +4 -5
  36. package/lib/worker/line-numbers.js +3 -7
  37. package/lib/worker/main.js +11 -0
  38. package/lib/worker/{options.cjs → options.js} +4 -5
  39. package/lib/worker/{plugin.cjs → plugin.js} +8 -10
  40. package/lib/worker/state.js +5 -0
  41. package/lib/worker/utils.js +5 -0
  42. package/package.json +30 -38
  43. package/plugin.d.ts +1 -1
  44. package/types/{test-fn.d.cts → test-fn.d.ts} +24 -3
  45. package/types/{try-fn.d.cts → try-fn.d.ts} +1 -2
  46. package/entrypoints/main.cjs +0 -2
  47. package/entrypoints/main.d.cts +0 -12
  48. package/entrypoints/plugin.cjs +0 -2
  49. package/entrypoints/plugin.d.mts +0 -6
  50. package/entrypoints/plugin.mjs +0 -4
  51. package/lib/module-types.js +0 -85
  52. package/lib/pkg.cjs +0 -2
  53. package/lib/slash.cjs +0 -36
  54. package/lib/worker/main.cjs +0 -12
  55. package/lib/worker/state.cjs +0 -6
  56. package/lib/worker/utils.cjs +0 -6
  57. /package/entrypoints/{cli.mjs → cli.js} +0 -0
  58. /package/types/{assertions.d.cts → assertions.d.ts} +0 -0
  59. /package/types/{shared-worker.d.cts → shared-worker.d.ts} +0 -0
  60. /package/types/{state-change-events.d.cts → state-change-events.d.ts} +0 -0
  61. /package/types/{subscribable.d.cts → subscribable.d.ts} +0 -0
@@ -1,11 +1,11 @@
1
- 'use strict';
2
- const events = require('node:events');
3
- const process = require('node:process');
4
- const {MessageChannel, threadId} = require('node:worker_threads');
1
+ import events from 'node:events';
2
+ import process from 'node:process';
3
+ import {MessageChannel, parentPort, threadId} from 'node:worker_threads';
5
4
 
6
- const timers = require('../now-and-timers.cjs');
5
+ import {controlFlow} from '../ipc-flow-control.js';
6
+ import {setTimeout as setTimeoutTimer} from '../now-and-timers.js';
7
7
 
8
- const {isRunningInChildProcess, isRunningInThread} = require('./utils.cjs');
8
+ import {isRunningInChildProcess, isRunningInThread} from './utils.js';
9
9
 
10
10
  const selectAvaMessage = async (channel, type) => {
11
11
  for await (const [message] of events.on(channel, 'message')) {
@@ -16,10 +16,6 @@ const selectAvaMessage = async (channel, type) => {
16
16
  };
17
17
 
18
18
  class RefCounter {
19
- constructor() {
20
- this.count = 0;
21
- }
22
-
23
19
  refAndTest() {
24
20
  return ++this.count === 1;
25
21
  }
@@ -27,6 +23,8 @@ class RefCounter {
27
23
  testAndUnref() {
28
24
  return this.count > 0 && --this.count === 0;
29
25
  }
26
+
27
+ count = 0;
30
28
  }
31
29
 
32
30
  class MessagePortHandle {
@@ -36,7 +34,7 @@ class MessagePortHandle {
36
34
  this.channel = port;
37
35
  // Referencing the port does not immediately prevent the thread from
38
36
  // exiting. Use a timer to keep a reference for at least a second.
39
- this.workaroundTimer = timers.setTimeout(() => {}, 1000).unref();
37
+ this.workaroundTimer = setTimeoutTimer(() => {}, 1000).unref();
40
38
  }
41
39
 
42
40
  forceUnref() {
@@ -94,10 +92,8 @@ class IpcHandle {
94
92
 
95
93
  let handle;
96
94
  if (isRunningInChildProcess) {
97
- const {controlFlow} = require('../ipc-flow-control.cjs');
98
95
  handle = new IpcHandle(controlFlow(process));
99
96
  } else if (isRunningInThread) {
100
- const {parentPort} = require('node:worker_threads');
101
97
  handle = new MessagePortHandle(parentPort);
102
98
  }
103
99
 
@@ -105,12 +101,14 @@ if (isRunningInChildProcess) {
105
101
  // Node.js. In order to keep track, explicitly reference before attaching.
106
102
  handle.ref();
107
103
 
108
- exports.options = selectAvaMessage(handle.channel, 'options').then(message => message.ava.options);
109
- exports.peerFailed = selectAvaMessage(handle.channel, 'peer-failed');
110
- exports.workerFreed = selectAvaMessage(handle.channel, 'free-worker');
111
- exports.send = handle.send.bind(handle);
112
- exports.ref = handle.ref.bind(handle);
113
- exports.unref = handle.unref.bind(handle);
104
+ /* eslint-disable unicorn/prefer-top-level-await */
105
+ export const options = selectAvaMessage(handle.channel, 'options').then(message => message.ava.options);
106
+ export const peerFailed = selectAvaMessage(handle.channel, 'peer-failed');
107
+ export const workerFreed = selectAvaMessage(handle.channel, 'free-worker');
108
+ /* eslint-enable unicorn/prefer-top-level-await */
109
+ export const send = handle.send.bind(handle);
110
+ export const ref = handle.ref.bind(handle);
111
+ export const unref = handle.unref.bind(handle);
114
112
 
115
113
  let channelCounter = 0;
116
114
  let messageCounter = 0;
@@ -138,7 +136,7 @@ function createChannelEmitter(channelId) {
138
136
  return [emitter, () => channelEmitters.delete(channelId)];
139
137
  }
140
138
 
141
- function registerSharedWorker(filename, initialData) {
139
+ export function registerSharedWorker(filename, initialData) {
142
140
  const channelId = `${threadId}/channel/${++channelCounter}`;
143
141
 
144
142
  const {port1: ourPort, port2: theirPort} = new MessageChannel();
@@ -160,9 +158,9 @@ function registerSharedWorker(filename, initialData) {
160
158
  // The attaching of message listeners will cause the port to be referenced by
161
159
  // Node.js. In order to keep track, explicitly reference before attaching.
162
160
  sharedWorkerHandle.ref();
163
- const ready = selectAvaMessage(ourPort, 'ready').then(() => { // eslint-disable-line promise/prefer-await-to-then
161
+ const ready = selectAvaMessage(ourPort, 'ready').then(() => {
164
162
  currentlyAvailable = error === null;
165
- }).finally(() => { // eslint-disable-line promise/prefer-await-to-then
163
+ }).finally(() => {
166
164
  // Once ready, it's up to user code to subscribe to messages, which (see
167
165
  // below) causes us to reference the port.
168
166
  sharedWorkerHandle.unref();
@@ -172,7 +170,7 @@ function registerSharedWorker(filename, initialData) {
172
170
 
173
171
  // Errors are received over the test worker channel, not the message port
174
172
  // dedicated to the shared worker.
175
- events.once(channelEmitter, 'shared-worker-error').then(() => { // eslint-disable-line promise/prefer-await-to-then
173
+ events.once(channelEmitter, 'shared-worker-error').then(() => {
176
174
  unsubscribe();
177
175
  sharedWorkerHandle.forceUnref();
178
176
  error = new Error('The shared worker is no longer available');
@@ -244,5 +242,3 @@ function registerSharedWorker(filename, initialData) {
244
242
  },
245
243
  };
246
244
  }
247
-
248
- exports.registerSharedWorker = registerSharedWorker;
@@ -1,13 +1,13 @@
1
1
  import process from 'node:process';
2
2
 
3
- import state from './state.cjs';
3
+ import {completionHandlers} from './state.js';
4
4
 
5
5
  export function runCompletionHandlers() {
6
- for (const handler of state.completionHandlers) {
6
+ for (const handler of completionHandlers) {
7
7
  process.nextTick(() => handler());
8
8
  }
9
9
  }
10
10
 
11
11
  export function registerCompletionHandler(handler) {
12
- state.completionHandlers.push(handler);
12
+ completionHandlers.push(handler);
13
13
  }
@@ -1,8 +1,7 @@
1
- 'use strict';
2
- const path = require('node:path');
3
- const process = require('node:process');
1
+ import path from 'node:path';
2
+ import process from 'node:process';
4
3
 
5
- const {isRunningInThread, isRunningInChildProcess} = require('./utils.cjs');
4
+ import {isRunningInThread, isRunningInChildProcess} from './utils.js';
6
5
 
7
6
  // Check if the test is being run without AVA cli
8
7
  if (!isRunningInChildProcess && !isRunningInThread) {
@@ -14,6 +13,6 @@ if (!isRunningInChildProcess && !isRunningInThread) {
14
13
 
15
14
  process.exit(1); // eslint-disable-line unicorn/no-process-exit
16
15
  } else {
17
- throw new Error('The ’ava’ module can only be imported in test files');
16
+ throw new Error('The \u2018ava\u2019 module can only be imported in test files');
18
17
  }
19
18
  }
@@ -1,16 +1,12 @@
1
1
  import * as fs from 'node:fs';
2
- import {createRequire, findSourceMap} from 'node:module';
2
+ import {findSourceMap} from 'node:module';
3
3
  import {pathToFileURL} from 'node:url';
4
4
 
5
+ import * as acorn from 'acorn';
6
+ import * as walk from 'acorn-walk';
5
7
  import callsites from 'callsites';
6
8
 
7
- const require = createRequire(import.meta.url);
8
-
9
9
  function parse(file) {
10
- // Avoid loading these until we actually need to select tests by line number.
11
- const acorn = require('acorn');
12
- const walk = require('acorn-walk');
13
-
14
10
  const ast = acorn.parse(fs.readFileSync(file, 'utf8'), {
15
11
  ecmaVersion: 'latest',
16
12
  locations: true,
@@ -0,0 +1,11 @@
1
+ import './guard-environment.js'; // eslint-disable-line import-x/no-unassigned-import
2
+
3
+ import assert from 'node:assert';
4
+
5
+ import {flags, refs} from './state.js';
6
+
7
+ assert.ok(refs.runnerChain);
8
+
9
+ flags.loadedMain = true;
10
+
11
+ export default refs.runnerChain;
@@ -1,17 +1,16 @@
1
- 'use strict';
2
1
  let options = null;
3
- exports.get = () => {
2
+ export function get() {
4
3
  if (!options) {
5
4
  throw new Error('Options have not yet been set');
6
5
  }
7
6
 
8
7
  return options;
9
- };
8
+ }
10
9
 
11
- exports.set = newOptions => {
10
+ export function set(newOptions) {
12
11
  if (options) {
13
12
  throw new Error('Options have already been set');
14
13
  }
15
14
 
16
15
  options = newOptions;
17
- };
16
+ }
@@ -1,10 +1,10 @@
1
- const pkg = require('../../package.json');
1
+ import pkg from '../pkg.js';
2
2
 
3
- const {registerSharedWorker: register} = require('./channel.cjs');
4
- const options = require('./options.cjs');
5
- const {sharedWorkerTeardowns, waitForReady} = require('./state.cjs');
3
+ import {registerSharedWorker as register} from './channel.js';
4
+ import {get as getOptions} from './options.js';
5
+ import {sharedWorkerTeardowns, waitForReady} from './state.js';
6
6
 
7
- require('./guard-environment.cjs'); // eslint-disable-line import-x/no-unassigned-import
7
+ import './guard-environment.js'; // eslint-disable-line import-x/no-unassigned-import
8
8
 
9
9
  const workers = new Map();
10
10
  const workerTeardownFns = new WeakMap();
@@ -83,13 +83,13 @@ function createSharedWorker(filename, initialData, teardown) {
83
83
  };
84
84
  }
85
85
 
86
- function registerSharedWorker({
86
+ export function registerSharedWorker({
87
87
  filename,
88
88
  initialData,
89
89
  supportedProtocols,
90
90
  teardown,
91
91
  }) {
92
- const options_ = options.get();
92
+ const options_ = getOptions();
93
93
 
94
94
  if (!options_.workerThreads) {
95
95
  throw new Error('Shared workers can be used only when worker threads are enabled');
@@ -108,7 +108,7 @@ function registerSharedWorker({
108
108
  // order. Any error will crash the worker.
109
109
  const teardownFns = workerTeardownFns.get(worker);
110
110
  if (teardownFns !== undefined) {
111
- for await (const fn of [...teardownFns].reverse()) {
111
+ for await (const fn of [...teardownFns].toReversed()) {
112
112
  await fn();
113
113
  }
114
114
  }
@@ -126,5 +126,3 @@ function registerSharedWorker({
126
126
 
127
127
  return worker;
128
128
  }
129
-
130
- exports.registerSharedWorker = registerSharedWorker;
@@ -0,0 +1,5 @@
1
+ export const flags = {loadedMain: false};
2
+ export const refs = {runnerChain: null};
3
+ export const completionHandlers = [];
4
+ export const sharedWorkerTeardowns = [];
5
+ export const waitForReady = [];
@@ -0,0 +1,5 @@
1
+ import process from 'node:process';
2
+ import {isMainThread} from 'node:worker_threads';
3
+
4
+ export const isRunningInThread = isMainThread === false;
5
+ export const isRunningInChildProcess = typeof process.send === 'function';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "7.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Node.js test runner that lets you develop with confidence.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,37 +9,25 @@
9
9
  },
10
10
  "homepage": "https://avajs.dev",
11
11
  "bin": {
12
- "ava": "entrypoints/cli.mjs"
12
+ "ava": "entrypoints/cli.js"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
16
- "import": {
17
- "types": "./entrypoints/main.d.mts",
18
- "default": "./entrypoints/main.mjs"
19
- },
20
- "require": {
21
- "types": "./entrypoints/main.d.cts",
22
- "default": "./entrypoints/main.cjs"
23
- }
16
+ "types": "./entrypoints/main.d.ts",
17
+ "default": "./entrypoints/main.js"
24
18
  },
25
- "./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.cjs",
19
+ "./eslint-plugin-helper": "./entrypoints/eslint-plugin-helper.js",
26
20
  "./plugin": {
27
- "import": {
28
- "types": "./entrypoints/plugin.d.mts",
29
- "default": "./entrypoints/plugin.mjs"
30
- },
31
- "require": {
32
- "types": "./entrypoints/plugin.d.cts",
33
- "default": "./entrypoints/plugin.cjs"
34
- }
21
+ "types": "./entrypoints/plugin.d.ts",
22
+ "default": "./entrypoints/plugin.js"
35
23
  },
36
24
  "./internal": {
37
- "types": "./entrypoints/internal.d.mts"
25
+ "types": "./entrypoints/internal.d.ts"
38
26
  }
39
27
  },
40
28
  "type": "module",
41
29
  "engines": {
42
- "node": "^20.19 || ^22.20 || ^24.12 || >=25"
30
+ "node": "^22.20 || ^24.12 || >=26"
43
31
  },
44
32
  "scripts": {
45
33
  "test": "./scripts/test.sh"
@@ -86,66 +74,70 @@
86
74
  "typescript"
87
75
  ],
88
76
  "dependencies": {
89
- "@vercel/nft": "^1.3.2",
77
+ "@vercel/nft": "^1.5.0",
90
78
  "acorn": "^8.16.0",
91
79
  "acorn-walk": "^8.3.5",
92
80
  "ansi-styles": "^6.2.3",
93
81
  "arrgv": "^1.0.2",
94
82
  "arrify": "^3.0.0",
95
83
  "callsites": "^4.2.0",
96
- "cbor": "^10.0.11",
84
+ "cbor2": "^2.3.0",
97
85
  "chalk": "^5.6.2",
98
86
  "chunkd": "^2.0.1",
99
87
  "ci-info": "^4.4.0",
100
88
  "ci-parallel-vars": "^1.0.1",
101
- "cli-truncate": "^5.1.1",
89
+ "cli-truncate": "^6.0.0",
102
90
  "code-excerpt": "^4.0.0",
103
91
  "common-path-prefix": "^3.0.0",
104
92
  "concordance": "^5.0.4",
105
93
  "currently-unhandled": "^0.4.1",
106
94
  "debug": "^4.4.3",
107
- "emittery": "^1.2.0",
95
+ "emittery": "^2.0.0",
108
96
  "figures": "^6.1.0",
109
- "globby": "^16.1.1",
97
+ "globby": "^16.2.0",
110
98
  "ignore-by-default": "^2.1.0",
111
99
  "indent-string": "^5.0.0",
112
100
  "is-plain-object": "^5.0.0",
113
101
  "is-promise": "^4.0.0",
114
102
  "matcher": "^6.0.0",
115
- "memoize": "^10.2.0",
103
+ "memoize": "^11.0.0",
116
104
  "ms": "^2.1.3",
117
105
  "p-map": "^7.0.4",
118
106
  "package-config": "^5.0.0",
119
- "picomatch": "^4.0.3",
107
+ "picomatch": "^4.0.4",
120
108
  "plur": "^6.0.0",
121
109
  "pretty-ms": "^9.3.0",
122
110
  "resolve-cwd": "^3.0.0",
111
+ "slash": "^5.1.0",
123
112
  "stack-utils": "^2.0.6",
124
113
  "supertap": "^3.0.1",
125
114
  "temp-dir": "^3.0.0",
126
- "write-file-atomic": "^7.0.0",
115
+ "write-file-atomic": "^7.0.1",
127
116
  "yargs": "^18.0.0"
128
117
  },
129
118
  "devDependencies": {
130
119
  "@ava/test": "github:avajs/test",
131
- "@ava/typescript": "^6.0.0",
120
+ "@ava/typescript": "^7.0.0",
132
121
  "@sindresorhus/tsconfig": "^8.1.0",
133
- "@types/node": "^24.10.15",
122
+ "@types/node": "^24.12.4",
134
123
  "ansi-escapes": "^7.3.0",
135
124
  "c8": "^11.0.0",
136
125
  "execa": "^9.6.1",
137
- "expect": "^30.2.0",
138
- "sinon": "^21.0.1",
139
- "tap": "^21.6.2",
126
+ "expect": "^30.4.1",
127
+ "sinon": "^22.0.0",
128
+ "tap": "^21.7.4",
140
129
  "tempy": "^3.2.0",
141
130
  "tsd": "^0.33.0",
142
- "typescript": "~5.9.3",
143
- "xo": "^1.2.3",
131
+ "typescript": "~6.0.3",
132
+ "xo": "^2.0.2",
144
133
  "zen-observable": "^0.10.0"
145
134
  },
146
135
  "overrides": {
147
136
  "c8": {
148
137
  "yargs": "^18.0.0"
138
+ },
139
+ "test-exclude": {
140
+ "glob": ">=13"
149
141
  }
150
142
  },
151
143
  "peerDependencies": {
@@ -157,7 +149,7 @@
157
149
  }
158
150
  },
159
151
  "volta": {
160
- "node": "24.14.0",
161
- "npm": "11.11.0"
152
+ "node": "24.15.0",
153
+ "npm": "11.14.1"
162
154
  }
163
155
  }
package/plugin.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // For compatibility with resolution algorithms other than Node16.
2
2
 
3
- export * from './entrypoints/plugin.cjs';
3
+ export * from './entrypoints/plugin.js';
@@ -1,6 +1,6 @@
1
- import type {Assertions} from './assertions.cjs';
2
- import type {Subscribable} from './subscribable.cjs';
3
- import type {TryFn} from './try-fn.cjs';
1
+ import type {Assertions} from './assertions.js';
2
+ import type {Subscribable} from './subscribable.js';
3
+ import type {TryFn} from './try-fn.js';
4
4
 
5
5
  /** The `t` value passed to test & hook implementations. */
6
6
  export type ExecutionContext<Context = unknown> = {
@@ -15,6 +15,7 @@ export type ExecutionContext<Context = unknown> = {
15
15
 
16
16
  readonly log: LogFn;
17
17
  readonly plan: PlanFn;
18
+ /** Declare a function to be run after the test has ended. */
18
19
  readonly teardown: TeardownFn;
19
20
  readonly timeout: TimeoutFn;
20
21
  readonly try: TryFn<Context>;
@@ -90,8 +91,13 @@ export type TestFn<Context = unknown> = {
90
91
  macro: MacroFn<Context>;
91
92
  meta: Meta;
92
93
  only: OnlyFn<Context>;
94
+ /** Declare a test that only runs when `condition` is true; otherwise the test is skipped. */
95
+ runIf: RunIfFn<TestFn<Context>>;
93
96
  serial: SerialFn<Context>;
94
97
  skip: SkipFn<Context>;
98
+ /** Declare a test that is skipped when `condition` is true. */
99
+ skipIf: SkipIfFn<TestFn<Context>>;
100
+ /** Declare a test that should be implemented later. */
95
101
  todo: TodoFn;
96
102
  };
97
103
 
@@ -158,7 +164,11 @@ export type FailingFn<Context = unknown> = {
158
164
  <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
159
165
 
160
166
  only: OnlyFn<Context>;
167
+ /** Declare a test that only runs when `condition` is true; otherwise the test is skipped. */
168
+ runIf: RunIfFn<FailingFn<Context>>;
161
169
  skip: SkipFn<Context>;
170
+ /** Declare a test that is skipped when `condition` is true. */
171
+ skipIf: SkipIfFn<FailingFn<Context>>;
162
172
  };
163
173
 
164
174
  export type HookSkipFn<Context = unknown> = {
@@ -183,6 +193,9 @@ export type OnlyFn<Context = unknown> = {
183
193
  <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
184
194
  };
185
195
 
196
+ /** Declare a test that only runs when `condition` is true; otherwise the test is skipped. */
197
+ export type RunIfFn<Chain> = (condition: boolean) => Chain;
198
+
186
199
  export type SerialFn<Context = unknown> = {
187
200
  /** Declare a serial test. Additional arguments are passed to the implementation or macro. */
188
201
  <Args extends unknown[]>(title: string, implementation: Implementation<Args, Context>, ...args: Args): void;
@@ -198,7 +211,12 @@ export type SerialFn<Context = unknown> = {
198
211
  beforeEach: BeforeFn<Context>;
199
212
  failing: FailingFn<Context>;
200
213
  only: OnlyFn<Context>;
214
+ /** Declare a test that only runs when `condition` is true; otherwise the test is skipped. */
215
+ runIf: RunIfFn<SerialFn<Context>>;
201
216
  skip: SkipFn<Context>;
217
+ /** Declare a test that is skipped when `condition` is true. */
218
+ skipIf: SkipIfFn<SerialFn<Context>>;
219
+ /** Declare a test that should be implemented later. */
202
220
  todo: TodoFn;
203
221
  };
204
222
 
@@ -210,6 +228,9 @@ export type SkipFn<Context = unknown> = {
210
228
  <Args extends unknown[]>(macro: Macro<Args, Context>, ...args: Args): void;
211
229
  };
212
230
 
231
+ /** Declare a test that is skipped when `condition` is true. */
232
+ export type SkipIfFn<Chain> = (condition: boolean) => Chain;
233
+
213
234
  /** Declare a test that should be implemented later. */
214
235
  export type TodoFn = (title: string) => void;
215
236
 
@@ -1,4 +1,4 @@
1
- import type {Implementation} from './test-fn.cjs';
1
+ import type {Implementation} from './test-fn.js';
2
2
 
3
3
  export type CommitDiscardOptions = {
4
4
  /**
@@ -55,4 +55,3 @@ export type TryFn<Context = unknown> = {
55
55
  */
56
56
  <Args extends unknown[]>(fn: Implementation<Args, Context>, ...args: Args): Promise<TryResult>;
57
57
  };
58
-
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- module.exports = require('../lib/worker/main.cjs');
@@ -1,12 +0,0 @@
1
- import type {TestFn} from '../types/test-fn.cjs';
2
-
3
- export type * from '../types/assertions.cjs';
4
- export type * from '../types/try-fn.cjs';
5
- export type * from '../types/test-fn.cjs';
6
- export type * from '../types/subscribable.cjs';
7
-
8
- /** Call to declare a test, or chain to declare hooks or test modifiers */
9
- declare const test: TestFn;
10
-
11
- /** Call to declare a test, or chain to declare hooks or test modifiers */
12
- export default test;
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- module.exports = require('../lib/worker/plugin.cjs');
@@ -1,6 +0,0 @@
1
- import type {SharedWorker} from '../types/shared-worker.cjs';
2
-
3
- export function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol<Data>;
4
- // Add overloads for additional protocols.
5
-
6
- export type {SharedWorker} from '../types/shared-worker.cjs';
@@ -1,4 +0,0 @@
1
- import * as plugin from '../lib/worker/plugin.cjs';
2
-
3
- const {registerSharedWorker} = plugin;
4
- export {registerSharedWorker};
@@ -1,85 +0,0 @@
1
- const requireTrueValue = value => {
2
- if (value !== true) {
3
- throw new TypeError('When specifying module types, use `true` for ’cjs’, ’mjs’ and ’js’ extensions');
4
- }
5
- };
6
-
7
- const normalize = (extension, type, defaultModuleType) => {
8
- switch (extension) {
9
- case 'cjs': {
10
- requireTrueValue(type);
11
- return 'commonjs';
12
- }
13
-
14
- case 'mjs': {
15
- requireTrueValue(type);
16
- return 'module';
17
- }
18
-
19
- case 'js': {
20
- requireTrueValue(type);
21
- return defaultModuleType;
22
- }
23
-
24
- default: {
25
- if (type !== 'commonjs' && type !== 'module') {
26
- throw new TypeError(`Module type for ’${extension}’ must be ’commonjs’ or ’module’`);
27
- }
28
-
29
- return type;
30
- }
31
- }
32
- };
33
-
34
- const deriveFromObject = (extensionsObject, defaultModuleType) => {
35
- const moduleTypes = {};
36
- for (const [extension, type] of Object.entries(extensionsObject)) {
37
- moduleTypes[extension] = normalize(extension, type, defaultModuleType);
38
- }
39
-
40
- return moduleTypes;
41
- };
42
-
43
- const deriveFromArray = (extensions, defaultModuleType) => {
44
- const moduleTypes = {};
45
- for (const extension of extensions) {
46
- switch (extension) {
47
- case 'cjs': {
48
- moduleTypes.cjs = 'commonjs';
49
- break;
50
- }
51
-
52
- case 'mjs': {
53
- moduleTypes.mjs = 'module';
54
- break;
55
- }
56
-
57
- case 'js': {
58
- moduleTypes.js = defaultModuleType;
59
- break;
60
- }
61
-
62
- default: {
63
- moduleTypes[extension] = 'commonjs';
64
- }
65
- }
66
- }
67
-
68
- return moduleTypes;
69
- };
70
-
71
- export default function moduleTypes(configuredExtensions, defaultModuleType) {
72
- if (configuredExtensions === undefined) {
73
- return {
74
- cjs: 'commonjs',
75
- mjs: 'module',
76
- js: defaultModuleType,
77
- };
78
- }
79
-
80
- if (Array.isArray(configuredExtensions)) {
81
- return deriveFromArray(configuredExtensions, defaultModuleType);
82
- }
83
-
84
- return deriveFromObject(configuredExtensions, defaultModuleType);
85
- }
package/lib/pkg.cjs DELETED
@@ -1,2 +0,0 @@
1
- 'use strict';
2
- module.exports = require('../package.json');