@vitest/runner 1.3.1 → 1.5.0

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-_kyNRBhz.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-_kyNRBhz.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
@@ -4,6 +4,7 @@ import { processError } from '@vitest/utils/error';
4
4
  export { processError } from '@vitest/utils/error';
5
5
  import { j as createChainable, g as generateHash, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, p as partitionSuiteChildren, h as hasTests, e as hasFailed } from './chunk-tasks.js';
6
6
  import { relative } from 'pathe';
7
+ import { parseSingleStack } from '@vitest/utils/source-map';
7
8
 
8
9
  const fnMap = /* @__PURE__ */ new WeakMap();
9
10
  const fixtureMap = /* @__PURE__ */ new WeakMap();
@@ -260,16 +261,21 @@ const describe = suite;
260
261
  const it = test;
261
262
  let runner;
262
263
  let defaultSuite;
264
+ let currentTestFilepath;
263
265
  function getDefaultSuite() {
264
266
  return defaultSuite;
265
267
  }
268
+ function getTestFilepath() {
269
+ return currentTestFilepath;
270
+ }
266
271
  function getRunner() {
267
272
  return runner;
268
273
  }
269
- function clearCollectorContext(currentRunner) {
274
+ function clearCollectorContext(filepath, currentRunner) {
270
275
  if (!defaultSuite)
271
276
  defaultSuite = currentRunner.config.sequence.shuffle ? suite.shuffle("") : currentRunner.config.sequence.concurrent ? suite.concurrent("") : suite("");
272
277
  runner = currentRunner;
278
+ currentTestFilepath = filepath;
273
279
  collectorContext.tasks.length = 0;
274
280
  defaultSuite.clear();
275
281
  collectorContext.currentSuite = defaultSuite;
@@ -315,7 +321,7 @@ function createSuiteCollector(name, factory = () => {
315
321
  const tasks = [];
316
322
  const factoryQueue = [];
317
323
  let suite2;
318
- initSuite();
324
+ initSuite(true);
319
325
  const task = function(name2 = "", options = {}) {
320
326
  const task2 = {
321
327
  id: "",
@@ -347,6 +353,15 @@ function createSuiteCollector(name, factory = () => {
347
353
  (options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
348
354
  ));
349
355
  }
356
+ if (runner.config.includeTaskLocation) {
357
+ const limit = Error.stackTraceLimit;
358
+ Error.stackTraceLimit = 15;
359
+ const error = new Error("stacktrace").stack;
360
+ Error.stackTraceLimit = limit;
361
+ const stack = findTestFileStackTrace(error, task2.each ?? false);
362
+ if (stack)
363
+ task2.location = stack;
364
+ }
350
365
  tasks.push(task2);
351
366
  return task2;
352
367
  };
@@ -380,7 +395,7 @@ function createSuiteCollector(name, factory = () => {
380
395
  function addHook(name2, ...fn) {
381
396
  getHooks(suite2)[name2].push(...fn);
382
397
  }
383
- function initSuite() {
398
+ function initSuite(includeLocation) {
384
399
  if (typeof suiteOptions === "number")
385
400
  suiteOptions = { timeout: suiteOptions };
386
401
  suite2 = {
@@ -394,12 +409,21 @@ function createSuiteCollector(name, factory = () => {
394
409
  meta: /* @__PURE__ */ Object.create(null),
395
410
  projectName: ""
396
411
  };
412
+ if (runner && includeLocation && runner.config.includeTaskLocation) {
413
+ const limit = Error.stackTraceLimit;
414
+ Error.stackTraceLimit = 15;
415
+ const error = new Error("stacktrace").stack;
416
+ Error.stackTraceLimit = limit;
417
+ const stack = findTestFileStackTrace(error, suite2.each ?? false);
418
+ if (stack)
419
+ suite2.location = stack;
420
+ }
397
421
  setHooks(suite2, createSuiteHooks());
398
422
  }
399
423
  function clear() {
400
424
  tasks.length = 0;
401
425
  factoryQueue.length = 0;
402
- initSuite();
426
+ initSuite(false);
403
427
  }
404
428
  async function collect(file) {
405
429
  factoryQueue.length = 0;
@@ -536,6 +560,24 @@ function formatTemplateString(cases, args) {
536
560
  }
537
561
  return res;
538
562
  }
563
+ function findTestFileStackTrace(error, each) {
564
+ const lines = error.split("\n").slice(1);
565
+ for (const line of lines) {
566
+ const stack = parseSingleStack(line);
567
+ if (stack && stack.file === getTestFilepath()) {
568
+ return {
569
+ line: stack.line,
570
+ /**
571
+ * test.each([1, 2])('name')
572
+ * ^ leads here, but should
573
+ * ^ lead here
574
+ * in source maps it's the same boundary, so it just points to the start of it
575
+ */
576
+ column: each ? stack.column + 1 : stack.column
577
+ };
578
+ }
579
+ }
580
+ }
539
581
 
540
582
  async function runSetupFiles(config, runner) {
541
583
  const files = toArray(config.setupFiles);
@@ -567,7 +609,7 @@ async function collectTests(paths, runner) {
567
609
  meta: /* @__PURE__ */ Object.create(null),
568
610
  projectName: config.name
569
611
  };
570
- clearCollectorContext(runner);
612
+ clearCollectorContext(filepath, runner);
571
613
  try {
572
614
  const setupStart = now$1();
573
615
  await runSetupFiles(config, runner);
@@ -900,7 +942,7 @@ async function startTests(paths, runner) {
900
942
  var _a, _b, _c, _d;
901
943
  await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
902
944
  const files = await collectTests(paths, runner);
903
- (_b = runner.onCollected) == null ? void 0 : _b.call(runner, files);
945
+ await ((_b = runner.onCollected) == null ? void 0 : _b.call(runner, files));
904
946
  await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
905
947
  await runFiles(files, runner);
906
948
  await ((_d = runner.onAfterRunFiles) == null ? void 0 : _d.call(runner, files));
@@ -35,6 +35,10 @@ interface TaskBase {
35
35
  result?: TaskResult;
36
36
  retry?: number;
37
37
  repeats?: number;
38
+ location?: {
39
+ line: number;
40
+ column: number;
41
+ };
38
42
  }
39
43
  interface TaskPopulated extends TaskBase {
40
44
  suite: Suite;
@@ -199,9 +203,9 @@ interface SuiteCollectorCallable<ExtraContext = {}> {
199
203
  /**
200
204
  * @deprecated Use options as the second argument instead
201
205
  */
202
- (name: string | Function, fn: SuiteFactory<ExtraContext>, options: TestOptions): SuiteCollector<ExtraContext>;
203
- (name: string | Function, fn?: SuiteFactory<ExtraContext>, options?: number | TestOptions): SuiteCollector<ExtraContext>;
204
- (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>;
205
209
  }
206
210
  type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', SuiteCollectorCallable<ExtraContext>, {
207
211
  each: TestEachFunction;
@@ -242,7 +246,7 @@ interface SuiteCollector<ExtraContext = {}> {
242
246
  clear: () => void;
243
247
  on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
244
248
  }
245
- type SuiteFactory<ExtraContext = {}> = (test: (name: string | Function, fn: TestFunction<ExtraContext>) => void) => Awaitable<void>;
249
+ type SuiteFactory<ExtraContext = {}> = (test: TestAPI<ExtraContext>) => Awaitable<void>;
246
250
  interface RuntimeContext {
247
251
  tasks: (SuiteCollector | Test)[];
248
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-_kyNRBhz.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-_kyNRBhz.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
 
@@ -24,6 +24,7 @@ interface VitestRunnerConfig {
24
24
  testTimeout: number;
25
25
  hookTimeout: number;
26
26
  retry: number;
27
+ includeTaskLocation?: boolean;
27
28
  diffOptions?: DiffOptions;
28
29
  }
29
30
  type VitestRunnerImportSource = 'collect' | 'setup';
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-_kyNRBhz.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-_kyNRBhz.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.3.1",
4
+ "version": "1.5.0",
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.3.1"
43
+ "@vitest/utils": "1.5.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",