vitest 0.34.0 → 0.34.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 (35) hide show
  1. package/LICENSE.md +28 -0
  2. package/dist/browser.d.ts +1 -1
  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.cc5282f7.js} +25 -15
  6. package/dist/{chunk-install-pkg.dd70081b.js → chunk-install-pkg.7e19b3a0.js} +6 -3
  7. package/dist/{chunk-integrations-globals.877c84db.js → chunk-integrations-globals.522ae1ae.js} +4 -3
  8. package/dist/cli.js +6 -3
  9. package/dist/config.d.ts +1 -1
  10. package/dist/coverage.d.ts +1 -1
  11. package/dist/entry-vm.js +4 -3
  12. package/dist/entry.js +4 -3
  13. package/dist/environments.d.ts +1 -1
  14. package/dist/environments.js +11 -2
  15. package/dist/execute.d.ts +139 -0
  16. package/dist/execute.js +1 -1
  17. package/dist/index.d.ts +10 -9
  18. package/dist/index.js +5 -4
  19. package/dist/loader.js +9 -528
  20. package/dist/node.d.ts +2 -2
  21. package/dist/node.js +6 -3
  22. package/dist/runners.d.ts +1 -1
  23. package/dist/runners.js +3 -2
  24. package/dist/{types-3c7dbfa5.d.ts → types-63abf2e0.d.ts} +63 -2
  25. package/dist/{vendor-environments.443ecd82.js → vendor-environments.37f266a9.js} +13 -6
  26. package/dist/{vendor-execute.9ab1c1a7.js → vendor-execute.4fc8203a.js} +409 -206
  27. package/dist/vendor-index.0b5b3600.js +2062 -0
  28. package/dist/{vendor-index.eff408fd.js → vendor-index.b5efbd68.js} +1 -1
  29. package/dist/{vendor-node.00226ab1.js → vendor-node.7b1bd3c5.js} +196 -122
  30. package/dist/vendor-tasks.f9d75aed.js +14 -0
  31. package/dist/{vendor-vi.271667ef.js → vendor-vi.f8055ff2.js} +2 -1
  32. package/dist/vm.js +14 -6
  33. package/dist/worker.js +12 -6
  34. package/package.json +7 -7
  35. package/dist/vendor-source-map.e6c1997b.js +0 -747
@@ -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;
@@ -1446,6 +1453,27 @@ interface JSDOMOptions {
1446
1453
  resources?: 'usable' | any;
1447
1454
  }
1448
1455
 
1456
+ /**
1457
+ * Happy DOM options.
1458
+ */
1459
+ interface HappyDOMOptions {
1460
+ width?: number;
1461
+ height?: number;
1462
+ url?: string;
1463
+ settings?: {
1464
+ disableJavaScriptEvaluation?: boolean;
1465
+ disableJavaScriptFileLoading?: boolean;
1466
+ disableCSSFileLoading?: boolean;
1467
+ disableIframePageLoading?: boolean;
1468
+ disableComputedStyleRendering?: boolean;
1469
+ enableFileSystemHttpRequests?: boolean;
1470
+ device?: {
1471
+ prefersColorScheme?: string;
1472
+ mediaType?: string;
1473
+ };
1474
+ };
1475
+ }
1476
+
1449
1477
  interface BenchmarkUserOptions {
1450
1478
  /**
1451
1479
  * Include globs for benchmark test files
@@ -1506,6 +1534,7 @@ interface EnvironmentOptions {
1506
1534
  * jsdom options.
1507
1535
  */
1508
1536
  jsdom?: JSDOMOptions;
1537
+ happyDOM?: HappyDOMOptions;
1509
1538
  [x: string]: unknown;
1510
1539
  }
1511
1540
  type VitestRunMode = 'test' | 'benchmark' | 'typecheck';
@@ -1576,6 +1605,38 @@ interface DepsOptions {
1576
1605
  web?: DepsOptimizationOptions;
1577
1606
  ssr?: DepsOptimizationOptions;
1578
1607
  };
1608
+ web?: {
1609
+ /**
1610
+ * Should Vitest process assets (.png, .svg, .jpg, etc) files and resolve them like Vite does in the browser.
1611
+ *
1612
+ * These module will have a default export equal to the path to the asset, if no query is specified.
1613
+ *
1614
+ * **At the moment, this option only works with `experimentalVmThreads` pool.**
1615
+ *
1616
+ * @default true
1617
+ */
1618
+ transformAssets?: boolean;
1619
+ /**
1620
+ * Should Vitest process CSS (.css, .scss, .sass, etc) files and resolve them like Vite does in the browser.
1621
+ *
1622
+ * If CSS files are disabled with `css` options, this option will just silence UNKNOWN_EXTENSION errors.
1623
+ *
1624
+ * **At the moment, this option only works with `experimentalVmThreads` pool.**
1625
+ *
1626
+ * @default true
1627
+ */
1628
+ transformCss?: boolean;
1629
+ /**
1630
+ * Regexp pattern to match external files that should be transformed.
1631
+ *
1632
+ * By default, files inside `node_modules` are externalized and not transformed.
1633
+ *
1634
+ * **At the moment, this option only works with `experimentalVmThreads` pool.**
1635
+ *
1636
+ * @default []
1637
+ */
1638
+ transformGlobPattern?: RegExp | RegExp[];
1639
+ };
1579
1640
  /**
1580
1641
  * Externalize means that Vite will bypass the package to native Node.
1581
1642
  *
@@ -2223,4 +2284,4 @@ type Context = RootAndTarget & {
2223
2284
  lastActivePath?: string;
2224
2285
  };
2225
2286
 
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 };
2287
+ 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, 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 };
@@ -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",
@@ -527,9 +528,12 @@ var jsdom = {
527
528
  var happy = {
528
529
  name: "happy-dom",
529
530
  transformMode: "web",
530
- async setupVM() {
531
+ async setupVM({ happyDOM = {} }) {
531
532
  const { Window } = await importModule("happy-dom");
532
- const win = new Window();
533
+ const win = new Window({
534
+ ...happyDOM,
535
+ url: happyDOM.url || "http://localhost:3000"
536
+ });
533
537
  win.Buffer = Buffer;
534
538
  win.Uint8Array = Uint8Array;
535
539
  if (typeof structuredClone !== "undefined" && !win.structuredClone)
@@ -543,9 +547,12 @@ var happy = {
543
547
  }
544
548
  };
545
549
  },
546
- async setup(global) {
550
+ async setup(global, { happyDOM = {} }) {
547
551
  const { Window, GlobalWindow } = await importModule("happy-dom");
548
- const win = new (GlobalWindow || Window)();
552
+ const win = new (GlobalWindow || Window)({
553
+ ...happyDOM,
554
+ url: happyDOM.url || "http://localhost:3000"
555
+ });
549
556
  const { keys, originals } = populateGlobal(global, win, { bindFunctions: true });
550
557
  return {
551
558
  teardown(global2) {
@@ -620,7 +627,7 @@ function getEnvPackageName(env) {
620
627
  async function loadEnvironment(name, root) {
621
628
  if (isBuiltinEnvironment(name))
622
629
  return environments[name];
623
- const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : resolveModule(`vitest-environment-${name}`, { paths: [root] }) ?? resolve(root, name);
630
+ const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name);
624
631
  const pkg = await import(pathToFileURL(normalize(packageId)).href);
625
632
  if (!pkg || !pkg.default || typeof pkg.default !== "object") {
626
633
  throw new TypeError(