vitest 0.0.75 → 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.
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import require$$2, { EventEmitter } from 'events';
2
- import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, d as c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-eb493046.js';
2
+ import { s as stringWidth, a as ansiStyles, b as stripAnsi, c as sliceAnsi, d as c, F as F_POINTER, e as F_DOWN, f as F_LONG_DASH, g as F_DOWN_RIGHT, h as F_DOT, i as F_CHECK, j as F_CROSS, k as cliTruncate, l as F_RIGHT, p as printError } from './error-1df12c37.js';
3
3
  import { performance } from 'perf_hooks';
4
4
  import path, { isAbsolute, relative, dirname, basename, resolve } from 'path';
5
5
  import { g as getNames, s as slash, a as getTests, b as getSuites, t as toArray, h as hasFailed } from './utils-9dcc4050.js';
@@ -632,7 +632,7 @@ const cac = (name = "") => new CAC(name);
632
632
 
633
633
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
634
634
 
635
- var version = "0.0.75";
635
+ var version = "0.0.76";
636
636
 
637
637
  const ESC = '\u001B[';
638
638
  const OSC = '\u001B]';
@@ -2176,6 +2176,7 @@ async function initViteServer(options = {}) {
2176
2176
  resolved.maxThreads = parseInt(process.env.VITEST_MAX_THREADS);
2177
2177
  if (process.env.VITEST_MIN_THREADS)
2178
2178
  resolved.minThreads = parseInt(process.env.VITEST_MIN_THREADS);
2179
+ resolved.setupFiles = Array.from(resolved.setupFiles || []).map((i) => resolve(root, i));
2179
2180
  return {
2180
2181
  server,
2181
2182
  config: resolved
package/dist/entry.js CHANGED
@@ -5,11 +5,11 @@ import chai, { expect, util } from 'chai';
5
5
  import SinonChai from 'sinon-chai';
6
6
  import Subset from 'chai-subset';
7
7
  import path, { basename } from 'path';
8
- import { g as getNames, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
8
+ import { g as getNames, t as toArray, i as interpretOnlyMode, p as partitionSuiteChildren, c as hasTests, h as hasFailed } from './utils-9dcc4050.js';
9
9
  import fs from 'fs';
10
- import { d as c$1, m as generateDiff } from './error-eb493046.js';
10
+ import { d as c$1, m as generateDiff } from './error-1df12c37.js';
11
11
  import { performance } from 'perf_hooks';
12
- import { j as setHooks, c as createSuiteHooks, h as clearContext, d as defaultSuite, k as context, l as getHooks, m as getFn } from './suite-819c135e.js';
12
+ import { b as setHooks, c as createSuiteHooks, e as clearContext, f as defaultSuite, h as context, j as getHooks, k as getFn } from './suite-1bc54c1b.js';
13
13
  import { n as nanoid } from './index-6427e0f2.js';
14
14
  import 'tty';
15
15
  import 'source-map';
@@ -248,8 +248,15 @@ var jsdom = {
248
248
  url: "http://localhost:3000"
249
249
  });
250
250
  const keys = KEYS.concat(Object.getOwnPropertyNames(dom.window)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
251
- for (const key of keys)
252
- global[key] = dom.window[key];
251
+ for (const key of keys) {
252
+ Object.defineProperty(global, key, {
253
+ get() {
254
+ return dom.window[key];
255
+ },
256
+ configurable: true
257
+ });
258
+ }
259
+ global.window = global;
253
260
  return {
254
261
  teardown(global2) {
255
262
  keys.forEach((key) => delete global2[key]);
@@ -264,8 +271,15 @@ var happy = {
264
271
  const { Window } = await importModule("happy-dom");
265
272
  const win = new Window();
266
273
  const keys = KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
267
- for (const key of keys)
268
- global[key] = win[key];
274
+ for (const key of keys) {
275
+ Object.defineProperty(global, key, {
276
+ get() {
277
+ return win[key];
278
+ },
279
+ configurable: true
280
+ });
281
+ }
282
+ global.window = global;
269
283
  return {
270
284
  teardown(global2) {
271
285
  win.happyDOM.cancelAsync();
@@ -3600,7 +3614,7 @@ async function setupGlobalEnv(config) {
3600
3614
  setupConsoleLogSpy();
3601
3615
  await setupChai();
3602
3616
  if (config.global)
3603
- (await import('./global-e40b54d6.js')).registerApiGlobally();
3617
+ (await import('./global-784f167d.js')).registerApiGlobally();
3604
3618
  }
3605
3619
  function setupConsoleLogSpy() {
3606
3620
  const stdout = new Writable({
@@ -3641,6 +3655,13 @@ async function withEnv(name, fn) {
3641
3655
  await env.teardown(globalThis);
3642
3656
  }
3643
3657
  }
3658
+ async function runSetupFiles(config) {
3659
+ const files = toArray(config.setupFiles);
3660
+ await Promise.all(files.map(async (file) => {
3661
+ process.__vitest_worker__.moduleCache.delete(file);
3662
+ await import(file);
3663
+ }));
3664
+ }
3644
3665
 
3645
3666
  function processError(err) {
3646
3667
  if (!err)
@@ -3652,7 +3673,7 @@ function processError(err) {
3652
3673
  return err;
3653
3674
  }
3654
3675
 
3655
- async function collectTests(paths) {
3676
+ async function collectTests(paths, config) {
3656
3677
  const files = [];
3657
3678
  for (const filepath of paths) {
3658
3679
  const file = {
@@ -3667,6 +3688,7 @@ async function collectTests(paths) {
3667
3688
  setHooks(file, createSuiteHooks());
3668
3689
  clearContext();
3669
3690
  try {
3691
+ await runSetupFiles(config);
3670
3692
  await import(filepath);
3671
3693
  for (const c of [defaultSuite, ...context.tasks]) {
3672
3694
  if (c.type === "test") {
@@ -3700,7 +3722,7 @@ async function collectTests(paths) {
3700
3722
  return files;
3701
3723
  }
3702
3724
 
3703
- async function callHook(suite, name, args) {
3725
+ async function callSuiteHook(suite, name, args) {
3704
3726
  await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)));
3705
3727
  }
3706
3728
  function updateTask(task) {
@@ -3717,7 +3739,7 @@ async function runTest(test) {
3717
3739
  getSnapshotClient().setTest(test);
3718
3740
  process.__vitest_worker__.current = test;
3719
3741
  try {
3720
- await callHook(test.suite, "beforeEach", [test, test.suite]);
3742
+ await callSuiteHook(test.suite, "beforeEach", [test, test.suite]);
3721
3743
  await getFn(test)();
3722
3744
  test.result.state = "pass";
3723
3745
  } catch (e) {
@@ -3725,7 +3747,7 @@ async function runTest(test) {
3725
3747
  test.result.error = processError(e);
3726
3748
  }
3727
3749
  try {
3728
- await callHook(test.suite, "afterEach", [test, test.suite]);
3750
+ await callSuiteHook(test.suite, "afterEach", [test, test.suite]);
3729
3751
  } catch (e) {
3730
3752
  test.result.state = "fail";
3731
3753
  test.result.error = processError(e);
@@ -3750,7 +3772,7 @@ async function runSuite(suite) {
3750
3772
  suite.result.state = "todo";
3751
3773
  } else {
3752
3774
  try {
3753
- await callHook(suite, "beforeAll", [suite]);
3775
+ await callSuiteHook(suite, "beforeAll", [suite]);
3754
3776
  for (const tasksGroup of partitionSuiteChildren(suite)) {
3755
3777
  const computeMode = tasksGroup[0].computeMode;
3756
3778
  if (computeMode === "serial") {
@@ -3760,7 +3782,7 @@ async function runSuite(suite) {
3760
3782
  await Promise.all(tasksGroup.map((c) => runSuiteChild(c)));
3761
3783
  }
3762
3784
  }
3763
- await callHook(suite, "afterAll", [suite]);
3785
+ await callSuiteHook(suite, "afterAll", [suite]);
3764
3786
  } catch (e) {
3765
3787
  suite.result.state = "fail";
3766
3788
  suite.result.error = processError(e);
@@ -3787,8 +3809,8 @@ async function runSuites(suites) {
3787
3809
  for (const suite of suites)
3788
3810
  await runSuite(suite);
3789
3811
  }
3790
- async function startTests(paths) {
3791
- const files = await collectTests(paths);
3812
+ async function startTests(paths, config) {
3813
+ const files = await collectTests(paths, config);
3792
3814
  send("onCollected", files);
3793
3815
  await runSuites(files);
3794
3816
  await getSnapshotClient().saveSnap();
@@ -3797,7 +3819,7 @@ async function startTests(paths) {
3797
3819
  async function run(files, config) {
3798
3820
  await setupGlobalEnv(config);
3799
3821
  await withEnv(config.environment, async () => {
3800
- await startTests(files);
3822
+ await startTests(files, config);
3801
3823
  });
3802
3824
  }
3803
3825
 
@@ -1,4 +1,5 @@
1
1
  import { existsSync, promises } from 'fs';
2
+ import { relative } from 'path';
2
3
  import require$$0 from 'tty';
3
4
  import { SourceMapConsumer } from 'source-map';
4
5
  import { n as notNullish } from './utils-9dcc4050.js';
@@ -1262,24 +1263,22 @@ async function printError(error) {
1262
1263
  stack: error
1263
1264
  };
1264
1265
  }
1265
- let codeFramePrinted = false;
1266
1266
  const stackStr = e.stack || e.stackStr || "";
1267
1267
  const stacks = parseStack(stackStr);
1268
- const nearest = stacks.find((stack) => !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file));
1269
- if (nearest) {
1270
- const pos = await getSourcePos(ctx, nearest);
1271
- if (pos && existsSync(nearest.file)) {
1272
- const sourceCode = await promises.readFile(nearest.file, "utf-8");
1273
- printErrorMessage(e);
1274
- await printStack(ctx, stacks, nearest, (s) => {
1275
- if (s === nearest)
1276
- ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
1277
- });
1278
- codeFramePrinted = true;
1279
- }
1280
- }
1281
- if (!codeFramePrinted)
1268
+ if (!stacks.length) {
1282
1269
  console.error(e);
1270
+ } else {
1271
+ const nearest = stacks.find((stack) => {
1272
+ return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
1273
+ });
1274
+ printErrorMessage(e);
1275
+ await printStack(ctx, stacks, nearest, async (s, pos) => {
1276
+ if (s === nearest) {
1277
+ const sourceCode = await promises.readFile(nearest.file, "utf-8");
1278
+ ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
1279
+ }
1280
+ });
1281
+ }
1283
1282
  if (e.showDiff)
1284
1283
  displayDiff(e.actual, e.expected);
1285
1284
  }
@@ -1302,8 +1301,9 @@ async function printStack(ctx, stack, highlight, onStack) {
1302
1301
  for (const frame of stack) {
1303
1302
  const pos = await getSourcePos(ctx, frame) || frame;
1304
1303
  const color = frame === highlight ? c.yellow : c.gray;
1305
- ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${frame.file}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
1306
- onStack == null ? void 0 : onStack(frame);
1304
+ const path = relative(ctx.config.root, frame.file);
1305
+ ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
1306
+ onStack == null ? void 0 : onStack(frame, pos);
1307
1307
  if (frame.file in ctx.state.filesMap)
1308
1308
  break;
1309
1309
  }
@@ -1,8 +1,8 @@
1
1
  import { g as globalApis } from './constants-d4c70610.js';
2
- import { i as index } from './index-e37648e9.js';
2
+ import { i as index } from './index-bf952d9c.js';
3
3
  import 'path';
4
4
  import 'url';
5
- import './suite-819c135e.js';
5
+ import './suite-1bc54c1b.js';
6
6
  import './index-6427e0f2.js';
7
7
  import 'chai';
8
8
  import 'sinon';
@@ -0,0 +1,33 @@
1
+ import { g as getCurrentSuite, w as withTimeout, a as getDefaultHookTimeout, s as suite, t as test, d as describe, i as it } from './suite-1bc54c1b.js';
2
+ import chai, { assert, should, expect } from 'chai';
3
+ import sinon from 'sinon';
4
+
5
+ const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
6
+ const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
7
+ const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
8
+ const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
9
+
10
+ const { mock, spy, stub } = sinon;
11
+ sinon.fn = sinon.spy;
12
+
13
+ var index = /*#__PURE__*/Object.freeze({
14
+ __proto__: null,
15
+ suite: suite,
16
+ test: test,
17
+ describe: describe,
18
+ it: it,
19
+ beforeAll: beforeAll,
20
+ afterAll: afterAll,
21
+ beforeEach: beforeEach,
22
+ afterEach: afterEach,
23
+ assert: assert,
24
+ should: should,
25
+ expect: expect,
26
+ chai: chai,
27
+ sinon: sinon,
28
+ mock: mock,
29
+ spy: spy,
30
+ stub: stub
31
+ });
32
+
33
+ export { afterAll as a, beforeAll as b, beforeEach as c, afterEach as d, stub as e, index as i, mock as m, spy as s };
package/dist/index.d.ts CHANGED
@@ -234,7 +234,7 @@ interface SuiteCollector {
234
234
  on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
235
235
  }
236
236
  declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
237
- interface GlobalContext {
237
+ interface RuntimeContext {
238
238
  tasks: (SuiteCollector | Test)[];
239
239
  currentSuite: SuiteCollector | null;
240
240
  }
@@ -393,11 +393,14 @@ interface UserOptions {
393
393
  hookTimeout?: number;
394
394
  /**
395
395
  * Silent mode
396
- * TODO: implement this
397
396
  *
398
397
  * @default false
399
398
  */
400
399
  silent?: boolean;
400
+ /**
401
+ * Path to setup files
402
+ */
403
+ setupFiles?: string | string[];
401
404
  }
402
405
  interface CliOptions extends UserOptions {
403
406
  /**
@@ -469,13 +472,6 @@ declare const suite: {
469
472
  concurrent: (suiteName: string) => SuiteCollector;
470
473
  };
471
474
  };
472
- declare const defaultSuite: SuiteCollector;
473
- declare function createSuiteHooks(): {
474
- beforeAll: never[];
475
- afterAll: never[];
476
- beforeEach: never[];
477
- afterEach: never[];
478
- };
479
475
  declare const test: {
480
476
  (name: string, fn: TestFunction, timeout?: number | undefined): void;
481
477
  concurrent: {
@@ -539,11 +535,6 @@ declare const it: {
539
535
  concurrent(name: string): void;
540
536
  };
541
537
  };
542
- declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
543
- declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
544
- declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
545
- declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
546
- declare function clearContext(): void;
547
538
  declare global {
548
539
  namespace NodeJS {
549
540
  interface Process {
@@ -552,11 +543,17 @@ declare global {
552
543
  rpc: RpcCall;
553
544
  send: RpcSend;
554
545
  current?: Test;
546
+ moduleCache: Map<string, ModuleCache>;
555
547
  };
556
548
  }
557
549
  }
558
550
  }
559
551
 
552
+ declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
553
+ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
554
+ declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
555
+ declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
556
+
560
557
  declare const mock: sinon.SinonMockStatic;
561
558
  declare const spy: sinon.SinonSpyStatic;
562
559
  declare const stub: sinon.SinonStubStatic;
@@ -626,4 +623,4 @@ declare global {
626
623
  }
627
624
  }
628
625
 
629
- export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, GlobalContext, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, clearContext, createSuiteHooks, defaultSuite, describe, it, mock, spy, stub, suite, test };
626
+ export { Arrayable, Awaitable, CliOptions, ComputeMode, Environment, EnvironmentReturn, File, HookListener, ModuleCache, Nullable, Reporter, ResolvedConfig, RpcCall, RpcMap, RpcPayload, RpcSend, RunMode, RuntimeContext, SnapshotData, SnapshotMatchOptions, SnapshotResult, SnapshotStateOptions, SnapshotSummary, SnapshotUpdateState, Suite, SuiteCollector, SuiteHooks, Task, TaskBase, TaskResult, TaskResultPack, TaskState, Test, TestCollector, TestFactory, TestFunction, UncheckedSnapshot, UserConsoleLog, UserOptions, VitestContext, WorkerContext, afterAll, afterEach, beforeAll, beforeEach, describe, it, mock, spy, stub, suite, test };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { e as afterAll, g as afterEach, b as beforeAll, f as beforeEach, h as clearContext, c as createSuiteHooks, d as defaultSuite, a as describe, i as it, s as suite, t as test } from './suite-819c135e.js';
1
+ export { d as describe, i as it, s as suite, t as test } from './suite-1bc54c1b.js';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, m as mock, s as spy, e as stub } from './index-bf952d9c.js';
2
3
  export { assert, default as chai, expect, should } from 'chai';
3
- export { m as mock, s as spy, a as stub } from './index-e37648e9.js';
4
4
  export { default as sinon } from 'sinon';
5
5
  import './index-6427e0f2.js';
@@ -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.75",
3
+ "version": "0.0.76",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -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 };