@vitest/runner 1.0.0-beta.2 → 1.0.0-beta.4

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, a as Test, C as Custom } from './tasks-54dc134a.js';
4
- export { D as DoneCallback, E as ExtendedContext, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, v as RuntimeContext, y as SequenceHooks, z as SequenceSetupFiles, S as Suite, u as SuiteFactory, j as TaskBase, x as TaskContext, t as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-54dc134a.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, a as Test, C as Custom } from './tasks-0309a91e.js';
4
+ export { D as DoneCallback, E as ExtendedContext, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, w as RuntimeContext, z as SequenceHooks, A as SequenceSetupFiles, S as Suite, v as SuiteFactory, j as TaskBase, y as TaskContext, u as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-0309a91e.js';
5
5
  import { Awaitable } from '@vitest/utils';
6
6
  export { processError } from '@vitest/utils/error';
7
7
 
package/dist/index.js CHANGED
@@ -105,12 +105,12 @@ function mergeContextFixtures(fixtures, context = {}) {
105
105
  if (fixture.isFn) {
106
106
  const usedProps = getUsedProps(fixture.value);
107
107
  if (usedProps.length)
108
- fixture.deps = context.fixtures.filter(({ index, prop }) => index !== fixture.index && usedProps.includes(prop));
108
+ fixture.deps = context.fixtures.filter(({ prop }) => prop !== fixture.prop && usedProps.includes(prop));
109
109
  }
110
110
  });
111
111
  return context;
112
112
  }
113
- const fixtureValueMap = /* @__PURE__ */ new Map();
113
+ const fixtureValueMaps = /* @__PURE__ */ new Map();
114
114
  let cleanupFnArray = new Array();
115
115
  async function callFixtureCleanup() {
116
116
  for (const cleanup of cleanupFnArray.reverse())
@@ -128,8 +128,13 @@ function withFixtures(fn, testContext) {
128
128
  const usedProps = getUsedProps(fn);
129
129
  if (!usedProps.length)
130
130
  return fn(context);
131
+ if (!fixtureValueMaps.get(context))
132
+ fixtureValueMaps.set(context, /* @__PURE__ */ new Map());
133
+ const fixtureValueMap = fixtureValueMaps.get(context);
131
134
  const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop));
132
135
  const pendingFixtures = resolveDeps(usedFixtures);
136
+ if (!pendingFixtures.length)
137
+ return fn(context);
133
138
  let cursor = 0;
