@vitest/runner 0.31.1 → 0.31.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.
@@ -90,8 +90,8 @@ function processError(err, options = {}) {
90
90
  err.stackStr = String(err.stack);
91
91
  if (err.name)
92
92
  err.nameStr = String(err.name);
93
- const clonedActual = deepClone(err.actual);
94
- const clonedExpected = deepClone(err.expected);
93
+ const clonedActual = deepClone(err.actual, { forceWritable: true });
94
+ const clonedExpected = deepClone(err.expected, { forceWritable: true });
95
95
  const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
96
96
  if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0)
97
97
  err.diff = unifiedDiff(replacedActual, replacedExpected, options);
@@ -238,6 +238,9 @@ function createChainable(keys, fn) {
238
238
  };
239
239
  Object.assign(chain2, fn);
240
240
  chain2.withContext = () => chain2.bind(context);
241
+ chain2.setContext = (key, value) => {
242
+ context[key] = value;
243
+ };
241
244
  for (const key of keys) {
242
245
  Object.defineProperty(chain2, key, {
243
246
  get() {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { V as VitestRunner } from './runner-a2cd0770.js';
2
- export { C as CancelReason, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-a2cd0770.js';
3
- import { T as Task, F as File, S as SuiteAPI, a as TestAPI, b as SuiteCollector, c as SuiteHooks, O as OnTestFailedHandler, d as Test } from './tasks-891047e7.js';
4
- export { D as DoneCallback, m as HookCleanupCallback, H as HookListener, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, n as SuiteFactory, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-891047e7.js';
1
+ import { V as VitestRunner } from './runner-6af7d148.js';
2
+ export { C as CancelReason, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-6af7d148.js';
3
+ import { T as Task, F as File, S as SuiteAPI, a as TestAPI, b as SuiteCollector, c as SuiteHooks, O as OnTestFailedHandler, d as Test } from './tasks-900f5000.js';
4
+ export { D as DoneCallback, n as HookCleanupCallback, H as HookListener, R as RunMode, p as RuntimeContext, r as SequenceHooks, s as SequenceSetupFiles, k as Suite, o as SuiteFactory, f as TaskBase, h as TaskCustom, g as TaskMeta, i as TaskResult, j as TaskResultPack, e as TaskState, q as TestContext, l as TestFunction, m as TestOptions } from './tasks-900f5000.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
 
7
7
  declare function updateTask(task: Task, runner: VitestRunner): void;
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ function createTestContext(test, runner) {
54
54
  throw new Error("done() callback is deprecated, use promise instead");
55
55
  };
56
56
  context.meta = test;
57
+ context.task = test;
57
58
  context.onTestFailed = (fn) => {
58
59
  test.onFailed || (test.onFailed = []);
59
60
  test.onFailed.push(fn);
@@ -65,7 +66,7 @@ function makeTimeoutMsg(isHook, timeout) {
65
66
  If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
66
67
  }
67
68
 
68
- var version = "0.31.1";
69
+ var version = "0.31.2";
69
70
 
70
71
  function getVersion() {
71
72
  return globalThis.__vitest_runner_version__ || version;
@@ -121,7 +122,7 @@ function createSuiteHooks() {
121
122
  };
122
123
  }
123
124
  function createSuiteCollector(name, factory = () => {
124
- }, mode, concurrent, shuffle, suiteOptions) {
125
+ }, mode, concurrent, shuffle, each, suiteOptions) {
125
126
  const tasks = [];
126
127
  const factoryQueue = [];
127
128
  let suite2;
@@ -134,6 +135,7 @@ function createSuiteCollector(name, factory = () => {
134
135
  options = {
135
136
  repeats: suiteOptions.repeats,
136
137
  retry: suiteOptions.retry,
138
+ timeout: suiteOptions.timeout,
137
139
  ...options
138
140
  };
139
141
  }
@@ -141,11 +143,13 @@ function createSuiteCollector(name, factory = () => {
141
143
  id: "",
142
144
  type: "test",
143
145
  name: name2,
146
+ each: this.each,
144
147
  mode: mode2,
145
148
  suite: void 0,
146
149
  fails: this.fails,
147
150
  retry: options == null ? void 0 : options.retry,
148
- repeats: options == null ? void 0 : options.repeats
151
+ repeats: options == null ? void 0 : options.repeats,
152
+ meta: /* @__PURE__ */ Object.create(null)
149
153
  };
150
154
  if (this.concurrent || concurrent)
151
155
  test3.concurrent = true;
@@ -168,7 +172,8 @@ function createSuiteCollector(name, factory = () => {
168
172
  id: "",
169
173
  name: name2,
170
174
  type: "custom",
171
- mode: self.only ? "only" : self.skip ? "skip" : self.todo ? "todo" : "run"
175
+ mode: self.only ? "only" : self.skip ? "skip" : self.todo ? "todo" : "run",
176
+ meta: /* @__PURE__ */ Object.create(null)
172
177
  };
173
178
  tasks.push(task);
174
179
  return task;
@@ -196,8 +201,10 @@ function createSuiteCollector(name, factory = () => {
196
201
  type: "suite",
197
202
  name,
198
203
  mode,
204
+ each,
199
205
  shuffle,
200
- tasks: []
206
+ tasks: [],
207
+ meta: /* @__PURE__ */ Object.create(null)
201
208
  };
202
209
  setHooks(suite2, createSuiteHooks());
203
210
  }
@@ -236,10 +243,11 @@ function createSuite() {
236
243
  if (currentSuite && typeof ((_a = currentSuite.options) == null ? void 0 : _a.repeats) === "number") {
237
244
  options = { repeats: currentSuite.options.repeats, ...options };
238
245
  }
239
- return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle, options);
246
+ return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle, this.each, options);
240
247
  }
241
248
  suiteFn.each = function(cases, ...args) {
242
249
  const suite2 = this.withContext();
250
+ this.setContext("each", true);
243
251
  if (Array.isArray(cases) && args.length)
244
252
  cases = formatTemplateString(cases, args);
245
253
  return (name, fn, options) => {
@@ -248,6 +256,7 @@ function createSuite() {
248
256
  const items = Array.isArray(i) ? i : [i];
249
257
  arrayOnlyCases ? suite2(formatTitle(name, items, idx), () => fn(...items), options) : suite2(formatTitle(name, items, idx), () => fn(i), options);
250
258
  });
259
+ this.setContext("each", void 0);
251
260
  };
252
261
  };
253
262
  suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
@@ -261,6 +270,7 @@ function createTest(fn) {
261
270
  const testFn = fn;
262
271
  testFn.each = function(cases, ...args) {
263
272
  const test2 = this.withContext();
273
+ this.setContext("each", true);
264
274
  if (Array.isArray(cases) && args.length)
265
275
  cases = formatTemplateString(cases, args);
266
276
  return (name, fn2, options) => {
@@ -269,6 +279,7 @@ function createTest(fn) {
269
279
  const items = Array.isArray(i) ? i : [i];
270
280
  arrayOnlyCases ? test2(formatTitle(name, items, idx), () => fn2(...items), options) : test2(formatTitle(name, items, idx), () => fn2(i), options);
271
281
  });
282
+ this.setContext("each", void 0);
272
283
  };
273
284
  };
274
285
  testFn.skipIf = (condition) => condition ? test.skip : test;
@@ -335,6 +346,7 @@ async function collectTests(paths, runner) {
335
346
  mode: "run",
336
347
  filepath,
337
348
  tasks: [],
349
+ meta: /* @__PURE__ */ Object.create(null),
338
350
  projectName: config.name
339
351
  };
340
352
  clearCollectorContext(runner);
@@ -431,7 +443,7 @@ const packs = /* @__PURE__ */ new Map();
431
443
  let updateTimer;
432
444
  let previousUpdate;
433
445
  function updateTask(task, runner) {
434
- packs.set(task.id, task.result);
446
+ packs.set(task.id, [task.result, task.meta]);
435
447
  const { clearTimeout, setTimeout } = getSafeTimers();
436
448
  clearTimeout(updateTimer);
437
449
  updateTimer = setTimeout(() => {
@@ -444,7 +456,14 @@ async function sendTasksUpdate(runner) {
444
456
  clearTimeout(updateTimer);
445
457
  await previousUpdate;
446
458
  if (packs.size) {
447
- const p = (_a = runner.onTaskUpdate) == null ? void 0 : _a.call(runner, Array.from(packs));
459
+ const taskPacks = Array.from(packs).map(([id, task]) => {
460
+ return [
461
+ id,
462
+ task[0],
463
+ task[1]
464
+ ];
465
+ });
466
+ const p = (_a = runner.onTaskUpdate) == null ? void 0 : _a.call(runner, taskPacks);
448
467
  packs.clear();
449
468
  return p;
450
469
  }
@@ -1,4 +1,4 @@
1
- import { q as SequenceHooks, r as SequenceSetupFiles, F as File, d as Test, j as Suite, h as TaskResult, p as TestContext } from './tasks-891047e7.js';
1
+ import { r as SequenceHooks, s as SequenceSetupFiles, F as File, d as Test, k as Suite, j as TaskResultPack, q as TestContext } from './tasks-900f5000.js';
2
2
 
3
3
  interface VitestRunnerConfig {
4
4
  root: string;
@@ -83,7 +83,7 @@ interface VitestRunner {
83
83
  /**
84
84
  * Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
85
85
  */
86
- onTaskUpdate?(task: [string, TaskResult | undefined][]): Promise<void>;
86
+ onTaskUpdate?(task: TaskResultPack[]): Promise<void>;
87
87
  /**
88
88
  * Called before running all tests in collected paths.
89
89
  */
@@ -15,15 +15,18 @@ interface TaskBase {
15
15
  id: string;
16
16
  name: string;
17
17
  mode: RunMode;
18
+ meta: TaskMeta;
19
+ each?: boolean;
18
20
  concurrent?: boolean;
19
21
  shuffle?: boolean;
20
22
  suite?: Suite;
21
23
  file?: File;
22
24
  result?: TaskResult;
23
25
  retry?: number;
24
- meta?: any;
25
26
  repeats?: number;
26
27
  }
28
+ interface TaskMeta {
29
+ }
27
30
  interface TaskCustom extends TaskBase {
28
31
  type: 'custom';
29
32
  }
@@ -42,7 +45,7 @@ interface TaskResult {
42
45
  retryCount?: number;
43
46
  repeatCount?: number;
44
47
  }
45
- type TaskResultPack = [id: string, result: TaskResult | undefined];
48
+ type TaskResultPack = [id: string, result: TaskResult | undefined, meta: TaskMeta];
46
49
  interface Suite extends TaskBase {
47
50
  type: 'suite';
48
51
  tasks: Task[];
@@ -143,10 +146,10 @@ type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI<ExtraContext> & {
143
146
  type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>;
144
147
  type HookCleanupCallback = (() => Awaitable<unknown>) | void;
145
148
  interface SuiteHooks<ExtraContext = {}> {
146
- beforeAll: HookListener<[Suite | File], HookCleanupCallback>[];
147
- afterAll: HookListener<[Suite | File]>[];
148
- beforeEach: HookListener<[TestContext & ExtraContext, Suite], HookCleanupCallback>[];
149
- afterEach: HookListener<[TestContext & ExtraContext, Suite]>[];
149
+ beforeAll: HookListener<[Readonly<Suite | File>], HookCleanupCallback>[];
150
+ afterAll: HookListener<[Readonly<Suite | File>]>[];
151
+ beforeEach: HookListener<[TestContext & ExtraContext, Readonly<Suite>], HookCleanupCallback>[];
152
+ afterEach: HookListener<[TestContext & ExtraContext, Readonly<Suite>]>[];
150
153
  }
151
154
  interface SuiteCollector<ExtraContext = {}> {
152
155
  readonly name: string;
@@ -168,8 +171,14 @@ interface RuntimeContext {
168
171
  interface TestContext {
169
172
  /**
170
173
  * Metadata of the current test
174
+ *
175
+ * @deprecated Use `task` instead
171
176
  */
172
177
  meta: Readonly<Test>;
178
+ /**
179
+ * Metadata of the current test
180
+ */
181
+ task: Readonly<Test>;
173
182
  /**
174
183
  * Extract hooks on test failed
175
184
  */
@@ -179,4 +188,4 @@ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
179
188
  type SequenceHooks = 'stack' | 'list' | 'parallel';
180
189
  type SequenceSetupFiles = 'list' | 'parallel';
181
190
 
182
- export { ChainableFunction as C, DoneCallback as D, File as F, HookListener as H, OnTestFailedHandler as O, RunMode as R, SuiteAPI as S, Task as T, TestAPI as a, SuiteCollector as b, SuiteHooks as c, Test as d, TaskState as e, TaskBase as f, TaskCustom as g, TaskResult as h, TaskResultPack as i, Suite as j, TestFunction as k, TestOptions as l, HookCleanupCallback as m, SuiteFactory as n, RuntimeContext as o, TestContext as p, SequenceHooks as q, SequenceSetupFiles as r, createChainable as s };
191
+ export { ChainableFunction as C, DoneCallback as D, File as F, HookListener as H, OnTestFailedHandler as O, RunMode as R, SuiteAPI as S, Task as T, TestAPI as a, SuiteCollector as b, SuiteHooks as c, Test as d, TaskState as e, TaskBase as f, TaskMeta as g, TaskCustom as h, TaskResult as i, TaskResultPack as j, Suite as k, TestFunction as l, TestOptions as m, HookCleanupCallback as n, SuiteFactory as o, RuntimeContext as p, TestContext as q, SequenceHooks as r, SequenceSetupFiles as s, createChainable as t };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { D as DoneCallback, F as File, m as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, S as SuiteAPI, b as SuiteCollector, n as SuiteFactory, c as SuiteHooks, T as Task, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, d as Test, a as TestAPI, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-891047e7.js';
2
- export { C as CancelReason, V as VitestRunner, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-a2cd0770.js';
1
+ export { D as DoneCallback, F as File, n as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, p as RuntimeContext, r as SequenceHooks, s as SequenceSetupFiles, k as Suite, S as SuiteAPI, b as SuiteCollector, o as SuiteFactory, c as SuiteHooks, T as Task, f as TaskBase, h as TaskCustom, g as TaskMeta, i as TaskResult, j as TaskResultPack, e as TaskState, d as Test, a as TestAPI, q as TestContext, l as TestFunction, m as TestOptions } from './tasks-900f5000.js';
2
+ export { C as CancelReason, V as VitestRunner, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-6af7d148.js';
3
3
  import '@vitest/utils';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { j as Suite, T as Task, d as Test, g as TaskCustom } from './tasks-891047e7.js';
2
- export { C as ChainableFunction, s as createChainable } from './tasks-891047e7.js';
1
+ import { k as Suite, T as Task, d as Test, h as TaskCustom } from './tasks-900f5000.js';
2
+ export { C as ChainableFunction, t as createChainable } from './tasks-900f5000.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
  export { ErrorWithDiff, ParsedStack } from '@vitest/utils';
5
5
  import { DiffOptions } from '@vitest/utils/diff';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "0.31.1",
4
+ "version": "0.31.2",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -41,7 +41,7 @@
41
41
  "concordance": "^5.0.4",
42
42
  "p-limit": "^4.0.0",
43
43
  "pathe": "^1.1.0",
44
- "@vitest/utils": "0.31.1"
44
+ "@vitest/utils": "0.31.2"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "rimraf dist && rollup -c",