vitest 0.34.1 → 0.34.3

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 (42) hide show
  1. package/LICENSE.md +28 -0
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +1 -1
  4. package/dist/child.js +11 -6
  5. package/dist/{chunk-api-setup.644415c3.js → chunk-api-setup.3b016b1c.js} +26 -16
  6. package/dist/{chunk-install-pkg.dd40cbef.js → chunk-install-pkg.a036014e.js} +8 -4
  7. package/dist/{chunk-integrations-globals.877c84db.js → chunk-integrations-globals.7f4b17bf.js} +5 -4
  8. package/dist/cli.js +11 -7
  9. package/dist/config.cjs +3 -1
  10. package/dist/config.d.ts +3 -3
  11. package/dist/config.js +3 -1
  12. package/dist/coverage.d.ts +3 -3
  13. package/dist/entry-vm.js +5 -4
  14. package/dist/entry.js +5 -4
  15. package/dist/environments.d.ts +3 -3
  16. package/dist/environments.js +11 -2
  17. package/dist/execute.d.ts +139 -0
  18. package/dist/execute.js +1 -1
  19. package/dist/index.d.ts +10 -9
  20. package/dist/index.js +6 -5
  21. package/dist/loader.js +9 -528
  22. package/dist/node.d.ts +4 -4
  23. package/dist/node.js +8 -4
  24. package/dist/{types-3c7dbfa5.d.ts → reporters-2ff87305.d.ts} +72 -5
  25. package/dist/reporters.d.ts +16 -0
  26. package/dist/reporters.js +16 -0
  27. package/dist/runners.d.ts +3 -3
  28. package/dist/runners.js +4 -3
  29. package/dist/{vendor-environments.443ecd82.js → vendor-environments.8eb4d407.js} +28 -10
  30. package/dist/{vendor-execute.9ab1c1a7.js → vendor-execute.a63e187f.js} +416 -211
  31. package/dist/vendor-index.0b5b3600.js +2062 -0
  32. package/dist/{vendor-index.087d1af7.js → vendor-index.29282562.js} +1 -1
  33. package/dist/{vendor-index.eff408fd.js → vendor-index.7178e7a2.js} +1 -1
  34. package/dist/{vendor-node.caa511fc.js → vendor-node.5ce5f335.js} +302 -2757
  35. package/dist/vendor-reporters.f6975b8d.js +2584 -0
  36. package/dist/vendor-tasks.f9d75aed.js +14 -0
  37. package/dist/{vendor-vi.271667ef.js → vendor-vi.597d9e06.js} +3 -2
  38. package/dist/vm.js +14 -6
  39. package/dist/worker.js +12 -6
  40. package/package.json +11 -7
  41. package/reporters.d.ts +1 -0
  42. package/dist/vendor-source-map.e6c1997b.js +0 -747
@@ -1,10 +1,10 @@
1
- import { SnapshotResult, SnapshotStateOptions, SnapshotState } from '@vitest/snapshot';
2
- import { ExpectStatic } from '@vitest/expect';
3
1
  import * as vite from 'vite';
4
2
  import { ViteDevServer, UserConfig as UserConfig$1, TransformResult as TransformResult$1, CommonServerOptions, DepOptimizationConfig, AliasOptions } from 'vite';
5
3
  import * as _vitest_runner from '@vitest/runner';
