@vitest/runner 2.1.5 → 2.2.0-beta.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.
@@ -179,17 +179,20 @@ function partitionSuiteChildren(suite) {
179
179
  }
180
180
 
181
181
  function isAtomTest(s) {
182
+ return isTestCase(s);
183
+ }
184
+ function isTestCase(s) {
182
185
  return s.type === "test" || s.type === "custom";
183
186
  }
184
187
  function getTests(suite) {
185
188
  const tests = [];
186
189
  const arraySuites = toArray(suite);
187
190
  for (const s of arraySuites) {
188
- if (isAtomTest(s)) {
191
+ if (isTestCase(s)) {
189
192
  tests.push(s);
190
193
  } else {
191
194
  for (const task of s.tasks) {
192
- if (isAtomTest(task)) {
195
+ if (isTestCase(task)) {
193
196
  tests.push(task);
194
197
  } else {
195
198
  const taskTests = getTests(task);
@@ -204,7 +207,7 @@ function getTests(suite) {
204
207
  }
205
208
  function getTasks(tasks = []) {
206
209
  return toArray(tasks).flatMap(
207
- (s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]
210
+ (s) => isTestCase(s) ? [s] : [s, ...getTasks(s.tasks)]
208
211
  );
209
212
  }
210
213
  function getSuites(suite) {
@@ -214,7 +217,7 @@ function getSuites(suite) {
214
217
  }
215
218
  function hasTests(suite) {
216
219
  return toArray(suite).some(
217
- (s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c))
220
+ (s) => s.tasks.some((c) => isTestCase(c) || hasTests(c))
218
221
  );
219
222
  }
220
223
  function hasFailed(suite) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as BeforeAllListener, A as AfterAllListener, d as BeforeEachListener, e as AfterEachListener, f as TaskHook, O as OnTestFailedHandler, g as OnTestFinishedHandler, a as Test, C as Custom, S as Suite, h as SuiteHooks, T as Task, F as File, i as SuiteAPI, j as TestAPI, k as SuiteCollector } from './tasks-3ZnPj1LR.js';
2
- export { D as DoneCallback, E as ExtendedContext, l as Fixture, m as FixtureFn, n as FixtureOptions, o as Fixtures, H as HookCleanupCallback, p as HookListener, I as InferFixturesTypes, R as RunMode, q as RuntimeContext, r as SequenceHooks, s as SequenceSetupFiles, t as SuiteFactory, u as TaskBase, v as TaskContext, w as TaskCustomOptions, x as TaskMeta, y as TaskPopulated, z as TaskResult, G as TaskResultPack, J as TaskState, K as TestContext, L as TestFunction, M as TestOptions, U as Use } from './tasks-3ZnPj1LR.js';
1
+ import { B as BeforeAllListener, A as AfterAllListener, d as BeforeEachListener, e as AfterEachListener, f as TaskHook, O as OnTestFailedHandler, g as OnTestFinishedHandler, a as Test, C as Custom, S as Suite, h as SuiteHooks, T as Task, F as File, i as SuiteAPI, j as TestAPI, k as SuiteCollector } from './tasks-CgWT5bp6.js';
2
+ export { D as DoneCallback, E as ExtendedContext, l as Fixture, m as FixtureFn, n as FixtureOptions, o as Fixtures, H as HookCleanupCallback, p as HookListener, I as InferFixturesTypes, R as RunMode, q as RuntimeContext, r as SequenceHooks, s as SequenceSetupFiles, t as SuiteFactory, u as TaskBase, v as TaskContext, w as TaskCustomOptions, x as TaskMeta, y as TaskPopulated, z as TaskResult, G as TaskResultPack, J as TaskState, K as TestContext, L as TestFunction, M as TestOptions, U as Use } from './tasks-CgWT5bp6.js';
3
3
  import { Awaitable } from '@vitest/utils';
4
4
  import { VitestRunner } from './types.js';
5
5
  export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@ export { processError } from '@vitest/utils/error';
6
6
  import 'pathe';
7
7
 
8
8
  class PendingError extends Error {
9
- constructor(message, task) {
9
+ constructor(message, task, note) {
10
10
  super(message);
11
11
  this.message = message;
12
+ this.note = note;
12
13
  this.taskId = task.id;
13
14
  }
14
15
  code = "VITEST_PENDING";
@@ -54,9 +55,9 @@ function createTestContext(test, runner) {
54
55
  throw new Error("done() callback is deprecated, use promise instead");
55
56
  };
56
57
  context.task = test;
57
- context.skip = () => {
58
+ context.skip = (note) => {
58
59
  test.pending = true;
59
- throw new PendingError("test is skipped; abort execution", test);
60
+ throw new PendingError("test is skipped; abort execution", test, note);
60
61
  };
61
62
  context.onTestFailed = (fn) => {
62
63
  test.onFailed || (test.onFailed = []);
@@ -95,14 +96,15 @@ function getHooks(key) {
95
96
  return hooksMap.get(key);
96
97
  }
97
98
 
98
- function mergeContextFixtures(fixtures, context = {}) {
99
- const fixtureOptionKeys = ["auto"];
99
+ function mergeContextFixtures(fixtures, context, inject) {
100
+ const fixtureOptionKeys = ["auto", "injected"];
100
101
  const fixtureArray = Object.entries(fixtures).map(
101
102
  ([prop, value]) => {
102
103
  const fixtureItem = { value };
103
104
  if (Array.isArray(value) && value.length >= 2 && isObject(value[1]) && Object.keys(value[1]).some((key) => fixtureOptionKeys.includes(key))) {
104
105
  Object.assign(fixtureItem, value[1]);
105
- fixtureItem.value = value[0];
106
+ const userValue = value[0];
107
+ fixtureItem.value = fixtureItem.injected ? inject(prop) ?? userValue : userValue;
106
108
  }
107
109
  fixtureItem.prop = prop;
108
110
  fixtureItem.isFn = typeof fixtureItem.value === "function";
@@ -401,7 +403,7 @@ function createSuiteCollector(name, factory = () => {
401
403
  each: options.each,
402
404
  fails: options.fails,
403
405
  context: void 0,
404
- type: "custom",
406
+ type: "test",
405
407
  file: void 0,
406
408
  retry: options.retry ?? runner.config.retry,
407
409
  repeats: options.repeats,
@@ -666,7 +668,14 @@ function createTaskCollector(fn, context) {
666
668
  return condition ? this : this.skip;
667
669
  };
668
670
  taskFn.extend = function(fixtures) {
669
- const _context = mergeContextFixtures(fixtures, context);
671
+ const _context = mergeContextFixtures(
672
+ fixtures,
673
+ context || {},
674
+ (key) => {
675
+ var _a, _b;
676
+ return (_b = (_a = getRunner()).injectValue) == null ? void 0 : _b.call(_a, key);
677
+ }
678
+ );
670
679
  return createTest(function fn2(name, optionsOrFn, optionsOrTest) {
671
680
  getCurrentSuite().test.fn.call(
672
681
  this,
@@ -1008,7 +1017,7 @@ async function callCleanupHooks(cleanups) {
1008
1017
  );
1009
1018
  }
1010
1019
  async function runTest(test, runner) {
1011
- var _a, _b, _c, _d, _e, _f, _g;
1020
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1012
1021
  await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
1013
1022
  if (test.mode !== "run") {
1014
1023
  return;
@@ -1071,13 +1080,13 @@ async function runTest(test, runner) {
1071
1080
  }
1072
1081
  if (test.pending || ((_e = test.result) == null ? void 0 : _e.state) === "skip") {
1073
1082
  test.mode = "skip";
1074
- test.result = { state: "skip" };
1083
+ test.result = { state: "skip", note: (_f = test.result) == null ? void 0 : _f.note };
1075
1084
  updateTask(test, runner);
1076
1085
  setCurrentTest(void 0);
1077
1086
  return;
1078
1087
  }
1079
1088
  try {
1080
- await ((_f = runner.onTaskFinished) == null ? void 0 : _f.call(runner, test));
1089
+ await ((_g = runner.onTaskFinished) == null ? void 0 : _g.call(runner, test));
1081
1090
  } catch (e) {
1082
1091
  failTask(test.result, e, runner.config.diffOptions);
1083
1092
  }
@@ -1124,12 +1133,13 @@ async function runTest(test, runner) {
1124
1133
  }
1125
1134
  setCurrentTest(void 0);
1126
1135
  test.result.duration = now() - start;
1127
- await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
1136
+ await ((_h = runner.onAfterRunTask) == null ? void 0 : _h.call(runner, test));
1128
1137
  updateTask(test, runner);
1129
1138
  }
1130
1139
  function failTask(result, err, diffOptions) {
1131
1140
  if (err instanceof PendingError) {
1132
1141
  result.state = "skip";
1142
+ result.note = err.note;
1133
1143
  return;
1134
1144
  }
1135
1145
  result.state = "fail";
@@ -3,6 +3,10 @@ import { ErrorWithDiff, Awaitable } from '@vitest/utils';
3
3
  interface FixtureItem extends FixtureOptions {
4
4
  prop: string;
5
5
  value: any;
6
+ /**
7
+ * Indicated if the injected value should be preferred over the fixture value
8
+ */
9
+ injected?: boolean;
6
10
  /**
7
11
  * Indicates whether the fixture is a function
8
12
  */
@@ -162,6 +166,8 @@ interface TaskResult {
162
166
  * `repeats` option is set. This number also contains `retryCount`.
163
167
  */
164
168
  repeatCount?: number;
169
+ /** @private */
170
+ note?: string;
165
171
  }
166
172
  /**
167
173
  * The tuple representing a single task update.
@@ -228,14 +234,23 @@ interface Test<ExtraContext = object> extends TaskPopulated {
228
234
  */
229
235
  context: TaskContext<Test> & ExtraContext & TestContext;
230
236
  }
237
+ /**
238
+ * @deprecated Use `Test` instead. `type: 'custom'` is not used since 2.2
239
+ */
231
240
  interface Custom<ExtraContext = object> extends TaskPopulated {
241
+ /**
242
+ * @deprecated use `test` instead. `custom` is not used since 2.2
243
+ */
232
244
  type: 'custom';
233
245
  /**
234
246
  * Task context that will be passed to the test function.
235
247
  */
236
- context: TaskContext<Custom> & ExtraContext & TestContext;
248
+ context: TaskContext<Test> & ExtraContext & TestContext;
237
249
  }
238
250
  type Task = Test | Suite | Custom | File;
251
+ /**
252
+ * @deprecated Vitest doesn't provide `done()` anymore
253
+ */
239
254
  type DoneCallback = (error?: any) => void;
240
255
  type TestFunction<ExtraContext = object> = (context: ExtendedContext<Test> & ExtraContext) => Awaitable<any> | void;
241
256
  type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
@@ -384,10 +399,10 @@ interface AfterAllListener {
384
399
  (suite: Readonly<Suite | File>): Awaitable<unknown>;
385
400
  }
386
401
  interface BeforeEachListener<ExtraContext = object> {
387
- (context: ExtendedContext<Test | Custom> & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
402
+ (context: ExtendedContext<Test> & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
388
403
  }
389
404
  interface AfterEachListener<ExtraContext = object> {
390
- (context: ExtendedContext<Test | Custom> & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
405
+ (context: ExtendedContext<Test> & ExtraContext, suite: Readonly<Suite>): Awaitable<unknown>;
391
406
  }
392
407
  interface SuiteHooks<ExtraContext = object> {
393
408
  beforeAll: BeforeAllListener[];
@@ -413,7 +428,7 @@ interface TaskCustomOptions extends TestOptions {
413
428
  * If nothing is provided, the runner will try to get the function using `getFn(task)`.
414
429
  * If the runner cannot find the function, the task will be marked as failed.
415
430
  */
416
- handler?: (context: TaskContext<Custom>) => Awaitable<void>;
431
+ handler?: (context: TaskContext<Test>) => Awaitable<void>;
417
432
  }
418
433
  interface SuiteCollector<ExtraContext = object> {
419
434
  readonly name: string;
@@ -422,7 +437,7 @@ interface SuiteCollector<ExtraContext = object> {
422
437
  type: 'collector';
423
438
  test: TestAPI<ExtraContext>;
424
439
  tasks: (Suite | Custom<ExtraContext> | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
425
- task: (name: string, options?: TaskCustomOptions) => Custom<ExtraContext>;
440
+ task: (name: string, options?: TaskCustomOptions) => Test<ExtraContext>;
426
441
  collect: (file: File) => Promise<Suite>;
427
442
  clear: () => void;
428
443
  on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
@@ -440,7 +455,7 @@ interface TestContext {
440
455
  /**
441
456
  * Context that's always available in the test function.
442
457
  */
443
- interface TaskContext<Task extends Custom | Test = Custom | Test> {
458
+ interface TaskContext<Task extends Test = Test> {
444
459
  /**
445
460
  * Metadata of the current test
446
461
  */
@@ -457,9 +472,9 @@ interface TaskContext<Task extends Custom | Test = Custom | Test> {
457
472
  * Mark tests as skipped. All execution after this call will be skipped.
458
473
  * This function throws an error, so make sure you are not catching it accidentally.
459
474
  */
460
- skip: () => void;
475
+ skip: (note?: string) => void;
461
476
  }
462
- type ExtendedContext<T extends Custom | Test> = TaskContext<T> & TestContext;
477
+ type ExtendedContext<T extends Test> = TaskContext<T> & TestContext;
463
478
  type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
464
479
  type OnTestFinishedHandler = (result: TaskResult) => Awaitable<void>;
465
480
  interface TaskHook<HookListener> {
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DiffOptions } from '@vitest/utils/diff';
2
- import { r as SequenceHooks, s as SequenceSetupFiles, F as File, T as Task, a as Test, C as Custom, S as Suite, G as TaskResultPack, v as TaskContext, E as ExtendedContext } from './tasks-3ZnPj1LR.js';
3
- export { A as AfterAllListener, e as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, j as CustomAPI, D as DoneCallback, l as Fixture, m as FixtureFn, n as FixtureOptions, o as Fixtures, H as HookCleanupCallback, p as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, g as OnTestFinishedHandler, R as RunMode, q as RuntimeContext, i as SuiteAPI, k as SuiteCollector, t as SuiteFactory, h as SuiteHooks, u as TaskBase, w as TaskCustomOptions, f as TaskHook, x as TaskMeta, y as TaskPopulated, z as TaskResult, J as TaskState, j as TestAPI, K as TestContext, L as TestFunction, M as TestOptions, U as Use } from './tasks-3ZnPj1LR.js';
2
+ import { r as SequenceHooks, s as SequenceSetupFiles, F as File, T as Task, a as Test, C as Custom, S as Suite, G as TaskResultPack, v as TaskContext, E as ExtendedContext } from './tasks-CgWT5bp6.js';
3
+ export { A as AfterAllListener, e as AfterEachListener, B as BeforeAllListener, d as BeforeEachListener, j as CustomAPI, D as DoneCallback, l as Fixture, m as FixtureFn, n as FixtureOptions, o as Fixtures, H as HookCleanupCallback, p as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, g as OnTestFinishedHandler, R as RunMode, q as RuntimeContext, i as SuiteAPI, k as SuiteCollector, t as SuiteFactory, h as SuiteHooks, u as TaskBase, w as TaskCustomOptions, f as TaskHook, x as TaskMeta, y as TaskPopulated, z as TaskResult, J as TaskState, j as TestAPI, K as TestContext, L as TestFunction, M as TestOptions, U as Use } from './tasks-CgWT5bp6.js';
4
4
  import '@vitest/utils';
5
5
 
6
6
  /**
@@ -118,11 +118,15 @@ interface VitestRunner {
118
118
  *
119
119
  * @see https://vitest.dev/advanced/runner.html#your-task-function
120
120
  */
121
- extendTaskContext?: <T extends Test | Custom>(context: TaskContext<T>) => ExtendedContext<T>;
121
+ extendTaskContext?: <T extends Test>(context: TaskContext<T>) => ExtendedContext<T>;
122
122
  /**
123
123
  * Called when test and setup files are imported. Can be called in two situations: when collecting tests and when importing setup files.
124
124
  */
125
125
  importFile: (filepath: string, source: VitestRunnerImportSource) => unknown;
126
+ /**
127
+ * Function that is called when the runner attempts to get the value when `test.extend` is used with `{ injected: true }`
128
+ */
129
+ injectValue?: (key: string) => unknown;
126
130
  /**
127
131
  * Publicly available configuration.
128
132
  */
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-3ZnPj1LR.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-3ZnPj1LR.js';
1
+ import { S as Suite, F as File, T as Task, a as Test, C as Custom } from './tasks-CgWT5bp6.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-CgWT5bp6.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
@@ -21,6 +21,9 @@ declare function limitConcurrency(concurrency?: number): <Args extends unknown[]
21
21
  */
22
22
  declare function partitionSuiteChildren(suite: Suite): Task[][];
23
23
 
24
+ /**
25
+ * @deprecated use `isTestCase` instead
26
+ */
24
27
  declare function isAtomTest(s: Task): s is Test | Custom;
25
28
  declare function getTests(suite: Arrayable<Task>): (Test | Custom)[];
26
29
  declare function getTasks(tasks?: Arrayable<Task>): Task[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "2.1.5",
4
+ "version": "2.2.0-beta.2",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "pathe": "^1.1.2",
42
- "@vitest/utils": "2.1.5"
42
+ "@vitest/utils": "2.2.0-beta.2"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",