vitest 0.0.72 → 0.0.76

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.
@@ -4,6 +4,38 @@ const context = {
4
4
  tasks: [],
5
5
  currentSuite: null
6
6
  };
7
+ function collectTask(task) {
8
+ var _a;
9
+ (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
10
+ }
11
+ async function runWithSuite(suite, fn) {
12
+ const prev = context.currentSuite;
13
+ context.currentSuite = suite;
14
+ await fn();
15
+ context.currentSuite = prev;
16
+ }
17
+ function getDefaultTestTimeout() {
18
+ var _a, _b;
19
+ return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.testTimeout) ?? 5e3;
20
+ }
21
+ function getDefaultHookTimeout() {
22
+ var _a, _b;
23
+ return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.hookTimeout) ?? 5e3;
24
+ }
25
+ function withTimeout(fn, _timeout) {
26
+ const timeout = _timeout ?? getDefaultTestTimeout();
27
+ if (timeout <= 0 || timeout === Infinity)
28
+ return fn;
29
+ return (...args) => {
30
+ return Promise.race([fn(...args), new Promise((resolve, reject) => {
31
+ const timer = setTimeout(() => {
32
+ clearTimeout(timer);
33
+ reject(new Error(`Test timed out in ${timeout}ms.`));
34
+ }, timeout);
35
+ timer.unref();
36
+ })]);
37
+ };
38
+ }
7
39
 
8
40
  const fnMap = new WeakMap();
9
41
  const hooksMap = new WeakMap();
@@ -22,17 +54,14 @@ function getHooks(key) {
22
54
 
23
55
  const suite = createSuite();
24
56
  const defaultSuite = suite("");
57
+ function clearContext() {
58
+ context.tasks.length = 0;
59
+ defaultSuite.clear();
60
+ context.currentSuite = defaultSuite;
61
+ }
25
62
  function getCurrentSuite() {
26
63
  return context.currentSuite || defaultSuite;
27
64
  }
28
- const getDefaultTestTimeout = () => {
29
- var _a, _b;
30
- return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.testTimeout) ?? 5e3;
31
- };
32
- const getDefaultHookTimeout = () => {
33
- var _a, _b;
34
- return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.hookTimeout) ?? 5e3;
35
- };
36
65
  function createSuiteHooks() {
37
66
  return {
38
67
  beforeAll: [],
@@ -43,7 +72,6 @@ function createSuiteHooks() {
43
72
  }
44
73
  function createSuiteCollector(name, factory = () => {
45
74
  }, mode, suiteComputeMode) {
46
- var _a;
47
75
  const tasks = [];
48
76
  const factoryQueue = [];
49
77
  let suite2;
@@ -91,12 +119,8 @@ function createSuiteCollector(name, factory = () => {
91
119
  }
92
120
  async function collect(file) {
93
121
  factoryQueue.length = 0;
94
- if (factory) {
95
- const prev = context.currentSuite;
96
- context.currentSuite = collector;
97
- await factory(test2);
98
- context.currentSuite = prev;
99
- }
122
+ if (factory)
123
+ await runWithSuite(collector, () => factory(test2));
100
124
  const allChildren = await Promise.all([...factoryQueue, ...tasks].map((i) => i.type === "collector" ? i.collect(file) : i));
101
125
  suite2.file = file;
102
126
  suite2.tasks = allChildren;
@@ -107,7 +131,7 @@ function createSuiteCollector(name, factory = () => {
107
131
  });
108
132
  return suite2;
109
133
  }
110
- (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(collector);
134
+ collectTask(collector);
111
135
  return collector;
112
136
  }
113
137
  function createTestCollector(collectTest) {
@@ -197,28 +221,5 @@ function createSuite() {
197
221
  }
198
222
  const describe = suite;
199
223
  const it = test;
200
- const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
201
- const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
202
- const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
203
- const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
204
- function clearContext() {
205
- context.tasks.length = 0;
206
- defaultSuite.clear();
207
- context.currentSuite = defaultSuite;
208
- }
209
- function withTimeout(fn, _timeout) {
210
- const timeout = _timeout ?? getDefaultTestTimeout();
211
- if (timeout <= 0 || timeout === Infinity)
212
- return fn;
213
- return (...args) => {
214
- return Promise.race([fn(...args), new Promise((resolve, reject) => {
215
- const timer = setTimeout(() => {
216
- clearTimeout(timer);
217
- reject(new Error(`Test timed out in ${timeout}ms.`));
218
- }, timeout);
219
- timer.unref();
220
- })]);
221
- };
222
- }
223
224
 
224
- export { describe as a, beforeAll as b, createSuiteHooks as c, defaultSuite as d, afterAll as e, beforeEach as f, afterEach as g, clearContext as h, it as i, setHooks as j, context as k, getHooks as l, getFn as m, suite as s, test as t };
225
+ export { getDefaultHookTimeout as a, setHooks as b, createSuiteHooks as c, describe as d, clearContext as e, defaultSuite as f, getCurrentSuite as g, context as h, it as i, getHooks as j, getFn as k, suite as s, test as t, withTimeout as w };
package/dist/worker.js CHANGED
@@ -229,6 +229,7 @@ async function run(ctx) {
229
229
  const { config, port } = ctx;
230
230
  const rpcPromiseMap = new Map();
231
231
  process.__vitest_worker__ = {
232
+ moduleCache,
232
233
  config,
233
234
  rpc: (method, ...args) => {
234
235
  return new Promise((resolve2, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.72",
3
+ "version": "0.0.76",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -51,7 +51,8 @@
51
51
  "test": "node bin/vitest.mjs -r test/core",
52
52
  "test:all": "cross-env CI=true pnpm -r --stream --filter !vitest run test --",
53
53
  "test:ci": "cross-env CI=true pnpm -r --stream --filter !vitest --filter !@vitest/test-fails run test --",
54
- "typecheck": "tsc --noEmit && nr lint"
54
+ "typecheck": "tsc --noEmit && nr lint",
55
+ "ci": "ni && nr typecheck && nr lint && nr build && nr test:all"
55
56
  },
56
57
  "dependencies": {
57
58
  "@types/chai": "^4.3.0",
@@ -1,31 +0,0 @@
1
- import { s as suite, d as defaultSuite, c as createSuiteHooks, t as test, a as describe, i as it, b as beforeAll, e as afterAll, f as beforeEach, g as afterEach, h as clearContext } from './suite-819c135e.js';
2
- import chai, { assert, should, expect } from 'chai';
3
- import sinon from 'sinon';
4
-
5
- const { mock, spy, stub } = sinon;
6
- sinon.fn = sinon.spy;
7
-
8
- var index = /*#__PURE__*/Object.freeze({
9
- __proto__: null,
10
- suite: suite,
11
- defaultSuite: defaultSuite,
12
- createSuiteHooks: createSuiteHooks,
13
- test: test,
14
- describe: describe,
15
- it: it,
16
- beforeAll: beforeAll,
17
- afterAll: afterAll,
18
- beforeEach: beforeEach,
19
- afterEach: afterEach,
20
- clearContext: clearContext,
21
- assert: assert,
22
- should: should,
23
- expect: expect,
24
- chai: chai,
25
- sinon: sinon,
26
- mock: mock,
27
- spy: spy,
28
- stub: stub
29
- });
30
-
31
- export { stub as a, index as i, mock as m, spy as s };