134
139
  return new Promise((resolve, reject) => {
135
140
  async function use(fixtureValue) {
@@ -225,9 +230,19 @@ function splitByComma(s) {
225
230
  return result;
226
231
  }
227
232
 
233
+ let _test;
234
+ function setCurrentTest(test) {
235
+ _test = test;
236
+ }
237
+ function getCurrentTest() {
238
+ return _test;
239
+ }
240
+
228
241
  const suite = createSuite();
229
242
  const test = createTest(
230
243
  function(name, fn, options) {
244
+ if (getCurrentTest())
245
+ throw new Error("Nested tests are not allowed");
231
246
  getCurrentSuite().test.fn.call(this, formatName(name), fn, options);
232
247
  }
233
248
  );
@@ -523,7 +538,6 @@ async function collectTests(paths, runner) {
523
538
  const error = processError(e);
524
539
  file.result = {
525
540
  state: "fail",
526
- error,
527
541
  errors: [error]
528
542
  };
529
543
  }
@@ -535,14 +549,6 @@ async function collectTests(paths, runner) {
535
549
  return files;
536
550
  }
537
551
 
538
- let _test;
539
- function setCurrentTest(test) {
540
- _test = test;
541
- }
542
- function getCurrentTest() {
543
- return _test;
544
- }
545
-
546
552
  const now = Date.now;
547
553
  function updateSuiteHookState(suite, name, state, runner) {
548
554
  var _a;
@@ -700,11 +706,9 @@ async function runTest(test, runner) {
700
706
  if (test.result.state === "pass") {
701
707
  const error = processError(new Error("Expect test to fail"));
702
708
  test.result.state = "fail";
703
- test.result.error = error;
704
709
  test.result.errors = [error];
705
710
  } else {
706
711
  test.result.state = "pass";
707
- test.result.error = void 0;
708
712
  test.result.errors = void 0;
709
713
  }
710
714
  }
@@ -722,7 +726,6 @@ function failTask(result, err, diffOptions) {
722
726
  const errors = Array.isArray(err) ? err : [err];
723
727
  for (const e of errors) {
724
728
  const error = processError(e, diffOptions);
725
- result.error ?? (result.error = error);
726
729
  result.errors ?? (result.errors = []);
727
730
  result.errors.push(error);
728
731
  }
@@ -737,7 +740,7 @@ function markTasksAsSkipped(suite, runner) {
737
740
  });
738
741
  }
739
742
  async function runSuite(suite, runner) {
740
- var _a, _b, _c;
743
+ var _a, _b, _c, _d;
741
744
  await ((_a = runner.onBeforeRunSuite) == null ? void 0 : _a.call(runner, suite));
742
745
  if (((_b = suite.result) == null ? void 0 : _b.state) === "fail") {
743
746
  markTasksAsSkipped(suite, runner);
@@ -790,9 +793,8 @@ async function runSuite(suite, runner) {
790
793
  if (suite.mode === "run") {
791
794
  if (!hasTests(suite)) {
792
795
  suite.result.state = "fail";
793
- if (!suite.result.error) {
796
+ if (!((_c = suite.result.errors) == null ? void 0 : _c.length)) {
794
797
  const error = processError(new Error(`No test found in suite ${suite.name}`));
795
- suite.result.error = error;
796
798
  suite.result.errors = [error];
797
799
  }
798
800
  } else if (hasFailed(suite)) {
@@ -803,7 +805,7 @@ async function runSuite(suite, runner) {
803
805
  }
804
806
  updateTask(suite, runner);
805
807
  suite.result.duration = now() - start;
806
- await ((_c = runner.onAfterRunSuite) == null ? void 0 : _c.call(runner, suite));
808
+ await ((_d = runner.onAfterRunSuite) == null ? void 0 : _d.call(runner, suite));
807
809
  }
808
810
  }
809
811
  async function runSuiteChild(c, runner) {
@@ -820,7 +822,6 @@ async function runFiles(files, runner) {
820
822
  const error = processError(new Error(`No test suite found in file ${file.filepath}`));
821
823
  file.result = {
822
824
  state: "fail",
823
- error,
824
825
  errors: [error]
825
826
  };
826
827
  }
@@ -57,10 +57,6 @@ interface TaskResult {
57
57
  duration?: number;
58
58
  startTime?: number;
59
59
  heap?: number;
60
- /**
61
- * @deprecated Use "errors" instead
62
- */
63
- error?: ErrorWithDiff;
64
60
  errors?: ErrorWithDiff[];
65
61
  htmlError?: string;
66
62
  hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
@@ -157,14 +153,11 @@ type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<E
157
153
  [K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
158
154
  }>;
159
155
  };
160
- type FixtureType<T> = T extends (context: any, use: (fixture: infer F) => any) => any ? F : T;
161
- type Fixture<T, K extends keyof T, OnlyFunction, ExtraContext = {}, V = FixtureType<T[K]>, FN = (context: {
162
- [P in keyof T | keyof ExtraContext as P extends K ? P extends keyof ExtraContext ? P : never : P]: K extends P ? K extends keyof ExtraContext ? ExtraContext[K] : V : P extends keyof T ? T[P] : never;
163
- } & TestContext, use: (fixture: V) => Promise<void>) => Promise<void>> = OnlyFunction extends true ? FN : (FN | V);
156
+ type Use<T> = (value: T) => Promise<void>;
157
+ type FixtureFn<T, K extends keyof T, ExtraContext> = (context: Omit<T, K> & ExtraContext, use: Use<T[K]>) => Promise<void>;
158
+ type Fixture<T, K extends keyof T, ExtraContext = {}> = ((...args: any) => any) extends T[K] ? (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never) : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
164
159
  type Fixtures<T extends Record<string, any>, ExtraContext = {}> = {
165
- [K in keyof T]: Fixture<T, K, false, ExtraContext>;
166
- } | {
167
- [K in keyof T]: Fixture<T, K, true, ExtraContext>;
160
+ [K in keyof T]: Fixture<T, K, ExtraContext & ExtendedContext<Test>>;
168
161
  };
169
162
  type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
170
163
  type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', [
@@ -238,4 +231,4 @@ type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
238
231
  type SequenceHooks = 'stack' | 'list' | 'parallel';
239
232
  type SequenceSetupFiles = 'list' | 'parallel';
240
233
 
241
- export { type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type TaskState as i, type TaskBase as j, type TaskPopulated as k, type TaskMeta as l, type TaskResult as m, type TaskResultPack as n, type TestFunction as o, type TestOptions as p, type Fixture as q, type Fixtures as r, type HookCleanupCallback as s, type TaskCustomOptions as t, type SuiteFactory as u, type RuntimeContext as v, type TestContext as w, type TaskContext as x, type SequenceHooks as y, type SequenceSetupFiles as z };
234
+ export { type SequenceSetupFiles as A, type Custom as C, type DoneCallback as D, type ExtendedContext as E, type File as F, type HookListener as H, type InferFixturesTypes as I, type OnTestFailedHandler as O, type RunMode as R, type Suite as S, type Task as T, type Use as U, type Test as a, type ChainableFunction as b, createChainable as c, type SuiteAPI as d, type TestAPI as e, type SuiteCollector as f, type CustomAPI as g, type SuiteHooks as h, type TaskState as i, type TaskBase as j, type TaskPopulated as k, type TaskMeta as l, type TaskResult as m, type TaskResultPack as n, type TestFunction as o, type TestOptions as p, type FixtureFn as q, type Fixture as r, type Fixtures as s, type HookCleanupCallback as t, type TaskCustomOptions as u, type SuiteFactory as v, type RuntimeContext as w, type TestContext as x, type TaskContext as y, type SequenceHooks as z };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { y as SequenceHooks, z as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, x as TaskContext, E as ExtendedContext } from './tasks-54dc134a.js';
2
- export { g as CustomAPI, D as DoneCallback, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, v as RuntimeContext, d as SuiteAPI, f as SuiteCollector, u as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, t as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-54dc134a.js';
1
+ import { z as SequenceHooks, A as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, y as TaskContext, E as ExtendedContext } from './tasks-0309a91e.js';
2
+ export { g as CustomAPI, D as DoneCallback, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, w as RuntimeContext, d as SuiteAPI, f as SuiteCollector, v as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, u as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-0309a91e.js';
3
3
  import '@vitest/utils';
4
4
 
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-54dc134a.js';
2
- export { b as ChainableFunction, c as createChainable } from './tasks-54dc134a.js';
1
+ import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-0309a91e.js';
2
+ export { b as ChainableFunction, c as createChainable } from './tasks-0309a91e.js';
3
3
  import { Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/dist/utils.js CHANGED
@@ -70,7 +70,6 @@ function checkAllowOnly(task, allowOnly) {
70
70
  const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"));
71
71
  task.result = {
72
72
  state: "fail",
73
- error,
74
73
  errors: [error]
75
74
  };
76
75
  }
@@ -125,8 +124,8 @@ function isAtomTest(s) {
125
124
  }
126
125
  function getTests(suite) {
127
126
  const tests = [];
128
- const suite_arr = toArray(suite);
129
- for (const s of suite_arr) {
127
+ const arraySuites = toArray(suite);
128
+ for (const s of arraySuites) {
130
129
  if (isAtomTest(s)) {
131
130
  tests.push(s);
132
131
  } else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.2",
4
+ "version": "1.0.0-beta.4",
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": "^4.0.0",
42
42
  "pathe": "^1.1.1",
43
- "@vitest/utils": "1.0.0-beta.2"
43
+ "@vitest/utils": "1.0.0-beta.4"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "rimraf dist && rollup -c",