vitest 4.0.17 → 4.1.0-beta.2

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.
Files changed (74) hide show
  1. package/LICENSE.md +36 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
  5. package/dist/chunks/{base.XJJQZiKB.js → base.DiopZV8F.js} +49 -14
  6. package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.BoqSLF53.js} +1 -1
  7. package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.BE4kbYok.d.ts} +4 -1
  8. package/dist/chunks/{cac.jRCLJDDc.js → cac.C4jjt2RX.js} +816 -14
  9. package/dist/chunks/{cli-api.Cx2DW4Bc.js → cli-api.ChbI1JU9.js} +412 -166
  10. package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.Cr1Ep39N.d.ts} +13 -11
  11. package/dist/chunks/{console.Cf-YriPC.js → console.CNlG1KsP.js} +3 -2
  12. package/dist/chunks/{constants.D_Q9UYh-.js → constants.B63TT-Bl.js} +1 -1
  13. package/dist/chunks/coverage.tyqbzn4W.js +1001 -0
  14. package/dist/chunks/{creator.DAmOKTvJ.js → creator.yyCHuw5R.js} +33 -2
  15. package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.JeWMqlOm.d.ts} +1 -1
  16. package/dist/chunks/{globals.DOayXfHP.js → globals.C6Ecf1TO.js} +11 -10
  17. package/dist/chunks/{index.M8mOzt4Y.js → index.B-iBE_Gx.js} +21 -5
  18. package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
  19. package/dist/chunks/{index.6Qv1eEA6.js → index.CAN630q3.js} +20 -8
  20. package/dist/chunks/{index.C5r1PdPD.js → index.CFulQRmC.js} +1 -1
  21. package/dist/chunks/{index.Z5E_ObnR.js → index.CouFDptX.js} +4 -2
  22. package/dist/chunks/{init-forks.BC6ZwHQN.js → init-forks.BnCXPazU.js} +1 -1
  23. package/dist/chunks/{init-threads.CxSxLC0N.js → init-threads.Cyh2PqXi.js} +1 -1
  24. package/dist/chunks/{init.C9kljSTm.js → init.B95Mm0Iz.js} +65 -12
  25. package/dist/chunks/native.mV0-490A.js +148 -0
  26. package/dist/chunks/nativeModuleMocker.D_q5sFv6.js +206 -0
  27. package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
  28. package/dist/chunks/{node.Ce0vMQM7.js → node.CrSEwhm4.js} +1 -1
  29. package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.C9o5bttz.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.7faYdkxy.d.ts} +146 -49
  31. package/dist/chunks/rpc.DcRWTy5G.js +148 -0
  32. package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.CM7x9-sm.d.ts} +1 -0
  33. package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.cvFp-ao9.js} +2 -2
  34. package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.BK-u7y4N.js} +182 -391
  35. package/dist/chunks/{vi.2VT5v0um.js → test.G82XYNFk.js} +505 -119
  36. package/dist/chunks/{utils.DvEY5TfP.js → utils.DT4VyRyl.js} +5 -1
  37. package/dist/chunks/{vm.CMjifoPa.js → vm.BdLtzhnj.js} +15 -11
  38. package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.CPzI2ZzJ.d.ts} +2 -2
  39. package/dist/cli.js +4 -3
  40. package/dist/config.d.ts +11 -11
  41. package/dist/config.js +1 -1
  42. package/dist/coverage.d.ts +10 -8
  43. package/dist/coverage.js +7 -4
  44. package/dist/environments.js +2 -0
  45. package/dist/index.d.ts +30 -23
  46. package/dist/index.js +9 -8
  47. package/dist/module-evaluator.d.ts +10 -1
  48. package/dist/module-evaluator.js +1 -5
  49. package/dist/node.d.ts +13 -12
  50. package/dist/node.js +27 -25
  51. package/dist/nodejs-worker-loader.js +41 -0
  52. package/dist/reporters.d.ts +8 -8
  53. package/dist/reporters.js +4 -2
  54. package/dist/runners.d.ts +24 -4
  55. package/dist/runners.js +6 -6
  56. package/dist/runtime.d.ts +6 -0
  57. package/dist/runtime.js +35 -0
  58. package/dist/snapshot.js +4 -2
  59. package/dist/suite.js +4 -2
  60. package/dist/worker.d.ts +8 -7
  61. package/dist/worker.js +25 -20
  62. package/dist/workers/forks.js +21 -16
  63. package/dist/workers/runVmTests.js +11 -13
  64. package/dist/workers/threads.js +21 -16
  65. package/dist/workers/vmForks.js +14 -11
  66. package/dist/workers/vmThreads.js +14 -11
  67. package/package.json +28 -29
  68. package/suppress-warnings.cjs +1 -0
  69. package/dist/chunks/date.Bq6ZW5rf.js +0 -73
  70. package/dist/chunks/rpc.BoxB0q7B.js +0 -76
  71. package/dist/chunks/test.B8ej_ZHS.js +0 -254
  72. package/dist/mocker.d.ts +0 -1
  73. package/dist/mocker.js +0 -1
  74. package/dist/module-runner.js +0 -17
