vitest 0.0.73 → 0.0.77

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.
@@ -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';
@@ -1246,15 +1247,15 @@ function cliTruncate(text, columns, options) {
1246
1247
 
1247
1248
  const F_RIGHT = "\u2192";
1248
1249
  const F_DOWN = "\u2193";
1249
- const F_UP = "\u2191";
1250
1250
  const F_DOWN_RIGHT = "\u21B3";
1251
1251
  const F_POINTER = "\u276F";
1252
1252
  const F_DOT = "\xB7";
1253
1253
  const F_CHECK = "\u221A";
1254
1254
  const F_CROSS = "\xD7";
1255
+ const F_LONG_DASH = "\u23AF";
1255
1256
 
1256
1257
  async function printError(error) {
1257
- const { server } = process.__vitest__;
1258
+ const ctx = process.__vitest__;
1258
1259
  let e = error;
1259
1260
  if (typeof error === "string") {
1260
1261
  e = {
@@ -1262,38 +1263,51 @@ async function printError(error) {
1262
1263
  stack: error
1263
1264
  };
1264
1265
  }
1265
- let codeFramePrinted = false;
1266
- const stacks = parseStack(e.stack || e.stackStr || "");
1267
- const nearest = stacks.find((stack) => !stack.file.includes("vitest/dist") && server.moduleGraph.getModuleById(stack.file));
1268
- if (nearest) {
1269
- const mod = server.moduleGraph.getModuleById(nearest.file);
1270
- const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
1271
- const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
1272
- if (pos && existsSync(nearest.file)) {
1273
- const sourceCode = await promises.readFile(nearest.file, "utf-8");
1274
- displayErrorMessage(e);
1275
- displayFilePath(nearest.file, pos);
1276
- displayCodeFrame(sourceCode, pos);
1277
- codeFramePrinted = true;
1278
- }
1279
- }
1280
- if (!codeFramePrinted)
1266
+ const stackStr = e.stack || e.stackStr || "";
1267
+ const stacks = parseStack(stackStr);
1268
+ if (!stacks.length) {
1281
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
+ }
1282
1282
  if (e.showDiff)
1283
1283
  displayDiff(e.actual, e.expected);
1284
1284
  }
1285
+ async function getSourcePos(ctx, nearest) {
1286
+ const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
1287
+ const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
1288
+ const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
1289
+ return pos;
1290
+ }
1285
1291
  function displayDiff(actual, expected) {
1286
1292
  console.error(c.gray(generateDiff(stringify(actual), stringify(expected))));
1287
1293
  }
1288
- function displayErrorMessage(error) {
1294
+ function printErrorMessage(error) {
1289
1295
  const errorName = error.name || error.nameStr || "Unknown Error";
1290
1296
  console.error(c.red(`${c.bold(errorName)}: ${error.message}`));
1291
1297
  }
1292
- function displayFilePath(filePath, pos) {
1293
- console.log(c.gray(`${filePath}:${pos.line}:${pos.column}`));
1294
- }
1295
- function displayCodeFrame(sourceCode, pos) {
1296
- console.log(c.yellow(generateCodeFrame(sourceCode, pos)));
1298
+ async function printStack(ctx, stack, highlight, onStack) {
1299
+ if (!stack.length)
1300
+ return;
1301
+ for (const frame of stack) {
1302
+ const pos = await getSourcePos(ctx, frame) || frame;
1303
+ const color = frame === highlight ? c.yellow : c.gray;
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
+ if (frame.file in ctx.state.filesMap)
1308
+ break;
1309
+ }
1310
+ ctx.console.log();
1297
1311
  }
1298
1312
  function getOriginalPos(map, { line, column }) {
1299
1313
  return new Promise((resolve) => {
@@ -1319,12 +1333,12 @@ function posToNumber(source, pos) {
1319
1333
  start += lines[i].length + 1;
1320
1334
  return start + column;
1321
1335
  }
1322
- function generateCodeFrame(source, start = 0, end, range = 2) {
1336
+ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
1323
1337
  start = posToNumber(source, start);
1324
1338
  end = end || start;
1325
1339
  const lines = source.split(splitRE);
1326
1340
  let count = 0;
1327
- const res = [];
1341
+ let res = [];
1328
1342
  function lineNo(no = "") {
1329
1343
  return c.gray(`${String(no).padStart(3, " ")}| `);
1330
1344
  }
@@ -1337,15 +1351,15 @@ function generateCodeFrame(source, start = 0, end, range = 2) {
1337
1351
  const lineLength = lines[j].length;
1338
1352
  if (lineLength > 200)
1339
1353
  return "";
1340
- res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5));
1354
+ res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5 - indent));
1341
1355
  if (j === i) {
1342
1356
  const pad = start - (count - lineLength);
1343
1357
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
1344
- res.push(lineNo() + " ".repeat(pad) + F_UP.repeat(length));
1358
+ res.push(lineNo() + " ".repeat(pad) + c.red("^".repeat(length)));
1345
1359
  } else if (j > i) {
1346
1360
  if (end > count) {
1347
1361
  const length = Math.max(1, Math.min(end - count, lineLength));
1348
- res.push(lineNo() + F_UP.repeat(length));
1362
+ res.push(lineNo() + c.red("^".repeat(length)));
1349
1363
  }
1350
1364
  count += lineLength + 1;
1351
1365
  }
@@ -1353,13 +1367,15 @@ function generateCodeFrame(source, start = 0, end, range = 2) {
1353
1367
  break;
1354
1368
  }
1355
1369
  }
1370
+ if (indent)
1371
+ res = res.map((line) => " ".repeat(indent) + line);
1356
1372
  return res.join("\n");
1357
1373
  }
1358
1374
  function stringify(obj) {
1359
1375
  return String(obj);
1360
1376
  }
1361
1377
  const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
1362
- const stackBarePathRE = /at ()(.+):(\d+):(\d+)$/;
1378
+ const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
1363
1379
  function parseStack(stack) {
1364
1380
  const lines = stack.split("\n");
1365
1381
  const stackFrames = lines.map((raw) => {
@@ -1412,4 +1428,4 @@ function notBlank(line) {
1412
1428
  return typeof line !== "undefined" && line !== null;
1413
1429
  }
1414
1430
 
1415
- export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, c as d, F_DOWN as e, F_DOWN_RIGHT as f, F_DOT as g, F_CHECK as h, F_CROSS as i, cliTruncate as j, F_RIGHT as k, generateDiff as l, printError as p, stringWidth as s };
1431
+ export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, c as d, F_DOWN as e, F_LONG_DASH as f, F_DOWN_RIGHT as g, F_DOT as h, F_CHECK as i, F_CROSS as j, cliTruncate as k, F_RIGHT as l, generateDiff as m, printError as p, stringWidth as s };
@@ -1,9 +1,9 @@
1
- import { g as globalApis } from './constants-d4c70610.js';
2
- import { i as index } from './index-e37648e9.js';
1
+ import { g as globalApis } from './constants-2435fa16.js';
2
+ import { i as index } from './index-6feda5ef.js';
3
3
  import 'path';
4
4
  import 'url';
5
- import './suite-819c135e.js';
6
- import './index-6427e0f2.js';
5
+ import './suite-95be5909.js';
6
+ import './index-9e71c815.js';
7
7
  import 'chai';
8
8
  import 'sinon';
9
9
 
@@ -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-95be5909.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 };
File without changes
package/dist/index.d.ts CHANGED
@@ -149,6 +149,7 @@ interface VitestContext {
149
149
  state: StateManager;
150
150
  snapshot: SnapshotManager;
151
151
  reporter: Reporter;
152
+ console: Console;
152
153
  }
153
154
  interface UserConsoleLog {
154
155
  content: string;
@@ -233,7 +234,7 @@ interface SuiteCollector {
233
234
  on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
234
235
  }
235
236
  declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
236
- interface GlobalContext {
237
+ interface RuntimeContext {
237
238
  tasks: (SuiteCollector | Test)[];
238
239
  currentSuite: SuiteCollector | null;
239
240
  }
@@ -378,8 +379,40 @@ interface UserOptions {
378
379
  */
379
380
  minThreads?: number;
380
381
  interpretDefault?: boolean;
382
+ /**
383
+ * Default timeout of a test in milliseconds
384
+ *
385
+ * @default 5000
386
+ */
381
387
  testTimeout?: number;
388
+ /**
389
+ * Default timeout of a hook in milliseconds
390
+ *
391
+ * @default 5000
392
+ */
382
393
  hookTimeout?: number;
394
+ /**
395
+ * Silent mode
396
+ *
397
+ * @default false
398
+ */
399
+ silent?: boolean;
400
+ /**
401
+ * Open Vitest UI
402
+ */
403
+ open?: boolean;
404
+ /**
405
+ * Path to setup files
406
+ */
407
+ setupFiles?: string | string[];
408
+ /**
409
+ * Listen to port and serve API
410
+ *
411
+ * When set to try, the default port is 55555
412
+ *
413
+ * @default false
414
+ */
415
+ api?: boolean | number;
383
416
  }
384
417
  interface CliOptions extends UserOptions {
385
418
  /**
@@ -451,13 +484,6 @@ declare const suite: {
451
484
  concurrent: (suiteName: string) => SuiteCollector;
452
485
  };
453
486
  };
454
- declare const defaultSuite: SuiteCollector;
455
- declare function createSuiteHooks(): {
456
- beforeAll: never[];
457
- afterAll: never[];
458
- beforeEach: never[];
459
- afterEach: never[];
460
- };
461
487
  declare const test: {
462
488
  (name: string, fn: TestFunction, timeout?: number | undefined): void;
463
489
  concurrent: {
@@ -521,11 +547,6 @@ declare const it: {
521
547
  concurrent(name: string): void;
522
548
  };
523
549
  };
524
- declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
525
- declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
526
- declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
527
- declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
528
- declare function clearContext(): void;
529
550
  declare global {
530
551
  namespace NodeJS {
531
552
  interface Process {
@@ -534,11 +555,17 @@ declare global {
534
555
  rpc: RpcCall;
535
556
  send: RpcSend;
536
557
  current?: Test;
558
+ moduleCache: Map<string, ModuleCache>;
537
559
  };
538
560
  }
539
561
  }
540
562
  }
541
563
 
564
+ declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
565
+ declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
566
+ declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
567
+ declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
568
+
542
569
  declare const mock: sinon.SinonMockStatic;
543
570
  declare const spy: sinon.SinonSpyStatic;
544
571
  declare const stub: sinon.SinonStubStatic;
@@ -558,6 +585,7 @@ declare global {
558
585
  }
559
586
  interface Assertion {
560
587
  toMatchSnapshot(message?: string): Assertion;
588
+ toMatchInlineSnapshot(snapshot?: string, message?: string): Assertion;
561
589
  matchSnapshot(message?: string): Assertion;
562
590
  toEqual(expected: any): void;
563
591
  toStrictEqual(expected: any): void;
@@ -607,4 +635,4 @@ declare global {
607
635
  }
608
636
  }
609
637
 
610
- 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 };
638
+ 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-95be5909.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-6feda5ef.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
- import './index-6427e0f2.js';
5
+ import './index-9e71c815.js';
@@ -0,0 +1,34 @@
1
+ import { stringify } from 'flatted';
2
+ import { A as API_PATH } from './constants-2435fa16.js';
3
+ import 'path';
4
+ import 'url';
5
+
6
+ function sendFlatted(res, data) {
7
+ res.setHeader("Content-Type", "application/json");
8
+ res.write(stringify(data));
9
+ res.statusCode = 200;
10
+ res.end();
11
+ }
12
+ function middlewareAPI() {
13
+ return (req, res, next) => {
14
+ var _a;
15
+ if (!((_a = req.url) == null ? void 0 : _a.startsWith(API_PATH)))
16
+ return next();
17
+ const url = req.url.slice(API_PATH.length);
18
+ const ctx = process.__vitest__;
19
+ if (url === "/") {
20
+ return sendFlatted(res, {
21
+ files: ctx.state.filesMap
22
+ });
23
+ }
24
+ if (url === "/files") {
25
+ return sendFlatted(res, {
26
+ files: Object.keys(ctx.state.filesMap)
27
+ });
28
+ }
29
+ res.statusCode = 404;
30
+ res.end();
31
+ };
32
+ }
33
+
34
+ export { middlewareAPI as default, sendFlatted };
@@ -1,9 +1,41 @@
1
- import { n as nanoid } from './index-6427e0f2.js';
1
+ import { n as nanoid } from './index-9e71c815.js';
2
2
 
3
3
  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
@@ -1,6 +1,6 @@
1
1
  import { resolve, dirname } from 'path';
2
- import { n as nanoid } from './index-6427e0f2.js';
3
- import { b as distDir } from './constants-d4c70610.js';
2
+ import { n as nanoid } from './index-9e71c815.js';
3
+ import { e as distDir } from './constants-2435fa16.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath } from 'url';
6
6
  import vm from 'vm';
@@ -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.73",
3
+ "version": "0.0.77",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -38,22 +38,6 @@
38
38
  "bin",
39
39
  "*.d.ts"
40
40
  ],
41
- "scripts": {
42
- "build": "rimraf dist && rollup -c",
43
- "coverage": "node bin/vitest.mjs -r test/core --coverage",
44
- "dev": "rollup -c -w src",
45
- "docs": "npm -C docs run dev",
46
- "docs:build": "npm -C docs run build",
47
- "docs:serve": "npm -C docs run serve",
48
- "lint": "eslint \"{src,test}/**/*.ts\"",
49
- "prepublishOnly": "nr build",
50
- "release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
51
- "test": "node bin/vitest.mjs -r test/core",
52
- "test:all": "cross-env CI=true pnpm -r --stream --filter !vitest run test --",
53
- "test:ci": "cross-env CI=true pnpm -r --stream --filter !vitest --filter !@vitest/test-fails run test --",
54
- "typecheck": "tsc --noEmit && nr lint",
55
- "ci": "ni && nr typecheck && nr lint && nr build && nr test:all"
56
- },
57
41
  "dependencies": {
58
42
  "@types/chai": "^4.3.0",
59
43
  "@types/chai-subset": "^1.3.3",
@@ -62,6 +46,7 @@
62
46
  "chai": "^4.3.4",
63
47
  "chai-subset": "^1.6.0",
64
48
  "fast-glob": "^3.2.7",
49
+ "flatted": "^3.2.4",
65
50
  "local-pkg": "^0.4.0",
66
51
  "micromatch": "^4.0.4",
67
52
  "piscina": "^3.2.0",
@@ -70,42 +55,24 @@
70
55
  "source-map": "^0.7.3"
71
56
  },
72
57
  "devDependencies": {
73
- "@antfu/eslint-config": "^0.13.1",
74
- "@antfu/ni": "^0.12.0",
75
- "@rollup/plugin-alias": "^3.1.8",
76
- "@rollup/plugin-commonjs": "^21.0.1",
77
- "@rollup/plugin-json": "^4.1.0",
78
- "@rollup/plugin-node-resolve": "^13.0.6",
79
58
  "@types/diff": "^5.0.1",
80
59
  "@types/jsdom": "^16.2.13",
81
60
  "@types/micromatch": "^4.0.2",
82
61
  "@types/natural-compare": "^1.4.1",
83
62
  "@types/node": "^16.11.12",
84
- "@types/sade": "^1.7.3",
85
- "bumpp": "^7.1.1",
86
63
  "c8": "^7.10.0",
87
64
  "cac": "^6.7.12",
88
65
  "cli-truncate": "^3.1.0",
89
- "cross-env": "^7.0.3",
90
66
  "diff": "^5.0.0",
91
- "eslint": "^8.4.1",
92
- "esno": "^0.12.1",
93
67
  "find-up": "^6.2.0",
94
68
  "happy-dom": "^2.24.5",
95
69
  "jsdom": "^19.0.0",
96
70
  "log-update": "^5.0.0",
97
71
  "nanoid": "^3.1.30",
98
72
  "natural-compare": "^1.4.0",
99
- "npm-run-all": "^4.1.5",
100
73
  "picocolors": "^1.0.0",
101
74
  "pretty-format": "^27.4.2",
102
- "rimraf": "^3.0.2",
103
- "rollup-plugin-dts": "^4.0.1",
104
- "rollup-plugin-esbuild": "^4.7.2",
105
- "strip-ansi": "^7.0.1",
106
- "tsup": "^5.11.1",
107
- "typescript": "^4.5.3",
108
- "vite": "^2.7.1"
75
+ "strip-ansi": "^7.0.1"
109
76
  },
110
77
  "peerDependencies": {
111
78
  "c8": "*",
@@ -126,5 +93,10 @@
126
93
  },
127
94
  "engines": {
128
95
  "node": ">=16.0.0"
96
+ },
97
+ "scripts": {
98
+ "build": "rimraf dist && rollup -c",
99
+ "dev": "rollup -c --watch src",
100
+ "typecheck": "tsc --noEmit"
129
101
  }
130
- }
102
+ }