@vitest/runner 1.3.1 → 1.4.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-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';
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 = 10;
359
+ const error = new Error("stacktrace").stack;
360
+ Error.stackTraceLimit = limit;
361
+ const stack = findStackTrace(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,27 @@ 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 = 5;
415
+ const error = new Error("stacktrace").stack;
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
+ }
426
+ }
397
427
  setHooks(suite2, createSuiteHooks());
398
428
  }
399
429
  function clear() {
400
430
  tasks.length = 0;
401
431
  factoryQueue.length = 0;
402
- initSuite();
432
+ initSuite(false);
403
433
  }
404
434
  async function collect(file) {
405
435
  factoryQueue.length = 0;
@@ -536,6 +566,24 @@ function formatTemplateString(cases, args) {
536
566
  }
537
567
  return res;
538
568
  }
569
+ function findStackTrace(error, each) {
570
+ const lines = error.split("\n").slice(4);
571
+ for (const line of lines) {
572
+ const stack = parseSingleStack(line);
573
+ if (stack && stack.file === getTestFilepath()) {
574
+ return {
575
+ line: stack.line,
576
+ /**
577
+ * test.each([1, 2])('name')
578
+ * ^ leads here, but should
579
+ * ^ lead here
580
+ * in source maps it's the same boundary, so it just points to the start of it
581
+ */
582
+ column: each ? stack.column + 1 : stack.column
583
+ };
584
+ }
585
+ }
586
+ }
539
587
 
540
588
  async function runSetupFiles(config, runner) {
541
589
  const files = toArray(config.setupFiles);
@@ -567,7 +615,7 @@ async function collectTests(paths, runner) {
567
615
  meta: /* @__PURE__ */ Object.create(null),
568
616
  projectName: config.name
569
617
  };
570
- clearCollectorContext(runner);
618
+ clearCollectorContext(filepath, runner);
571
619
  try {
572
620
  const setupStart = now$1();
573
621
  await runSetupFiles(config, runner);
@@ -900,7 +948,7 @@ async function startTests(paths, runner) {
900
948
  var _a, _b, _c, _d;
901
949
  await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
902
950
  const files = await collectTests(paths, runner);
903
- (_b = runner.onCollected) == null ? void 0 : _b.call(runner, files);
951
+ await ((_b = runner.onCollected) == null ? void 0 : _b.call(runner, files));
904
952
  await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
905
953
  await runFiles(files, runner);
906
954
  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;
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-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';
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-B4r0U6Dq.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-B4r0U6Dq.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.4.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.4.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",