6
4
  import { File, Test as Test$1, Suite, TaskResultPack, Task, CancelReason, TaskCustom, SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
7
5
  import { RawSourceMap, FetchResult, ViteNodeResolveId, ModuleCacheMap, ViteNodeServerOptions } from 'vite-node';
6
+ import { SnapshotResult, SnapshotStateOptions, SnapshotState } from '@vitest/snapshot';
7
+ import { ExpectStatic } from '@vitest/expect';
8
8
  import { ChainableFunction } from '@vitest/runner/utils';
9
9
  import { ParsedStack, Awaitable as Awaitable$1, ErrorWithDiff, Arrayable as Arrayable$1 } from '@vitest/utils';
10
10
  import { TaskResult, Bench, Options } from 'tinybench';
@@ -739,7 +739,7 @@ declare class Vitest {
739
739
  isFirstRun: boolean;
740
740
  restartsCount: number;
741
741
  runner: ViteNodeRunner;
742
- private coreWorkspace;
742
+ private coreWorkspaceProject;
743
743
  projects: WorkspaceProject[];
744
744
  private projectsTestFiles;
745
745
  constructor(mode: VitestRunMode);
@@ -1118,10 +1118,17 @@ type BirpcReturn<RemoteFunctions, LocalFunctions = {}> = {
1118
1118
  type MockFactoryWithHelper = (importOriginal: <T = unknown>() => Promise<T>) => any;
1119
1119
  type MockFactory = () => any;
1120
1120
  type MockMap = Map<string, Record<string, string | null | MockFactory>>;
1121
+ interface PendingSuiteMock {
1122
+ id: string;
1123
+ importer: string;
1124
+ type: 'mock' | 'unmock';
1125
+ factory?: MockFactory;
1126
+ }
1121
1127
 
1122
1128
  type TransformMode = 'web' | 'ssr';
1123
1129
  interface RuntimeRPC {
1124
1130
  fetch: (id: string, environment: TransformMode) => Promise<FetchResult>;
1131
+ transform: (id: string, environment: TransformMode) => Promise<FetchResult>;
1125
1132
  resolveId: (id: string, importer: string | undefined, environment: TransformMode) => Promise<ViteNodeResolveId | null>;
1126
1133
  getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>;
1127
1134
  onFinished: (files: File[], errors?: unknown[]) => void;
@@ -1228,7 +1235,7 @@ type CoverageOptions<T extends Provider = Provider> = T extends 'istanbul' ? ({
1228
1235
  provider?: T;
1229
1236
  } & (CoverageV8Options));
1230
1237
  /** Fields that have default values. Internally these will always be defined. */
1231
- type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension' | 'reportOnFailure';
1238
+ type FieldsWithDefaultValues = 'enabled' | 'clean' | 'cleanOnRerun' | 'reportsDirectory' | 'exclude' | 'extension' | 'reportOnFailure' | 'allowExternal';
1232
1239
  type ResolvedCoverageOptions<T extends Provider = Provider> = CoverageOptions<T> & Required<Pick<CoverageOptions<T>, FieldsWithDefaultValues>> & {
1233
1240
  reporter: CoverageReporterWithOptions[];
1234
1241
  };
@@ -1344,6 +1351,12 @@ interface BaseCoverageOptions {
1344
1351
  * @default false
1345
1352
  */
1346
1353
  reportOnFailure?: boolean;
1354
+ /**
1355
+ * Collect coverage of files outside the project `root`.
1356
+ *
1357
+ * @default false
1358
+ */
1359
+ allowExternal?: boolean;
1347
1360
  }
1348
1361
  interface CoverageIstanbulOptions extends BaseCoverageOptions {
1349
1362
  /**
@@ -1446,6 +1459,27 @@ interface JSDOMOptions {
1446
1459
  resources?: 'usable' | any;
1447
1460
  }
1448
1461
 
1462
+ /**
1463
+ * Happy DOM options.
1464
+ */
1465
+ interface HappyDOMOptions {
1466
+ width?: number;
1467
+ height?: number;
1468
+ url?: string;
1469
+ settings?: {
1470
+ disableJavaScriptEvaluation?: boolean;
1471
+ disableJavaScriptFileLoading?: boolean;
1472
+ disableCSSFileLoading?: boolean;
1473
+ disableIframePageLoading?: boolean;
1474
+ disableComputedStyleRendering?: boolean;
1475
+ enableFileSystemHttpRequests?: boolean;
1476
+ device?: {
1477
+ prefersColorScheme?: string;
1478
+ mediaType?: string;
1479
+ };
1480
+ };
1481
+ }
1482
+
1449
1483
  interface BenchmarkUserOptions {
1450
1484
  /**
1451
1485
  * Include globs for benchmark test files
@@ -1506,6 +1540,7 @@ interface EnvironmentOptions {
1506
1540
  * jsdom options.
1507
1541
  */
1508
1542
  jsdom?: JSDOMOptions;
1543
+ happyDOM?: HappyDOMOptions;
1509
1544
  [x: string]: unknown;
1510
1545
  }
1511
1546
  type VitestRunMode = 'test' | 'benchmark' | 'typecheck';
@@ -1576,6 +1611,38 @@ interface DepsOptions {
1576
1611
  web?: DepsOptimizationOptions;
1577
1612
  ssr?: DepsOptimizationOptions;
1578
1613
  };
1614
+ web?: {
1615
+ /**
1616
+ * Should Vitest process assets (.png, .svg, .jpg, etc) files and resolve them like Vite does in the browser.
1617
+ *
1618
+ * These module will have a default export equal to the path to the asset, if no query is specified.
1619
+ *
1620
+ * **At the moment, this option only works with `experimentalVmThreads` pool.**
1621
+ *
1622
+ * @default true
1623
+ */
1624
+ transformAssets?: boolean;
1625
+ /**
1626
+ * Should Vitest process CSS (.css, .scss, .sass, etc) files and resolve them like Vite does in the browser.
1627
+ *
1628
+ * If CSS files are disabled with `css` options, this option will just silence UNKNOWN_EXTENSION errors.
1629
+ *
1630
+ * **At the moment, this option only works with `experimentalVmThreads` pool.**
1631
+ *
1632
+ * @default true
1633
+ */
1634
+ transformCss?: boolean;
1635
+ /**
1636
+ * Regexp pattern to match external files that should be transformed.
1637
+ *
1638
+ * By default, files inside `node_modules` are externalized and not transformed.
1639
+ *
1640
+ * **At the moment, this option only works with `experimentalVmThreads` pool.**
1641
+ *
1642
+ * @default []
1643
+ */
1644
+ transformGlobPattern?: RegExp | RegExp[];
1645
+ };
1579
1646
  /**
1580
1647
  * Externalize means that Vite will bypass the package to native Node.
1581
1648
  *
@@ -2223,4 +2290,4 @@ type Context = RootAndTarget & {
2223
2290
  lastActivePath?: string;
2224
2291
  };
2225
2292
 
2226
- export { Arrayable as $, AfterSuiteRunMeta as A, BaseCoverageOptions as B, CoverageOptions as C, DepsOptimizationOptions as D, Environment as E, FakeTimerInstallOpts as F, TypecheckConfig as G, RuntimeRPC as H, InlineConfig as I, JSDOMOptions as J, RunnerRPC as K, ContextTestEnvironment as L, MockFactoryWithHelper as M, ResolvedTestEnvironment as N, ContextRPC as O, ProjectConfig as P, WorkerContext as Q, ResolvedConfig as R, ResolveIdFunction as S, TestSequencer as T, UserConfig as U, VitestRunMode as V, WorkspaceSpec as W, WorkerRPC as X, WorkerGlobalState as Y, Awaitable as Z, Nullable as _, CoverageProvider as a, ArgumentsType$1 as a0, MutableArray as a1, Constructable as a2, ModuleCache as a3, EnvironmentReturn as a4, VmEnvironmentReturn as a5, OnServerRestartHandler as a6, ReportContext as a7, CoverageReporter as a8, CoverageIstanbulOptions as a9, CustomProviderOptions as aa, BenchmarkUserOptions as ab, Benchmark as ac, BenchmarkResult as ad, BenchFunction as ae, CoverageProviderModule as b, ResolvedCoverageOptions as c, CoverageV8Options as d, Vitest as e, WorkspaceProject as f, TestSequencerConstructor as g, BenchmarkAPI as h, RuntimeConfig as i, UserConsoleLog as j, ModuleGraphData as k, Reporter as l, RawErrsMap as m, TscErrorInfo as n, CollectLineNumbers as o, CollectLines as p, RootAndTarget as q, Context as r, startVitest as s, BuiltinEnvironment as t, VitestEnvironment as u, VitestPool as v, CSSModuleScopeStrategy as w, ApiConfig as x, EnvironmentOptions as y, TransformModePatterns as z };
2293
+ export { ResolveIdFunction as $, AfterSuiteRunMeta as A, BaseCoverageOptions as B, CoverageOptions as C, VitestPool as D, Environment as E, FakeTimerInstallOpts as F, CSSModuleScopeStrategy as G, HappyDOMOptions as H, ApiConfig as I, JSDOMOptions as J, EnvironmentOptions as K, DepsOptimizationOptions as L, MockFactory as M, TransformModePatterns as N, InlineConfig as O, ProjectConfig as P, TypecheckConfig as Q, ResolvedConfig as R, RunnerRPC as S, TestSequencer as T, UserConfig as U, VitestRunMode as V, WorkspaceSpec as W, ContextTestEnvironment as X, ResolvedTestEnvironment as Y, ContextRPC as Z, WorkerContext as _, CoverageProvider as a, WorkerRPC as a0, Awaitable as a1, Nullable as a2, Arrayable as a3, ArgumentsType$1 as a4, MutableArray as a5, Constructable as a6, ModuleCache as a7, EnvironmentReturn as a8, VmEnvironmentReturn as a9, OnServerRestartHandler as aa, ReportContext as ab, CoverageReporter as ac, CoverageIstanbulOptions as ad, CustomProviderOptions as ae, BenchmarkUserOptions as af, Benchmark as ag, BenchmarkResult as ah, BenchFunction as ai, DefaultReporter as aj, BasicReporter as ak, DotReporter as al, JsonReporter$1 as am, VerboseReporter as an, TapReporter as ao, JUnitReporter as ap, TapFlatReporter as aq, HangingProcessReporter as ar, BaseReporter as as, ReportersMap as at, BuiltinReporters as au, BenchmarkReportsMap as av, BenchmarkBuiltinReporters as aw, CoverageProviderModule as b, ResolvedCoverageOptions as c, CoverageV8Options as d, Vitest as e, WorkspaceProject as f, TestSequencerConstructor as g, PendingSuiteMock as h, WorkerGlobalState as i, MockMap as j, RuntimeRPC as k, BenchmarkAPI as l, MockFactoryWithHelper as m, RuntimeConfig as n, UserConsoleLog as o, ModuleGraphData as p, Reporter as q, RawErrsMap as r, startVitest as s, TscErrorInfo as t, CollectLineNumbers as u, CollectLines as v, RootAndTarget as w, Context as x, BuiltinEnvironment as y, VitestEnvironment as z };
@@ -0,0 +1,16 @@
1
+ export { as as BaseReporter, ak as BasicReporter, aw as BenchmarkBuiltinReporters, av as BenchmarkReportsMap, au as BuiltinReporters, aj as DefaultReporter, al as DotReporter, ar as HangingProcessReporter, ap as JUnitReporter, am as JsonReporter, q as Reporter, at as ReportersMap, aq as TapFlatReporter, ao as TapReporter, an as VerboseReporter } from './reporters-2ff87305.js';
2
+ import 'vite';
3
+ import '@vitest/runner';
4
+ import 'vite-node';
5
+ import '@vitest/snapshot';
6
+ import '@vitest/expect';
7
+ import '@vitest/runner/utils';
8
+ import '@vitest/utils';
9
+ import 'tinybench';
10
+ import 'vite-node/client';
11
+ import '@vitest/snapshot/manager';
12
+ import 'vite-node/server';
13
+ import 'node:worker_threads';
14
+ import 'rollup';
15
+ import 'node:fs';
16
+ import 'chai';
@@ -0,0 +1,16 @@
1
+ export { f as BasicReporter, B as BenchmarkReportsMap, D as DefaultReporter, g as DotReporter, H as HangingProcessReporter, h as JUnitReporter, J as JsonReporter, R as ReportersMap, i as TapFlatReporter, T as TapReporter, V as VerboseReporter } from './vendor-reporters.f6975b8d.js';
2
+ import 'node:perf_hooks';
3
+ import 'picocolors';
4
+ import './vendor-index.29282562.js';
5
+ import 'pathe';
6
+ import 'std-env';
7
+ import '@vitest/runner/utils';
8
+ import '@vitest/utils';
9
+ import './vendor-global.97e4527c.js';
10
+ import './vendor-base.9c08bbd0.js';
11
+ import './vendor-tasks.f9d75aed.js';
12
+ import './vendor-_commonjsHelpers.7d1333e8.js';
13
+ import 'node:fs';
14
+ import '@vitest/utils/source-map';
15
+ import 'node:os';
16
+ import 'node:module';
package/dist/runners.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { VitestRunner, VitestRunnerImportSource, Suite, Test, CancelReason, TestContext } from '@vitest/runner';
2
- import { R as ResolvedConfig } from './types-3c7dbfa5.js';
3
- import '@vitest/snapshot';
4
- import '@vitest/expect';
2
+ import { R as ResolvedConfig } from './reporters-2ff87305.js';
5
3
  import 'vite';
6
4
  import 'vite-node';
5
+ import '@vitest/snapshot';
6
+ import '@vitest/expect';
7
7
  import '@vitest/runner/utils';
8
8
  import '@vitest/utils';
9
9
  import 'tinybench';
package/dist/runners.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
2
- import { g as getSnapshotClient, c as createExpect, v as vi, a as getBenchOptions, b as getBenchFn } from './vendor-vi.271667ef.js';
3
- import './vendor-index.087d1af7.js';
2
+ import { g as getSnapshotClient, c as createExpect, v as vi, a as getBenchOptions, b as getBenchFn } from './vendor-vi.597d9e06.js';
3
+ import './vendor-index.29282562.js';
4
4
  import { a as rpc } from './vendor-rpc.cbd8e972.js';
5
- import { g as getFullName } from './vendor-source-map.e6c1997b.js';
5
+ import { g as getFullName } from './vendor-tasks.f9d75aed.js';
6
6
  import { g as getWorkerState } from './vendor-global.97e4527c.js';
7
7
  import { getNames } from '@vitest/runner/utils';
8
8
  import { performance } from 'node:perf_hooks';
@@ -12,6 +12,7 @@ import 'chai';
12
12
  import './vendor-_commonjsHelpers.7d1333e8.js';
13
13
  import '@vitest/snapshot';
14
14
  import '@vitest/utils/error';
15
+ import '@vitest/utils/source-map';
15
16
  import 'util';
16
17
  import './vendor-date.6e993429.js';
17
18
  import '@vitest/spy';
@@ -1,7 +1,8 @@
1
1
  import { pathToFileURL } from 'node:url';
2
2
  import { resolve, normalize } from 'pathe';
3
- import { importModule, resolveModule } from 'local-pkg';
3
+ import { r as resolvePath } from './vendor-index.0b5b3600.js';
4
4
  import { Console } from 'node:console';
5
+ import { importModule } from 'local-pkg';
5
6
 
6
7
  const denyList = /* @__PURE__ */ new Set([
7
8
  "GLOBAL",
@@ -264,6 +265,15 @@ const LIVING_KEYS = [
264
265
  "Headers",
265
266
  "AbortController",
266
267
  "AbortSignal",
268
+ "Uint8Array",
269
+ "Uint16Array",
270
+ "Uint32Array",
271
+ "Uint8ClampedArray",
272
+ "Int8Array",
273
+ "Int16Array",
274
+ "Int32Array",
275
+ "Float32Array",
276
+ "Float64Array",
267
277
  "ArrayBuffer",
268
278
  "DOMRectReadOnly",
269
279
  "DOMRect",
@@ -463,7 +473,6 @@ var jsdom = {
463
473
  );
464
474
  const clearWindowErrors = catchWindowErrors(dom.window);
465
475
  dom.window.Buffer = Buffer;
466
- dom.window.Uint8Array = Uint8Array;
467
476
  if (typeof structuredClone !== "undefined" && !dom.window.structuredClone)
468
477
  dom.window.structuredClone = structuredClone;
469
478
  return {
@@ -527,25 +536,30 @@ var jsdom = {
527
536
  var happy = {
528
537
  name: "happy-dom",
529
538
  transformMode: "web",
530
- async setupVM() {
539
+ async setupVM({ happyDOM = {} }) {
531
540
  const { Window } = await importModule("happy-dom");
532
- const win = new Window();
541
+ const win = new Window({
542
+ ...happyDOM,
543
+ url: happyDOM.url || "http://localhost:3000"
544
+ });
533
545
  win.Buffer = Buffer;
534
- win.Uint8Array = Uint8Array;
535
546
  if (typeof structuredClone !== "undefined" && !win.structuredClone)
536
547
  win.structuredClone = structuredClone;
537
548
  return {
538
549
  getVmContext() {
539
550
  return win;
540
551
  },
541
- teardown() {
542
- win.happyDOM.cancelAsync();
552
+ async teardown() {
553
+ await win.happyDOM.cancelAsync();
543
554
  }
544
555
  };
545
556
  },
546
- async setup(global) {
557
+ async setup(global, { happyDOM = {} }) {
547
558
  const { Window, GlobalWindow } = await importModule("happy-dom");
548
- const win = new (GlobalWindow || Window)();
559
+ const win = new (GlobalWindow || Window)({
560
+ ...happyDOM,
561
+ url: happyDOM.url || "http://localhost:3000"
562
+ });
549
563
  const { keys, originals } = populateGlobal(global, win, { bindFunctions: true });
550
564
  return {
551
565
  teardown(global2) {
@@ -583,6 +597,10 @@ var edge = {
583
597
  extend: (context) => {
584
598
  context.global = context;
585
599
  context.Buffer = Buffer;
600
+ KEYS.forEach((key) => {
601
+ if (key in global)
602
+ context[key] = global[key];
603
+ });
586
604
  return context;
587
605
  }
588
606
  });
@@ -620,7 +638,7 @@ function getEnvPackageName(env) {
620
638
  async function loadEnvironment(name, root) {
621
639
  if (isBuiltinEnvironment(name))
622
640
  return environments[name];
623
- const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : resolveModule(`vitest-environment-${name}`, { paths: [root] }) ?? resolve(root, name);
641
+ const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name);
624
642
  const pkg = await import(pathToFileURL(normalize(packageId)).href);
625
643
  if (!pkg || !pkg.default || typeof pkg.default !== "object") {
626
644
  throw new TypeError(