@vitest/runner 2.1.4 → 2.2.0-beta.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.
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-F_411-nA.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-F_411-nA.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";
@@ -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,
@@ -924,15 +933,23 @@ function getSuiteHooks(suite, name, sequence) {
924
933
  }
925
934
  return hooks;
926
935
  }
927
- async function callTaskHooks(task, hooks, sequence) {
936
+ async function callTestHooks(runner, task, hooks, sequence) {
928
937
  if (sequence === "stack") {
929
938
  hooks = hooks.slice().reverse();
930
939
  }
931
940
  if (sequence === "parallel") {
932
- await Promise.all(hooks.map((fn) => fn(task.result)));
941
+ try {
942
+ await Promise.all(hooks.map((fn) => fn(task.result)));
943
+ } catch (e) {
944
+ failTask(task.result, e, runner.config.diffOptions);
945
+ }
933
946
  } else {
934
947
  for (const fn of hooks) {
935
- await fn(task.result);
948
+ try {
949
+ await fn(task.result);
950
+ } catch (e) {
951
+ failTask(task.result, e, runner.config.diffOptions);
952
+ }
936
953
  }
937
954
  }
938
955
  }
@@ -1000,7 +1017,7 @@ async function callCleanupHooks(cleanups) {
1000
1017
  );
1001
1018
  }
1002
1019
  async function runTest(test, runner) {
1003
- var _a, _b, _c, _d, _e, _f, _g;
1020
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1004
1021
  await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
1005
1022
  if (test.mode !== "run") {
1006
1023
  return;
@@ -1063,13 +1080,13 @@ async function runTest(test, runner) {
1063
1080
  }
1064
1081
  if (test.pending || ((_e = test.result) == null ? void 0 : _e.state) === "skip") {
1065
1082
  test.mode = "skip";
1066
- test.result = { state: "skip" };
1083
+ test.result = { state: "skip", note: (_f = test.result) == null ? void 0 : _f.note };
1067
1084
  updateTask(test, runner);
1068
1085
  setCurrentTest(void 0);
1069
1086
  return;
1070
1087
  }
1071
1088
  try {
1072
- await ((_f = runner.onTaskFinished) == null ? void 0 : _f.call(runner, test));
1089
+ await ((_g = runner.onTaskFinished) == null ? void 0 : _g.call(runner, test));
1073
1090
  } catch (e) {
1074
1091
  failTask(test.result, e, runner.config.diffOptions);
1075
1092
  }
@@ -1083,21 +1100,14 @@ async function runTest(test, runner) {
1083
1100
  } catch (e) {
1084
1101
  failTask(test.result, e, runner.config.diffOptions);
1085
1102
  }
1086
- try {
1087
- await callTaskHooks(test, test.onFinished || [], "stack");
1088
- } catch (e) {
1089
- failTask(test.result, e, runner.config.diffOptions);
1090
- }
1103
+ await callTestHooks(runner, test, test.onFinished || [], "stack");
1091
1104
  if (test.result.state === "fail") {
1092
- try {
1093
- await callTaskHooks(
1094
- test,
1095
- test.onFailed || [],
1096
- runner.config.sequence.hooks
1097
- );
1098
- } catch (e) {
1099
- failTask(test.result, e, runner.config.diffOptions);
1100
- }
1105
+ await callTestHooks(
1106
+ runner,
1107
+ test,
1108
+ test.onFailed || [],
1109
+ runner.config.sequence.hooks
1110
+ );
1101
1111
  }
1102
1112
  delete test.onFailed;
1103
1113
  delete test.onFinished;
@@ -1123,12 +1133,13 @@ async function runTest(test, runner) {
1123
1133
  }
1124
1134
  setCurrentTest(void 0);
1125
1135
  test.result.duration = now() - start;
1126
- await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
1136
+ await ((_h = runner.onAfterRunTask) == null ? void 0 : _h.call(runner, test));
1127
1137
  updateTask(test, runner);
1128
1138
  }
1129
1139
  function failTask(result, err, diffOptions) {
1130
1140
  if (err instanceof PendingError) {
1131
1141
  result.state = "skip";
1142
+ result.note = err.note;
1132
1143
  return;
1133
1144
  }
1134
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.
@@ -457,7 +463,7 @@ interface TaskContext<Task extends Custom | Test = Custom | Test> {
457
463
  * Mark tests as skipped. All execution after this call will be skipped.
458
464
  * This function throws an error, so make sure you are not catching it accidentally.
459
465
  */
460
- skip: () => void;
466
+ skip: (note?: string) => void;
461
467
  }
462
468
  type ExtendedContext<T extends Custom | Test> = TaskContext<T> & TestContext;
463
469
  type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
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-F_411-nA.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-F_411-nA.js';
4
4
  import '@vitest/utils';
5
5
 
6
6
  /**
@@ -123,6 +123,10 @@ interface VitestRunner {
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-F_411-nA.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-F_411-nA.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "2.1.4",
4
+ "version": "2.2.0-beta.1",
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.4"
42
+ "@vitest/utils": "2.2.0-beta.1"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "rimraf dist && rollup -c",