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.
package/dist/entry.js CHANGED
@@ -1,13 +1,15 @@
1
+ import { Console } from 'console';
2
+ import { Writable } from 'stream';
1
3
  import { importModule } from 'local-pkg';
2
4
  import chai, { expect, util } from 'chai';
3
5
  import SinonChai from 'sinon-chai';
4
6
  import Subset from 'chai-subset';
5
7
  import path, { basename } from 'path';
6
- 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';
7
9
  import fs from 'fs';
8
- import { d as c$1, l as generateDiff } from './error-fb6ff2e6.js';
10
+ import { d as c$1, m as generateDiff } from './error-1df12c37.js';
9
11
  import { performance } from 'perf_hooks';
10
- 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';
11
13
  import { n as nanoid } from './index-6427e0f2.js';
12
14
  import 'tty';
13
15
  import 'source-map';
@@ -246,8 +248,15 @@ var jsdom = {
246
248
  url: "http://localhost:3000"
247
249
  });
248
250
  const keys = KEYS.concat(Object.getOwnPropertyNames(dom.window)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
249
- for (const key of keys)
250
- 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;
251
260
  return {
252
261
  teardown(global2) {
253
262
  keys.forEach((key) => delete global2[key]);
@@ -262,8 +271,15 @@ var happy = {
262
271
  const { Window } = await importModule("happy-dom");
263
272
  const win = new Window();
264
273
  const keys = KEYS.concat(Object.getOwnPropertyNames(win)).filter((k) => !k.startsWith("_")).filter((k) => !(k in global));
265
- for (const key of keys)
266
- 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;
267
283
  return {
268
284
  teardown(global2) {
269
285
  win.happyDOM.cancelAsync();
@@ -2829,7 +2845,7 @@ class SnapshotState {
2829
2845
  this._uncheckedKeys.delete(key);
2830
2846
  const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
2831
2847
  const expected = isInline ? inlineSnapshot : this._snapshotData[key];
2832
- const pass = expected === receivedSerialized;
2848
+ const pass = (expected == null ? void 0 : expected.trim()) === (receivedSerialized == null ? void 0 : receivedSerialized.trim());
2833
2849
  const hasSnapshot = expected !== void 0;
2834
2850
  const snapshotIsPersisted = isInline || fs.existsSync(this._snapshotPath);
2835
2851
  if (pass && !isInline) {
@@ -2907,13 +2923,15 @@ class SnapshotClient {
2907
2923
  clearTest() {
2908
2924
  this.test = void 0;
2909
2925
  }
2910
- assert(received, message) {
2926
+ assert(received, message, inlineSnapshot) {
2911
2927
  if (!this.test)
2912
- throw new Error("Snapshot can't not be used outside of test");
2928
+ throw new Error("Snapshot cannot be used outside of test");
2929
+ const testName = getNames(this.test).slice(1).join(" > ");
2913
2930
  const { actual, expected, key, pass } = this.snapshotState.match({
2914
- testName: getNames(this.test).slice(1).join(" > "),
2931
+ testName,
2915
2932
  received,
2916
- isInline: false
2933
+ isInline: !!inlineSnapshot,
2934
+ inlineSnapshot: inlineSnapshot == null ? void 0 : inlineSnapshot.trim()
2917
2935
  });
2918
2936
  if (!pass) {
2919
2937
  expect(actual.trim()).equals(expected ? expected.trim() : "", message || `Snapshot name: \`${key}\``);
@@ -2968,6 +2986,10 @@ function SnapshotPlugin() {
2968
2986
  getSnapshotClient().assert(expected, message);
2969
2987
  });
2970
2988
  }
2989
+ utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function(inlineSnapshot, message) {
2990
+ const expected = utils.flag(this, "object");
2991
+ getSnapshotClient().assert(expected, message, inlineSnapshot);
2992
+ });
2971
2993
  };
2972
2994
  }
2973
2995
 
@@ -3473,6 +3495,9 @@ function JestChaiExpect() {
3473
3495
  def("toHaveLength", function(length) {
3474
3496
  return this.have.length(length);
3475
3497
  });
3498
+ def("toHaveProperty", function(...args) {
3499
+ return this.have.deep.nested.property(...args);
3500
+ });
3476
3501
  def("toBeCloseTo", function(number, numDigits = 2) {
3477
3502
  utils.expectTypes(this, ["number"]);
3478
3503
  return this.closeTo(number, numDigits);
@@ -3581,10 +3606,46 @@ async function setupChai() {
3581
3606
  installed = true;
3582
3607
  }
3583
3608
 
3609
+ let globalSetup = false;
3584
3610
  async function setupGlobalEnv(config) {
3611
+ if (globalSetup)
3612
+ return;
3613
+ globalSetup = true;
3614
+ setupConsoleLogSpy();
3585
3615
  await setupChai();
3586
3616
  if (config.global)
3587
- (await import('./global-e40b54d6.js')).registerApiGlobally();
3617
+ (await import('./global-784f167d.js')).registerApiGlobally();
3618
+ }
3619
+ function setupConsoleLogSpy() {
3620
+ const stdout = new Writable({
3621
+ write(data, encoding, callback) {
3622
+ var _a;
3623
+ send("log", {
3624
+ type: "stdout",
3625
+ content: String(data),
3626
+ taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
3627
+ });
3628
+ callback();
3629
+ }
3630
+ });
3631
+ const stderr = new Writable({
3632
+ write(data, encoding, callback) {
3633
+ var _a;
3634
+ send("log", {
3635
+ type: "stderr",
3636
+ content: String(data),
3637
+ taskId: (_a = process.__vitest_worker__.current) == null ? void 0 : _a.id
3638
+ });
3639
+ callback();
3640
+ }
3641
+ });
3642
+ const newConsole = new Console({
3643
+ stdout,
3644
+ stderr,
3645
+ colorMode: true,
3646
+ groupIndentation: 2
3647
+ });
3648
+ globalThis.console = newConsole;
3588
3649
  }
3589
3650
  async function withEnv(name, fn) {
3590
3651
  const env = await environments[name].setup(globalThis);
@@ -3594,6 +3655,13 @@ async function withEnv(name, fn) {
3594
3655
  await env.teardown(globalThis);
3595
3656
  }
3596
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
+ }
3597
3665
 
3598
3666
  function processError(err) {
3599
3667
  if (!err)
@@ -3605,7 +3673,7 @@ function processError(err) {
3605
3673
  return err;
3606
3674
  }
3607
3675
 
3608
- async function collectTests(paths) {
3676
+ async function collectTests(paths, config) {
3609
3677
  const files = [];
3610
3678
  for (const filepath of paths) {
3611
3679
  const file = {
@@ -3620,6 +3688,7 @@ async function collectTests(paths) {
3620
3688
  setHooks(file, createSuiteHooks());
3621
3689
  clearContext();
3622
3690
  try {
3691
+ await runSetupFiles(config);
3623
3692
  await import(filepath);
3624
3693
  for (const c of [defaultSuite, ...context.tasks]) {
3625
3694
  if (c.type === "test") {
@@ -3653,7 +3722,7 @@ async function collectTests(paths) {
3653
3722
  return files;
3654
3723
  }
3655
3724
 
3656
- async function callHook(suite, name, args) {
3725
+ async function callSuiteHook(suite, name, args) {
3657
3726
  await Promise.all(getHooks(suite)[name].map((fn) => fn(...args)));
3658
3727
  }
3659
3728
  function updateTask(task) {
@@ -3668,8 +3737,9 @@ async function runTest(test) {
3668
3737
  };
3669
3738
  updateTask(test);
3670
3739
  getSnapshotClient().setTest(test);
3740
+ process.__vitest_worker__.current = test;
3671
3741
  try {
3672
- await callHook(test.suite, "beforeEach", [test, test.suite]);
3742
+ await callSuiteHook(test.suite, "beforeEach", [test, test.suite]);
3673
3743
  await getFn(test)();
3674
3744
  test.result.state = "pass";
3675
3745
  } catch (e) {
@@ -3677,13 +3747,14 @@ async function runTest(test) {
3677
3747
  test.result.error = processError(e);
3678
3748
  }
3679
3749
  try {
3680
- await callHook(test.suite, "afterEach", [test, test.suite]);
3750
+ await callSuiteHook(test.suite, "afterEach", [test, test.suite]);
3681
3751
  } catch (e) {
3682
3752
  test.result.state = "fail";
3683
3753
  test.result.error = processError(e);
3684
3754
  }
3685
3755
  getSnapshotClient().clearTest();
3686
3756
  test.result.end = performance.now();
3757
+ process.__vitest_worker__.current = void 0;
3687
3758
  updateTask(test);
3688
3759
  }
3689
3760
  async function runSuite(suite) {
@@ -3701,7 +3772,7 @@ async function runSuite(suite) {
3701
3772
  suite.result.state = "todo";
3702
3773
  } else {
3703
3774
  try {
3704
- await callHook(suite, "beforeAll", [suite]);
3775
+ await callSuiteHook(suite, "beforeAll", [suite]);
3705
3776
  for (const tasksGroup of partitionSuiteChildren(suite)) {
3706
3777
  const computeMode = tasksGroup[0].computeMode;
3707
3778
  if (computeMode === "serial") {
@@ -3711,7 +3782,7 @@ async function runSuite(suite) {
3711
3782
  await Promise.all(tasksGroup.map((c) => runSuiteChild(c)));
3712
3783
  }
3713
3784
  }
3714
- await callHook(suite, "afterAll", [suite]);
3785
+ await callSuiteHook(suite, "afterAll", [suite]);
3715
3786
  } catch (e) {
3716
3787
  suite.result.state = "fail";
3717
3788
  suite.result.error = processError(e);
@@ -3738,8 +3809,8 @@ async function runSuites(suites) {
3738
3809
  for (const suite of suites)
3739
3810
  await runSuite(suite);
3740
3811
  }
3741
- async function startTests(paths) {
3742
- const files = await collectTests(paths);
3812
+ async function startTests(paths, config) {
3813
+ const files = await collectTests(paths, config);
3743
3814
  send("onCollected", files);
3744
3815
  await runSuites(files);
3745
3816
  await getSnapshotClient().saveSnap();
@@ -3748,7 +3819,7 @@ async function startTests(paths) {
3748
3819
  async function run(files, config) {
3749
3820
  await setupGlobalEnv(config);
3750
3821
  await withEnv(config.environment, async () => {
3751
- await startTests(files);
3822
+ await startTests(files, config);
3752
3823
  });
3753
3824
  }
3754
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';
@@ -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) => 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,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
@@ -149,6 +149,12 @@ interface VitestContext {
149
149
  state: StateManager;
150
150
  snapshot: SnapshotManager;
151
151
  reporter: Reporter;
152
+ console: Console;
153
+ }
154
+ interface UserConsoleLog {
155
+ content: string;
156
+ type: 'stdout' | 'stderr';
157
+ taskId?: string;
152
158
  }
153
159
 
154
160
  declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
@@ -228,7 +234,7 @@ interface SuiteCollector {
228
234
  on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void;
229
235
  }
230
236
  declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
231
- interface GlobalContext {
237
+ interface RuntimeContext {
232
238
  tasks: (SuiteCollector | Test)[];
233
239
  currentSuite: SuiteCollector | null;
234
240
  }
@@ -239,6 +245,7 @@ interface Reporter {
239
245
  onTaskUpdate?: (pack: TaskResultPack) => Awaitable<void>;
240
246
  onWatcherStart?: () => Awaitable<void>;
241
247
  onWatcherRerun?: (files: string[], trigger: string) => Awaitable<void>;
248
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
242
249
  }
243
250
 
244
251
  declare type SnapshotData = Record<string, string>;
@@ -372,8 +379,28 @@ interface UserOptions {
372
379
  */
373
380
  minThreads?: number;
374
381
  interpretDefault?: boolean;
382
+ /**
383
+ * Default timeout of a test in milliseconds
384
+ *
385
+ * @default 5000
386
+ */
375
387
  testTimeout?: number;
388
+ /**
389
+ * Default timeout of a hook in milliseconds
390
+ *
391
+ * @default 5000
392
+ */
376
393
  hookTimeout?: number;
394
+ /**
395
+ * Silent mode
396
+ *
397
+ * @default false
398
+ */
399
+ silent?: boolean;
400
+ /**
401
+ * Path to setup files
402
+ */
403
+ setupFiles?: string | string[];
377
404
  }
378
405
  interface CliOptions extends UserOptions {
379
406
  /**
@@ -407,8 +434,8 @@ interface WorkerContext {
407
434
  invalidates?: string[];
408
435
  }
409
436
  interface RpcMap {
410
- workerReady: [[], void];
411
437
  fetch: [[id: string], TransformResult | null | undefined];
438
+ log: [[UserConsoleLog], void];
412
439
  onCollected: [[files: File[]], void];
413
440
  onFinished: [[], void];
414
441
  onTaskUpdate: [[pack: TaskResultPack], void];
@@ -445,13 +472,6 @@ declare const suite: {
445
472
  concurrent: (suiteName: string) => SuiteCollector;
446
473
  };
447
474
  };
448
- declare const defaultSuite: SuiteCollector;
449
- declare function createSuiteHooks(): {
450
- beforeAll: never[];
451
- afterAll: never[];
452
- beforeEach: never[];
453
- afterEach: never[];
454
- };
455
475
  declare const test: {
456
476
  (name: string, fn: TestFunction, timeout?: number | undefined): void;
457
477
  concurrent: {
@@ -515,11 +535,6 @@ declare const it: {
515
535
  concurrent(name: string): void;
516
536
  };
517
537
  };
518
- declare const beforeAll: (fn: SuiteHooks['beforeAll'][0], timeout?: number | undefined) => void;
519
- declare const afterAll: (fn: SuiteHooks['afterAll'][0], timeout?: number | undefined) => void;
520
- declare const beforeEach: (fn: SuiteHooks['beforeEach'][0], timeout?: number | undefined) => void;
521
- declare const afterEach: (fn: SuiteHooks['afterEach'][0], timeout?: number | undefined) => void;
522
- declare function clearContext(): void;
523
538
  declare global {
524
539
  namespace NodeJS {
525
540
  interface Process {
@@ -527,11 +542,18 @@ declare global {
527
542
  config: ResolvedConfig;
528
543
  rpc: RpcCall;
529
544
  send: RpcSend;
545
+ current?: Test;
546
+ moduleCache: Map<string, ModuleCache>;
530
547
  };
531
548
  }
532
549
  }
533
550
  }
534
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
+
535
557
  declare const mock: sinon.SinonMockStatic;
536
558
  declare const spy: sinon.SinonSpyStatic;
537
559
  declare const stub: sinon.SinonStubStatic;
@@ -551,6 +573,7 @@ declare global {
551
573
  }
552
574
  interface Assertion {
553
575
  toMatchSnapshot(message?: string): Assertion;
576
+ toMatchInlineSnapshot(snapshot?: string, message?: string): Assertion;
554
577
  matchSnapshot(message?: string): Assertion;
555
578
  toEqual(expected: any): void;
556
579
  toStrictEqual(expected: any): void;
@@ -572,6 +595,7 @@ declare global {
572
595
  toBeInstanceOf(c: any): void;
573
596
  toBeCalledTimes(n: number): void;
574
597
  toHaveLength(l: number): void;
598
+ toHaveProperty(p: string, value?: any): void;
575
599
  toBeCloseTo(number: number, numDigits?: number): void;
576
600
  toHaveBeenCalledTimes(n: number): void;
577
601
  toHaveBeenCalledOnce(): void;
@@ -599,4 +623,4 @@ declare global {
599
623
  }
600
624
  }
601
625
 
602
- 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, 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';