@@ -5,7 +5,7 @@ import { detectPackageManager, installPackage } from './index.D3XRDfWc.js';
5
5
  import { p as prompt, a as any } from './index.D4KonVSU.js';
6
6
  import { x } from 'tinyexec';
7
7
  import c from 'tinyrainbow';
8
- import { c as configFiles } from './constants.D_Q9UYh-.js';
8
+ import { c as configFiles } from './constants.B63TT-Bl.js';
9
9
  import 'node:process';
10
10
  import 'node:module';
11
11
  import 'node:url';
@@ -226,6 +226,37 @@ import { expect, test } from 'vitest'
226
226
  import { render } from 'vitest-browser-qwik'
227
227
  import HelloWorld from './HelloWorld.tsx'
228
228
 
229
+ test('renders name', async () => {
230
+ const { getByText } = render(<HelloWorld name="Vitest" />)
231
+ await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
232
+ })
233
+ `
234
+ };
235
+ const preactExample = {
236
+ name: "HelloWorld.jsx",
237
+ js: `
238
+ export default function HelloWorld({ name }) {
239
+ return (
240
+ <div>
241
+ <h1>Hello {name}!</h1>
242
+ </div>
243
+ )
244
+ }
245
+ `,
246
+ ts: `
247
+ export default function HelloWorld({ name }: { name: string }) {
248
+ return (
249
+ <div>
250
+ <h1>Hello {name}!</h1>
251
+ </div>
252
+ )
253
+ }
254
+ `,
255
+ test: `
256
+ import { expect, test } from 'vitest'
257
+ import { render } from 'vitest-browser-preact'
258
+ import HelloWorld from './HelloWorld.<EXT>x'
259
+
229
260
  test('renders name', async () => {
230
261
  const { getByText } = render(<HelloWorld name="Vitest" />)
231
262
  await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
@@ -276,7 +307,7 @@ function getExampleTest(framework) {
276
307
  ...jsxExample,
277
308
  test: jsxExample.test.replace("@testing-library/jsx", `@testing-library/${framework}`)
278
309
  };
279
- case "preact":
310
+ case "preact": return preactExample;
280
311
  case "react": return {
281
312
  ...jsxExample,
282
313
  test: jsxExample.test.replace("@testing-library/jsx", `vitest-browser-${framework}`)
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
2
2
  import { Plugin } from '@vitest/pretty-format';
3
3
  import { SnapshotState } from '@vitest/snapshot';
4
4
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
5
- import { U as UserConsoleLog } from './rpc.d.RH3apGEf.js';
5
+ import { U as UserConsoleLog } from './rpc.d.CM7x9-sm.js';
6
6
 
7
7
  interface SnapshotMatcher<T> {
8
8
  <U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
@@ -1,22 +1,23 @@
1
- import { g as globalApis } from './constants.D_Q9UYh-.js';
2
- import { i as index } from './index.Z5E_ObnR.js';
3
- import './vi.2VT5v0um.js';
4
- import '@vitest/expect';
1
+ import { g as globalApis } from './constants.B63TT-Bl.js';
2
+ import { i as index } from './index.CouFDptX.js';
3
+ import './test.G82XYNFk.js';
5
4
  import '@vitest/runner';
6
- import './utils.DvEY5TfP.js';
5
+ import '@vitest/utils/helpers';
7
6
  import '@vitest/utils/timers';
7
+ import './benchmark.BoqSLF53.js';
8
8
  import '@vitest/runner/utils';
9
- import '@vitest/snapshot';
9
+ import './utils.DT4VyRyl.js';
10
+ import '@vitest/expect';
10
11
  import '@vitest/utils/error';
11
- import '@vitest/utils/helpers';
12
+ import 'pathe';
13
+ import '@vitest/snapshot';
12
14
  import '@vitest/spy';
13
15
  import '@vitest/utils/offset';
14
16
  import '@vitest/utils/source-map';
15
17
  import './_commonjsHelpers.D26ty3Ew.js';
16
- import './date.Bq6ZW5rf.js';
17
- import './benchmark.B3N2zMcH.js';
18
+ import './rpc.DcRWTy5G.js';
19
+ import './index.Chj8NDwU.js';
18
20
  import './evaluatedModules.Dg1zASAC.js';
19
- import 'pathe';
20
21
  import 'vite/module-runner';
21
22
  import 'expect-type';
22
23
 
@@ -496,13 +496,23 @@ function countTestErrors(tasks) {
496
496
  }
497
497
  function getStateString$1(tasks, name = "tests", showTotal = true) {
498
498
  if (tasks.length === 0) return c.dim(`no ${name}`);
499
- const passed = tasks.reduce((acc, i) => i.result?.state === "pass" ? acc + 1 : acc, 0);
499
+ const passed = tasks.reduce((acc, i) => {
500
+ // Exclude expected failures from passed count
501
+ if (i.result?.state === "pass" && i.type === "test" && i.fails) return acc;
502
+ return i.result?.state === "pass" ? acc + 1 : acc;
503
+ }, 0);
500
504
  const failed = tasks.reduce((acc, i) => i.result?.state === "fail" ? acc + 1 : acc, 0);
501
505
  const skipped = tasks.reduce((acc, i) => i.mode === "skip" ? acc + 1 : acc, 0);
502
506
  const todo = tasks.reduce((acc, i) => i.mode === "todo" ? acc + 1 : acc, 0);
507
+ const expectedFail = tasks.reduce((acc, i) => {
508
+ // Count tests that are marked as .fails and passed (which means they failed as expected)
509
+ if (i.result?.state === "pass" && i.type === "test" && i.fails) return acc + 1;
510
+ return acc;
511
+ }, 0);
503
512
  return [
504
513
  failed ? c.bold(c.red(`${failed} failed`)) : null,
505
514
  passed ? c.bold(c.green(`${passed} passed`)) : null,
515
+ expectedFail ? c.cyan(`${expectedFail} expected fail`) : null,
506
516
  skipped ? c.yellow(`${skipped} skipped`) : null,
507
517
  todo ? c.gray(`${todo} todo`) : null
508
518
  ].filter(Boolean).join(c.dim(" | ")) + (showTotal ? c.gray(` (${tasks.length})`) : "");
@@ -1292,7 +1302,10 @@ class SummaryReporter {
1292
1302
  stats.tests.delete(test.id);
1293
1303
  stats.completed++;
1294
1304
  const result = test.result();
1295
- if (result?.state === "passed") this.tests.passed++;
1305
+ if (result?.state === "passed")
1306
+ // Check if this is an expected failure (test.fails && passed)
1307
+ if (test.options.fails) this.tests.expectedFail++;
1308
+ else this.tests.passed++;
1296
1309
  else if (result?.state === "failed") this.tests.failed++;
1297
1310
  else if (!result?.state || result?.state === "skipped") this.tests.skipped++;
1298
1311
  this.renderer.schedule();
@@ -1373,6 +1386,7 @@ function emptyCounters() {
1373
1386
  failed: 0,
1374
1387
  skipped: 0,
1375
1388
  todo: 0,
1389
+ expectedFail: 0,
1376
1390
  total: 0
1377
1391
  };
1378
1392
  }
@@ -1380,6 +1394,7 @@ function getStateString(entry) {
1380
1394
  return [
1381
1395
  entry.failed ? c.bold(c.red(`${entry.failed} failed`)) : null,
1382
1396
  c.bold(c.green(`${entry.passed} passed`)),
1397
+ entry.expectedFail ? c.cyan(`${entry.expectedFail} expected fail`) : null,
1383
1398
  entry.skipped ? c.yellow(`${entry.skipped} skipped`) : null,
1384
1399
  entry.todo ? c.gray(`${entry.todo} todo`) : null
1385
1400
  ].filter(Boolean).join(c.dim(" | ")) + c.gray(` (${entry.total})`);
@@ -2599,7 +2614,7 @@ async function collectTests(ctx, filepath) {
2599
2614
  });
2600
2615
  calculateSuiteHash(file);
2601
2616
  const hasOnly = someTasksAreOnly(file);
2602
- interpretTaskModes(file, ctx.config.testNamePattern, void 0, hasOnly, false, ctx.config.allowOnly);
2617
+ interpretTaskModes(file, ctx.config.testNamePattern, void 0, void 0, void 0, hasOnly, false, ctx.config.allowOnly);
2603
2618
  return {
2604
2619
  file,
2605
2620
  parsed: request.code,
@@ -3410,7 +3425,8 @@ class JsonReporter {
3410
3425
  duration: t.result?.duration,
3411
3426
  failureMessages: t.result?.errors?.map((e) => e.stack || e.message) || [],
3412
3427
  location: t.location,
3413
- meta: t.meta
3428
+ meta: t.meta,
3429
+ tags: t.tags || []
3414
3430
  };
3415
3431
  });
3416
3432
  if (tests.some((t) => t.result?.state === "run" || t.result?.state === "queued")) this.ctx.logger.warn("WARNING: Some tests are still running when generating the JSON report.This is likely an internal bug in Vitest.Please report it to https://github.com/vitest-dev/vitest/issues");
@@ -3677,7 +3693,7 @@ class JUnitReporter {
3677
3693
  await this.writeElement("testsuite", {
3678
3694
  name: filename,
3679
3695
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
3680
- hostname: hostname(),
3696
+ hostname: this.options.hostname || hostname(),
3681
3697
  tests: file.tasks.length,
3682
3698
  failures: file.stats.failures,
3683
3699
  errors: 0,