@vitest/runner 1.4.0 → 1.5.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,7 +1,7 @@
1
1
  import { VitestRunner } from './types.js';
2
2
  export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
3
- import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, i as OnTestFinishedHandler, a as Test, C as Custom, S as Suite } from './tasks-B4r0U6Dq.js';
4
- export { D as DoneCallback, E as ExtendedContext, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, y as RuntimeContext, B as SequenceHooks, G as SequenceSetupFiles, x as SuiteFactory, k as TaskBase, A as TaskContext, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, o as TaskResultPack, j as TaskState, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-B4r0U6Dq.js';
3
+ import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, i as OnTestFinishedHandler, a as Test, C as Custom, S as Suite } from './tasks-K5XERDtv.js';
4
+ export { D as DoneCallback, E as ExtendedContext, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, y as RuntimeContext, B as SequenceHooks, G as SequenceSetupFiles, x as SuiteFactory, k as TaskBase, A as TaskContext, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, o as TaskResultPack, j as TaskState, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-K5XERDtv.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
  import '@vitest/utils/diff';
package/dist/index.js CHANGED
@@ -355,10 +355,10 @@ function createSuiteCollector(name, factory = () => {
355
355
  }
356
356
  if (runner.config.includeTaskLocation) {
357
357
  const limit = Error.stackTraceLimit;
358
- Error.stackTraceLimit = 10;
358
+ Error.stackTraceLimit = 15;
359
359
  const error = new Error("stacktrace").stack;
360
360
  Error.stackTraceLimit = limit;
361
- const stack = findStackTrace(error, task2.each ?? false);
361
+ const stack = findTestFileStackTrace(error, task2.each ?? false);
362
362
  if (stack)
363
363
  task2.location = stack;
364
364
  }
@@ -411,18 +411,12 @@ function createSuiteCollector(name, factory = () => {
411
411
  };
412
412
  if (runner && includeLocation && runner.config.includeTaskLocation) {
413
413
  const limit = Error.stackTraceLimit;
414
- Error.stackTraceLimit = 5;
414
+ Error.stackTraceLimit = 15;
415
415
  const error = new Error("stacktrace").stack;
416
416
  Error.stackTraceLimit = limit;
417
- const stack = parseSingleStack(error.split("\n")[5]);
418
- if (stack) {
419
- suite2.location = {
420
- line: stack.line,
421
- // because source map is boundary based, this line leads to ")" in test.each()[(]),
422
- // but it should be the next opening bracket - here we assume it's on the same line
423
- column: each ? stack.column + 1 : stack.column
424
- };
425
- }
417
+ const stack = findTestFileStackTrace(error, suite2.each ?? false);
418
+ if (stack)
419
+ suite2.location = stack;
426
420
  }
427
421
  setHooks(suite2, createSuiteHooks());
428
422
  }
@@ -566,8 +560,8 @@ function formatTemplateString(cases, args) {
566
560
  }
567
561
  return res;
568
562
  }
569
- function findStackTrace(error, each) {
570
- const lines = error.split("\n").slice(4);
563
+ function findTestFileStackTrace(error, each) {
564
+ const lines = error.split("\n").slice(1);
571
565
  for (const line of lines) {
572
566
  const stack = parseSingleStack(line);
573
567
  if (stack && stack.file === getTestFilepath()) {
@@ -672,6 +666,16 @@ function getSuiteHooks(suite, name, sequence) {
672
666
  return hooks.slice().reverse();
673
667
  return hooks;
674
668
  }
669
+ async function callTaskHooks(task, hooks, sequence) {
670
+ if (sequence === "stack")
671
+ hooks = hooks.slice().reverse();
672
+ if (sequence === "parallel") {
673
+ await Promise.all(hooks.map((fn) => fn(task.result)));
674
+ } else {
675
+ for (const fn of hooks)
676
+ await fn(task.result);
677
+ }
678
+ }
675
679
  async function callSuiteHook(suite, currentTask, name, runner, args) {
676
680
  const sequence = runner.config.sequence.hooks;
677
681
  const callbacks = [];
@@ -733,7 +737,7 @@ async function callCleanupHooks(cleanups) {
733
737
  }));
734
738
  }
735
739
  async function runTest(test, runner) {
736
- var _a, _b, _c, _d, _e, _f, _g, _h;
740
+ var _a, _b, _c, _d, _e, _f;
737
741
  await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
738
742
  if (test.mode !== "run")
739
743
  return;
@@ -806,13 +810,13 @@ async function runTest(test, runner) {
806
810
  }
807
811
  }
808
812
  try {
809
- await Promise.all(((_f = test.onFinished) == null ? void 0 : _f.map((fn) => fn(test.result))) || []);
813
+ await callTaskHooks(test, test.onFinished || [], "stack");
810
814
  } catch (e) {
811
815
  failTask(test.result, e, runner.config.diffOptions);
812
816
  }
813
817
  if (test.result.state === "fail") {
814
818
  try {
815
- await Promise.all(((_g = test.onFailed) == null ? void 0 : _g.map((fn) => fn(test.result))) || []);
819
+ await callTaskHooks(test, test.onFailed || [], runner.config.sequence.hooks);
816
820
  } catch (e) {
817
821
  failTask(test.result, e, runner.config.diffOptions);
818
822
  }
@@ -829,7 +833,7 @@ async function runTest(test, runner) {
829
833
  }
830
834
  setCurrentTest(void 0);
831
835
  test.result.duration = now() - start;
832
- await ((_h = runner.onAfterRunTask) == null ? void 0 : _h.call(runner, test));
836
+ await ((_f = runner.onAfterRunTask) == null ? void 0 : _f.call(runner, test));
833
837
  updateTask(test, runner);
834
838
  }
835
839
  function failTask(result, err, diffOptions) {
@@ -203,9 +203,9 @@ interface SuiteCollectorCallable<ExtraContext = {}> {
203
203
  /**
204
204
  * @deprecated Use options as the second argument instead
205
205
  */
206
- (name: string | Function, fn: SuiteFactory<ExtraContext>, options: TestOptions): SuiteCollector<ExtraContext>;
207
- (name: string | Function, fn?: SuiteFactory<ExtraContext>, options?: number | TestOptions): SuiteCollector<ExtraContext>;
208
- (name: string | Function, options: TestOptions, fn?: SuiteFactory<ExtraContext>): SuiteCollector<ExtraContext>;
206
+ <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn: SuiteFactory<OverrideExtraContext>, options: TestOptions): SuiteCollector<OverrideExtraContext>;
207
+ <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, fn?: SuiteFactory<OverrideExtraContext>, options?: number | TestOptions): SuiteCollector<OverrideExtraContext>;
208
+ <OverrideExtraContext extends ExtraContext = ExtraContext>(name: string | Function, options: TestOptions, fn?: SuiteFactory<OverrideExtraContext>): SuiteCollector<OverrideExtraContext>;
209
209
  }
210
210
  type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', SuiteCollectorCallable<ExtraContext>, {
211
211
  each: TestEachFunction;
@@ -246,7 +246,7 @@ interface SuiteCollector<ExtraContext = {}> {
246
246
  clear: () => void;
247
247
  on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
248
248
  }
249
- type SuiteFactory<ExtraContext = {}> = (test: (name: string | Function, fn: TestFunction<ExtraContext>) => void) => Awaitable<void>;
249
+ type SuiteFactory<ExtraContext = {}> = (test: TestAPI<ExtraContext>) => Awaitable<void>;
250
250
  interface RuntimeContext {
251
251
  tasks: (SuiteCollector | Test)[];
252
252
  currentSuite: SuiteCollector | null;
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as SequenceHooks, G as SequenceSetupFiles, F as File, T as Task, S as Suite, o as TaskResultPack, a as Test, C as Custom, A as TaskContext, E as ExtendedContext } from './tasks-B4r0U6Dq.js';
2
- export { g as CustomAPI, D as DoneCallback, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, i as OnTestFinishedHandler, R as RunMode, y as RuntimeContext, d as SuiteAPI, f as SuiteCollector, x as SuiteFactory, h as SuiteHooks, k as TaskBase, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, j as TaskState, e as TestAPI, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-B4r0U6Dq.js';
1
+ import { B as SequenceHooks, G as SequenceSetupFiles, F as File, T as Task, S as Suite, o as TaskResultPack, a as Test, C as Custom, A as TaskContext, E as ExtendedContext } from './tasks-K5XERDtv.js';
2
+ export { g as CustomAPI, D as DoneCallback, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, i as OnTestFinishedHandler, R as RunMode, y as RuntimeContext, d as SuiteAPI, f as SuiteCollector, x as SuiteFactory, h as SuiteHooks, k as TaskBase, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, j as TaskState, e as TestAPI, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-K5XERDtv.js';
3
3
  import { DiffOptions } from '@vitest/utils/diff';
4
4
  import '@vitest/utils';
5
5
 
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-B4r0U6Dq.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-B4r0U6Dq.js';
1
+ import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-K5XERDtv.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-K5XERDtv.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": "1.4.0",
4
+ "version": "1.5.1",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "p-limit": "^5.0.0",
42
42
  "pathe": "^1.1.1",
43
- "@vitest/utils": "1.4.0"
43
+ "@vitest/utils": "1.5.1"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",