vitest 2.0.4 → 2.1.0-beta.1

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 (80) hide show
  1. package/dist/browser.d.ts +21 -42
  2. package/dist/browser.js +5 -5
  3. package/dist/chunks/RandomSequencer.B4M2ux5b.js +952 -0
  4. package/dist/{vendor/base.DRHPZCCj.js → chunks/base.BH-FAiX7.js} +2 -2
  5. package/dist/{vendor/base.Csk7BT3h.js → chunks/base.BYvKfYzm.js} +3 -3
  6. package/dist/{vendor/benchmark.B6pblCp2.js → chunks/benchmark.C8CRJYG4.js} +1 -1
  7. package/dist/chunks/benchmark.puBFxyfE.d.ts +22 -0
  8. package/dist/{vendor/cac.DFtWvZc2.js → chunks/cac.CaYKA7Wt.js} +19 -21
  9. package/dist/{vendor/cli-api.CTkP2Ier.js → chunks/cli-api.B8LE391_.js} +500 -4615
  10. package/dist/chunks/config.CHuotKvS.d.ts +206 -0
  11. package/dist/chunks/{runtime-console.C2L2zykk.js → console.DI3gHgtH.js} +11 -14
  12. package/dist/{vendor/constants.CsnA4eRy.js → chunks/constants.CaAN7icJ.js} +1 -3
  13. package/dist/{vendor/coverage.BhYSDdTT.js → chunks/coverage.CqfT4xaf.js} +4 -7
  14. package/dist/chunks/{browser-creator.CyaOd8pl.js → creator.GreKbaUc.js} +10 -11
  15. package/dist/chunks/env.CmHVDJnw.js +7 -0
  16. package/dist/chunks/environment.0M5R1SX_.d.ts +173 -0
  17. package/dist/{vendor/execute.jzOWtys_.js → chunks/execute.DT9BA6zp.js} +28 -20
  18. package/dist/chunks/globals.DRPLtPOv.js +31 -0
  19. package/dist/{vendor/index.D6GZqexG.js → chunks/index.CM5UI-4O.js} +2 -2
  20. package/dist/{vendor/index.DI9daj1Q.js → chunks/index.CNZXZ9PJ.js} +43 -43
  21. package/dist/{vendor/index.BJmtb_7W.js → chunks/index.CxRxs566.js} +2 -2
  22. package/dist/{vendor/index.CVqMv71L.js → chunks/index.CxWPpGJz.js} +11 -12
  23. package/dist/{vendor/index.CuuL9y4g.js → chunks/index.YuPJueCg.js} +505 -1185
  24. package/dist/{vendor/index.D4nqnQWz.js → chunks/index.lVXYBqEP.js} +1 -18
  25. package/dist/{vendor/inspector.-FCQUzqR.js → chunks/inspector.70d6emsh.js} +4 -5
  26. package/dist/chunks/{environments-node.XE5FbRPQ.js → node.Bx4JZjMG.js} +2 -2
  27. package/dist/{reporters-B7ebVMkT.d.ts → chunks/reporters.DRZ7ndzr.d.ts} +860 -1000
  28. package/dist/chunks/resolveConfig.CGobt8AB.js +8120 -0
  29. package/dist/{vendor/rpc.BGx7q_k2.js → chunks/rpc.B7Mfb-Yf.js} +3 -5
  30. package/dist/{vendor/run-once.Db8Hgq9X.js → chunks/run-once.Sxe67Wng.js} +1 -1
  31. package/dist/chunks/{runtime-runBaseTests.Dq_sJZq9.js → runBaseTests.BAhL8UH_.js} +21 -23
  32. package/dist/{vendor/setup-common.symvFZPh.js → chunks/setup-common.KBrCO5LJ.js} +2 -2
  33. package/dist/{suite-CRLAhsm0.d.ts → chunks/suite.CcK46U-P.d.ts} +1 -1
  34. package/dist/{vendor/tasks.DhVtQBtW.js → chunks/tasks.BZnCS9aT.js} +2 -3
  35. package/dist/{vendor/utils.DkxLWvS1.js → chunks/utils.C3_cBsyn.js} +3 -4
  36. package/dist/{vendor/global.7bFbnyXl.js → chunks/utils.Ck2hJTRs.js} +1 -1
  37. package/dist/{vendor/utils.BySfPUwy.js → chunks/utils.DO38lwfj.js} +8 -21
  38. package/dist/{vendor/vi.Elqer9-7.js → chunks/vi.B6QZ938s.js} +13 -18
  39. package/dist/{vendor/vm.img-AOox.js → chunks/vm.kl9T_5ai.js} +40 -68
  40. package/dist/chunks/worker.BANO5ak1.d.ts +144 -0
  41. package/dist/chunks/worker.Cx2xE71X.d.ts +8 -0
  42. package/dist/cli.js +3 -3
  43. package/dist/config.cjs +6 -8
  44. package/dist/config.d.ts +10 -8
  45. package/dist/config.js +6 -8
  46. package/dist/coverage.d.ts +10 -8
  47. package/dist/coverage.js +35 -15
  48. package/dist/environments.d.ts +3 -19
  49. package/dist/environments.js +1 -1
  50. package/dist/execute.d.ts +5 -14
  51. package/dist/execute.js +2 -2
  52. package/dist/index.d.ts +267 -34
  53. package/dist/index.js +12 -12
  54. package/dist/node.d.ts +15 -9
  55. package/dist/node.js +26 -28
  56. package/dist/reporters.d.ts +10 -8
  57. package/dist/reporters.js +16 -18
  58. package/dist/runners.d.ts +15 -20
  59. package/dist/runners.js +12 -13
  60. package/dist/snapshot.js +3 -3
  61. package/dist/suite.d.ts +2 -16
  62. package/dist/suite.js +4 -4
  63. package/dist/worker.js +7 -8
  64. package/dist/workers/forks.js +5 -5
  65. package/dist/workers/runVmTests.js +18 -19
  66. package/dist/workers/threads.js +5 -5
  67. package/dist/workers/vmForks.js +8 -8
  68. package/dist/workers/vmThreads.js +8 -8
  69. package/dist/workers.d.ts +13 -8
  70. package/dist/workers.js +13 -13
  71. package/package.json +16 -17
  72. package/dist/chunks/integrations-globals.nDMtdOcn.js +0 -31
  73. package/dist/vendor/env.2ltrQNq0.js +0 -8
  74. package/dist/vendor/index.BMmMjLIQ.js +0 -3975
  75. /package/dist/{vendor → chunks}/_commonjsHelpers.BFTU3MAI.js +0 -0
  76. /package/dist/{vendor → chunks}/date.W2xKR2qe.js +0 -0
  77. /package/dist/chunks/{node-git.ZtkbKc8u.js → git.ZtkbKc8u.js} +0 -0
  78. /package/dist/{vendor → chunks}/index.BpSiYbpB.js +0 -0
  79. /package/dist/chunks/{install-pkg.DNUmWFkO.js → index.DNUmWFkO.js} +0 -0
  80. /package/dist/{vendor → chunks}/spy.Cf_4R5Oe.js +0 -0
@@ -0,0 +1,206 @@
1
+ import { PrettyFormatOptions } from '@vitest/pretty-format';
2
+ import { SequenceHooks, SequenceSetupFiles } from '@vitest/runner';
3
+ import { SnapshotUpdateState } from '@vitest/snapshot';
4
+ import { SnapshotEnvironment } from '@vitest/snapshot/environment';
5
+
6
+ /**
7
+ * Names of clock methods that may be faked by install.
8
+ */
9
+ type FakeMethod =
10
+ | "setTimeout"
11
+ | "clearTimeout"
12
+ | "setImmediate"
13
+ | "clearImmediate"
14
+ | "setInterval"
15
+ | "clearInterval"
16
+ | "Date"
17
+ | "nextTick"
18
+ | "hrtime"
19
+ | "requestAnimationFrame"
20
+ | "cancelAnimationFrame"
21
+ | "requestIdleCallback"
22
+ | "cancelIdleCallback"
23
+ | "performance"
24
+ | "queueMicrotask";
25
+
26
+ interface FakeTimerInstallOpts {
27
+ /**
28
+ * Installs fake timers with the specified unix epoch (default: 0)
29
+ */
30
+ now?: number | Date | undefined;
31
+
32
+ /**
33
+ * An array with names of global methods and APIs to fake.
34
+ * For instance, `vi.useFakeTimer({ toFake: ['setTimeout', 'performance'] })` will fake only `setTimeout()` and `performance.now()`
35
+ * @default ['setTimeout', 'clearTimeout', 'setImmediate', 'clearImmediate', 'setInterval', 'clearInterval', 'Date']
36
+ */
37
+ toFake?: FakeMethod[] | undefined;
38
+
39
+ /**
40
+ * The maximum number of timers that will be run when calling runAll()
41
+ * @default 10000
42
+ */
43
+ loopLimit?: number | undefined;
44
+
45
+ /**
46
+ * Tells @sinonjs/fake-timers to increment mocked time automatically based on the real system time shift (e.g. the mocked time will be incremented by
47
+ * 20ms for every 20ms change in the real system time) (default: false)
48
+ */
49
+ shouldAdvanceTime?: boolean | undefined;
50
+
51
+ /**
52
+ * Relevant only when using with shouldAdvanceTime: true. increment mocked time by advanceTimeDelta ms every advanceTimeDelta ms change
53
+ * in the real system time (default: 20)
54
+ */
55
+ advanceTimeDelta?: number | undefined;
56
+
57
+ /**
58
+ * Tells FakeTimers to clear 'native' (i.e. not fake) timers by delegating to their respective handlers.
59
+ * @default true
60
+ */
61
+ shouldClearNativeTimers?: boolean | undefined;
62
+ }
63
+
64
+ /**
65
+ * Config that tests have access to.
66
+ */
67
+ interface SerializedConfig {
68
+ name: string | undefined;
69
+ globals: boolean;
70
+ base: string | undefined;
71
+ snapshotEnvironment?: string;
72
+ disableConsoleIntercept: boolean | undefined;
73
+ runner: string | undefined;
74
+ isolate: boolean;
75
+ mode: 'test' | 'benchmark';
76
+ bail: number | undefined;
77
+ environmentOptions?: Record<string, any>;
78
+ root: string;
79
+ setupFiles: string[];
80
+ passWithNoTests: boolean;
81
+ testNamePattern: RegExp | undefined;
82
+ allowOnly: boolean;
83
+ testTimeout: number;
84
+ hookTimeout: number;
85
+ clearMocks: boolean;
86
+ mockReset: boolean;
87
+ restoreMocks: boolean;
88
+ unstubGlobals: boolean;
89
+ unstubEnvs: boolean;
90
+ fakeTimers: FakeTimerInstallOpts;
91
+ maxConcurrency: number;
92
+ defines: Record<string, any>;
93
+ expect: {
94
+ requireAssertions?: boolean;
95
+ poll?: {
96
+ timeout?: number;
97
+ interval?: number;
98
+ };
99
+ };
100
+ printConsoleTrace: boolean | undefined;
101
+ sequence: {
102
+ shuffle?: boolean;
103
+ concurrent?: boolean;
104
+ seed: number;
105
+ hooks: SequenceHooks;
106
+ setupFiles: SequenceSetupFiles;
107
+ };
108
+ poolOptions: {
109
+ forks: {
110
+ singleFork: boolean;
111
+ isolate: boolean;
112
+ };
113
+ threads: {
114
+ singleThread: boolean;
115
+ isolate: boolean;
116
+ };
117
+ vmThreads: {
118
+ singleThread: boolean;
119
+ };
120
+ vmForks: {
121
+ singleFork: boolean;
122
+ };
123
+ };
124
+ deps: {
125
+ web: {
126
+ transformAssets?: boolean;
127
+ transformCss?: boolean;
128
+ transformGlobPattern?: RegExp | RegExp[];
129
+ };
130
+ optimizer: {
131
+ web: {
132
+ enabled: boolean;
133
+ };
134
+ ssr: {
135
+ enabled: boolean;
136
+ };
137
+ };
138
+ interopDefault: boolean | undefined;
139
+ moduleDirectories: string[] | undefined;
140
+ };
141
+ snapshotOptions: {
142
+ updateSnapshot: SnapshotUpdateState;
143
+ expand: boolean | undefined;
144
+ snapshotFormat: PrettyFormatOptions | undefined;
145
+ /**
146
+ * only exists for tests, not available in the main process
147
+ */
148
+ snapshotEnvironment: SnapshotEnvironment;
149
+ };
150
+ pool: string;
151
+ snapshotSerializers: string[];
152
+ chaiConfig: {
153
+ includeStack?: boolean;
154
+ showDiff?: boolean;
155
+ truncateThreshold?: number;
156
+ } | undefined;
157
+ diff: string | undefined;
158
+ retry: number;
159
+ includeTaskLocation: boolean | undefined;
160
+ inspect: boolean | string | undefined;
161
+ inspectBrk: boolean | string | undefined;
162
+ inspector: {
163
+ enabled?: boolean;
164
+ port?: number;
165
+ host?: string;
166
+ waitForDebugger?: boolean;
167
+ };
168
+ watch: boolean;
169
+ env: Record<string, any>;
170
+ browser: {
171
+ name: string;
172
+ headless: boolean;
173
+ isolate: boolean;
174
+ fileParallelism: boolean;
175
+ ui: boolean;
176
+ viewport: {
177
+ width: number;
178
+ height: number;
179
+ };
180
+ locators: {
181
+ testIdAttribute: string;
182
+ };
183
+ screenshotFailures: boolean;
184
+ };
185
+ standalone: boolean;
186
+ logHeapUsage: boolean | undefined;
187
+ coverage: SerializedCoverageConfig;
188
+ }
189
+ interface SerializedCoverageConfig {
190
+ provider: 'istanbul' | 'v8' | 'custom' | undefined;
191
+ reportsDirectory: string;
192
+ htmlReporter: {
193
+ subdir: string | undefined;
194
+ } | undefined;
195
+ enabled: boolean;
196
+ customProviderModule: string | undefined;
197
+ }
198
+ type RuntimeConfig = Pick<SerializedConfig, 'allowOnly' | 'testTimeout' | 'hookTimeout' | 'clearMocks' | 'mockReset' | 'restoreMocks' | 'fakeTimers' | 'maxConcurrency' | 'expect' | 'printConsoleTrace'> & {
199
+ sequence?: {
200
+ concurrent?: boolean;
201
+ hooks?: SequenceHooks;
202
+ };
203
+ };
204
+ type RuntimeOptions = Partial<RuntimeConfig>;
205
+
206
+ export type { FakeTimerInstallOpts as F, RuntimeOptions as R, SerializedConfig as S, SerializedCoverageConfig as a, RuntimeConfig as b };
@@ -3,17 +3,16 @@ import { Console } from 'node:console';
3
3
  import { relative } from 'node:path';
4
4
  import { getSafeTimers } from '@vitest/utils';
5
5
  import c from 'tinyrainbow';
6
- import { R as RealDate } from '../vendor/date.W2xKR2qe.js';
6
+ import { R as RealDate } from './date.W2xKR2qe.js';
7
7
  import 'pathe';
8
8
  import '@vitest/runner/utils';
9
- import { g as getWorkerState } from '../vendor/global.7bFbnyXl.js';
10
- import '../vendor/env.2ltrQNq0.js';
9
+ import { g as getWorkerState } from './utils.Ck2hJTRs.js';
10
+ import './env.CmHVDJnw.js';
11
11
  import 'std-env';
12
12
 
13
13
  const UNKNOWN_TEST_ID = "__vitest__unknown_test__";
14
14
  function getTaskIdByStack(root) {
15
- var _a, _b;
16
- const stack = (_a = new Error("STACK_TRACE_ERROR").stack) == null ? void 0 : _a.split("\n");
15
+ const stack = new Error("STACK_TRACE_ERROR").stack?.split("\n");
17
16
  if (!stack) {
18
17
  return UNKNOWN_TEST_ID;
19
18
  }
@@ -22,7 +21,7 @@ function getTaskIdByStack(root) {
22
21
  if (!line) {
23
22
  return UNKNOWN_TEST_ID;
24
23
  }
25
- const filepath = (_b = line.match(/at\s(.*)\s?/)) == null ? void 0 : _b[1];
24
+ const filepath = line.match(/at\s(.*)\s?/)?.[1];
26
25
  if (filepath) {
27
26
  return relative(root, filepath);
28
27
  }
@@ -90,9 +89,8 @@ function createCustomConsole(defaultState) {
90
89
  }
91
90
  const stdout = new Writable({
92
91
  write(data, encoding, callback) {
93
- var _a, _b, _c, _d;
94
92
  const s = state();
95
- const id = ((_a = s == null ? void 0 : s.current) == null ? void 0 : _a.id) || ((_c = (_b = s == null ? void 0 : s.current) == null ? void 0 : _b.suite) == null ? void 0 : _c.id) || ((_d = s.current) == null ? void 0 : _d.file.id) || getTaskIdByStack(s.config.root);
93
+ const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
96
94
  let timer = timers.get(id);
97
95
  if (timer) {
98
96
  timer.stdoutTime = timer.stdoutTime || RealDate.now();
@@ -113,7 +111,7 @@ function createCustomConsole(defaultState) {
113
111
  const limit = Error.stackTraceLimit;
114
112
  Error.stackTraceLimit = limit + 6;
115
113
  const stack = new Error("STACK_TRACE").stack;
116
- const trace = stack == null ? void 0 : stack.split("\n").slice(7).join("\n");
114
+ const trace = stack?.split("\n").slice(7).join("\n");
117
115
  Error.stackTraceLimit = limit;
118
116
  buffer.push([data, trace]);
119
117
  } else {
@@ -125,9 +123,8 @@ function createCustomConsole(defaultState) {
125
123
  });
126
124
  const stderr = new Writable({
127
125
  write(data, encoding, callback) {
128
- var _a, _b, _c, _d, _e;
129
126
  const s = state();
130
- const id = ((_a = s == null ? void 0 : s.current) == null ? void 0 : _a.id) || ((_c = (_b = s == null ? void 0 : s.current) == null ? void 0 : _b.suite) == null ? void 0 : _c.id) || ((_d = s.current) == null ? void 0 : _d.file.id) || getTaskIdByStack(s.config.root);
127
+ const id = s?.current?.id || s?.current?.suite?.id || s.current?.file.id || getTaskIdByStack(s.config.root);
131
128
  let timer = timers.get(id);
132
129
  if (timer) {
133
130
  timer.stderrTime = timer.stderrTime || RealDate.now();
@@ -147,15 +144,15 @@ function createCustomConsole(defaultState) {
147
144
  if (state().config.printConsoleTrace) {
148
145
  const limit = Error.stackTraceLimit;
149
146
  Error.stackTraceLimit = limit + 6;
150
- const stack = (_e = new Error("STACK_TRACE").stack) == null ? void 0 : _e.split("\n");
147
+ const stack = new Error("STACK_TRACE").stack?.split("\n");
151
148
  Error.stackTraceLimit = limit;
152
- const isTrace = stack == null ? void 0 : stack.some(
149
+ const isTrace = stack?.some(
153
150
  (line) => line.includes("at Console.trace")
154
151
  );
155
152
  if (isTrace) {
156
153
  buffer.push([data, void 0]);
157
154
  } else {
158
- const trace = stack == null ? void 0 : stack.slice(7).join("\n");
155
+ const trace = stack?.slice(7).join("\n");
159
156
  Error.stackTraceLimit = limit;
160
157
  buffer.push([data, trace]);
161
158
  }
@@ -6,9 +6,7 @@ const extraInlineDeps = [
6
6
  /^(?!.*node_modules).*\.mjs$/,
7
7
  /^(?!.*node_modules).*\.cjs\.js$/,
8
8
  // Vite client
9
- /vite\w*\/dist\/client\/env.mjs/,
10
- // Nuxt
11
- "@nuxt/test-utils"
9
+ /vite\w*\/dist\/client\/env.mjs/
12
10
  ];
13
11
  const CONFIG_NAMES = ["vitest.config", "vite.config"];
14
12
  const WORKSPACES_NAMES = ["vitest.workspace", "vitest.projects"];
@@ -3,7 +3,7 @@ const CoverageProviderMap = {
3
3
  istanbul: "@vitest/coverage-istanbul"
4
4
  };
5
5
  async function resolveCoverageProviderModule(options, loader) {
6
- if (!(options == null ? void 0 : options.enabled) || !options.provider) {
6
+ if (!options?.enabled || !options.provider) {
7
7
  return null;
8
8
  }
9
9
  const provider = options.provider;
@@ -42,26 +42,23 @@ async function getCoverageProvider(options, loader) {
42
42
  return null;
43
43
  }
44
44
  async function startCoverageInsideWorker(options, loader) {
45
- var _a;
46
45
  const coverageModule = await resolveCoverageProviderModule(options, loader);
47
46
  if (coverageModule) {
48
- return (_a = coverageModule.startCoverage) == null ? void 0 : _a.call(coverageModule);
47
+ return coverageModule.startCoverage?.();
49
48
  }
50
49
  return null;
51
50
  }
52
51
  async function takeCoverageInsideWorker(options, loader) {
53
- var _a;
54
52
  const coverageModule = await resolveCoverageProviderModule(options, loader);
55
53
  if (coverageModule) {
56
- return (_a = coverageModule.takeCoverage) == null ? void 0 : _a.call(coverageModule);
54
+ return coverageModule.takeCoverage?.();
57
55
  }
58
56
  return null;
59
57
  }
60
58
  async function stopCoverageInsideWorker(options, loader) {
61
- var _a;
62
59
  const coverageModule = await resolveCoverageProviderModule(options, loader);
63
60
  if (coverageModule) {
64
- return (_a = coverageModule.stopCoverage) == null ? void 0 : _a.call(coverageModule);
61
+ return coverageModule.stopCoverage?.();
65
62
  }
66
63
  return null;
67
64
  }
@@ -1,14 +1,14 @@
1
1
  import { resolve, dirname, relative } from 'node:path';
2
2
  import { existsSync, writeFileSync, readFileSync } from 'node:fs';
3
3
  import { mkdir, writeFile } from 'node:fs/promises';
4
- import { p as prompt, f as findUp } from '../vendor/index.D6GZqexG.js';
4
+ import { p as prompt, f as findUp } from './index.CM5UI-4O.js';
5
5
  import c from 'tinyrainbow';
6
- import { detectPackageManager, installPackage } from './install-pkg.DNUmWFkO.js';
6
+ import { detectPackageManager, installPackage } from './index.DNUmWFkO.js';
7
7
  import { execa } from 'execa';
8
- import { c as configFiles } from '../vendor/constants.CsnA4eRy.js';
8
+ import { c as configFiles } from './constants.CaAN7icJ.js';
9
9
  import 'node:url';
10
10
  import 'node:process';
11
- import '../vendor/_commonjsHelpers.BFTU3MAI.js';
11
+ import './_commonjsHelpers.BFTU3MAI.js';
12
12
  import 'readline';
13
13
  import 'events';
14
14
  import 'fs';
@@ -155,7 +155,6 @@ const vanillaExample = {
155
155
  js: `
156
156
  export default function HelloWorld({ name }) {
157
157
  const parent = document.createElement('div')
158
- document.body.appendChild(parent)
159
158
 
160
159
  const h1 = document.createElement('h1')
161
160
  h1.textContent = 'Hello ' + name + '!'
@@ -167,7 +166,6 @@ export default function HelloWorld({ name }) {
167
166
  ts: `
168
167
  export default function HelloWorld({ name }: { name: string }): HTMLDivElement {
169
168
  const parent = document.createElement('div')
170
- document.body.appendChild(parent)
171
169
 
172
170
  const h1 = document.createElement('h1')
173
171
  h1.textContent = 'Hello ' + name + '!'
@@ -179,10 +177,11 @@ export default function HelloWorld({ name }: { name: string }): HTMLDivElement {
179
177
  test: `
180
178
  import { expect, test } from 'vitest'
181
179
  import { getByText } from '@testing-library/dom'
182
- import HelloWorld from './HelloWorld'
180
+ import HelloWorld from './HelloWorld.js'
183
181
 
184
182
  test('renders name', () => {
185
183
  const parent = HelloWorld({ name: 'Vitest' })
184
+ document.body.appendChild(parent)
186
185
 
187
186
  const element = getByText(parent, 'Hello Vitest!')
188
187
  expect(element).toBeInTheDocument()
@@ -552,7 +551,7 @@ async function create() {
552
551
  type: "select",
553
552
  name: "lang",
554
553
  message: "Choose a language for your tests",
555
- choices: sort(getLanguageOptions(), defaults == null ? void 0 : defaults.lang)
554
+ choices: sort(getLanguageOptions(), defaults?.lang)
556
555
  });
557
556
  if (!lang) {
558
557
  return fail();
@@ -561,7 +560,7 @@ async function create() {
561
560
  type: "select",
562
561
  name: "provider",
563
562
  message: "Choose a browser provider. Vitest will use its API to control the testing environment",
564
- choices: sort(getProviderOptions(), defaults == null ? void 0 : defaults.provider)
563
+ choices: sort(getProviderOptions(), defaults?.provider)
565
564
  });
566
565
  if (!provider) {
567
566
  return fail();
@@ -582,7 +581,7 @@ async function create() {
582
581
  type: "select",
583
582
  name: "framework",
584
583
  message: "Choose your framework",
585
- choices: sort(getFramework(), defaults == null ? void 0 : defaults.framework)
584
+ choices: sort(getFramework(), defaults?.framework)
586
585
  });
587
586
  if (!framework) {
588
587
  return fail();
@@ -660,7 +659,7 @@ async function create() {
660
659
  });
661
660
  }
662
661
  if (lang === "ts") {
663
- await updateTsConfig(providerPkg == null ? void 0 : providerPkg.types);
662
+ await updateTsConfig(providerPkg?.types);
664
663
  }
665
664
  log();
666
665
  const exampleTestFile = await generateExampleFiles(framework, lang);
@@ -0,0 +1,7 @@
1
+ import 'std-env';
2
+
3
+ const isNode = typeof process < "u" && typeof process.stdout < "u" && !process.versions?.deno && !globalThis.window;
4
+ const isDeno = typeof process < "u" && typeof process.stdout < "u" && process.versions?.deno !== void 0;
5
+ const isWindows = (isNode || isDeno) && process.platform === "win32";
6
+
7
+ export { isNode as a, isDeno as b, isWindows as i };
@@ -0,0 +1,173 @@
1
+ type Awaitable<T> = T | PromiseLike<T>;
2
+ type Nullable<T> = T | null | undefined;
3
+ type Arrayable<T> = T | Array<T>;
4
+ type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
5
+ type MutableArray<T extends readonly any[]> = {
6
+ -readonly [k in keyof T]: T[k];
7
+ };
8
+ interface Constructable {
9
+ new (...args: any[]): any;
10
+ }
11
+ type TransformMode = 'web' | 'ssr';
12
+ /** @deprecated not used */
13
+ interface ModuleCache {
14
+ promise?: Promise<any>;
15
+ exports?: any;
16
+ code?: string;
17
+ }
18
+ interface AfterSuiteRunMeta {
19
+ coverage?: unknown;
20
+ transformMode: TransformMode;
21
+ projectName?: string;
22
+ }
23
+ interface UserConsoleLog {
24
+ content: string;
25
+ origin?: string;
26
+ browser?: boolean;
27
+ type: 'stdout' | 'stderr';
28
+ taskId?: string;
29
+ time: number;
30
+ size: number;
31
+ }
32
+ interface ModuleGraphData {
33
+ graph: Record<string, string[]>;
34
+ externalized: string[];
35
+ inlined: string[];
36
+ }
37
+ type OnServerRestartHandler = (reason?: string) => Promise<void> | void;
38
+ interface ProvidedContext {
39
+ }
40
+
41
+ interface JSDOMOptions {
42
+ /**
43
+ * The html content for the test.
44
+ *
45
+ * @default '<!DOCTYPE html>'
46
+ */
47
+ html?: string | ArrayBufferLike;
48
+ /**
49
+ * referrer just affects the value read from document.referrer.
50
+ * It defaults to no referrer (which reflects as the empty string).
51
+ */
52
+ referrer?: string;
53
+ /**
54
+ * userAgent affects the value read from navigator.userAgent, as well as the User-Agent header sent while fetching subresources.
55
+ *
56
+ * @default `Mozilla/5.0 (${process.platform}) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/${jsdomVersion}`
57
+ */
58
+ userAgent?: string;
59
+ /**
60
+ * url sets the value returned by window.location, document.URL, and document.documentURI,
61
+ * and affects things like resolution of relative URLs within the document
62
+ * and the same-origin restrictions and referrer used while fetching subresources.
63
+ *
64
+ * @default 'http://localhost:3000'.
65
+ */
66
+ url?: string;
67
+ /**
68
+ * contentType affects the value read from document.contentType, and how the document is parsed: as HTML or as XML.
69
+ * Values that are not "text/html" or an XML mime type will throw.
70
+ *
71
+ * @default 'text/html'.
72
+ */
73
+ contentType?: string;
74
+ /**
75
+ * The maximum size in code units for the separate storage areas used by localStorage and sessionStorage.
76
+ * Attempts to store data larger than this limit will cause a DOMException to be thrown. By default, it is set
77
+ * to 5,000,000 code units per origin, as inspired by the HTML specification.
78
+ *
79
+ * @default 5_000_000
80
+ */
81
+ storageQuota?: number;
82
+ /**
83
+ * Enable console?
84
+ *
85
+ * @default false
86
+ */
87
+ console?: boolean;
88
+ /**
89
+ * jsdom does not have the capability to render visual content, and will act like a headless browser by default.
90
+ * It provides hints to web pages through APIs such as document.hidden that their content is not visible.
91
+ *
92
+ * When the `pretendToBeVisual` option is set to `true`, jsdom will pretend that it is rendering and displaying
93
+ * content.
94
+ *
95
+ * @default true
96
+ */
97
+ pretendToBeVisual?: boolean;
98
+ /**
99
+ * `includeNodeLocations` preserves the location info produced by the HTML parser,
100
+ * allowing you to retrieve it with the nodeLocation() method (described below).
101
+ *
102
+ * It defaults to false to give the best performance,
103
+ * and cannot be used with an XML content type since our XML parser does not support location info.
104
+ *
105
+ * @default false
106
+ */
107
+ includeNodeLocations?: boolean | undefined;
108
+ /**
109
+ * @default 'dangerously'
110
+ */
111
+ runScripts?: 'dangerously' | 'outside-only';
112
+ /**
113
+ * Enable CookieJar
114
+ *
115
+ * @default false
116
+ */
117
+ cookieJar?: boolean;
118
+ resources?: 'usable';
119
+ }
120
+
121
+ /**
122
+ * Happy DOM options.
123
+ */
124
+ interface HappyDOMOptions {
125
+ width?: number;
126
+ height?: number;
127
+ url?: string;
128
+ settings?: {
129
+ disableJavaScriptEvaluation?: boolean;
130
+ disableJavaScriptFileLoading?: boolean;
131
+ disableCSSFileLoading?: boolean;
132
+ disableIframePageLoading?: boolean;
133
+ disableComputedStyleRendering?: boolean;
134
+ enableFileSystemHttpRequests?: boolean;
135
+ navigator?: {
136
+ userAgent?: string;
137
+ };
138
+ device?: {
139
+ prefersColorScheme?: string;
140
+ mediaType?: string;
141
+ };
142
+ };
143
+ }
144
+
145
+ interface EnvironmentReturn {
146
+ teardown: (global: any) => Awaitable<void>;
147
+ }
148
+ interface VmEnvironmentReturn {
149
+ getVmContext: () => {
150
+ [key: string]: any;
151
+ };
152
+ teardown: () => Awaitable<void>;
153
+ }
154
+ interface Environment {
155
+ name: string;
156
+ transformMode: 'web' | 'ssr';
157
+ setupVM?: (options: Record<string, any>) => Awaitable<VmEnvironmentReturn>;
158
+ setup: (global: any, options: Record<string, any>) => Awaitable<EnvironmentReturn>;
159
+ }
160
+ interface EnvironmentOptions {
161
+ /**
162
+ * jsdom options.
163
+ */
164
+ jsdom?: JSDOMOptions;
165
+ happyDOM?: HappyDOMOptions;
166
+ [x: string]: unknown;
167
+ }
168
+ interface ResolvedTestEnvironment {
169
+ environment: Environment;
170
+ options: Record<string, any> | null;
171
+ }
172
+
173
+ export type { AfterSuiteRunMeta as A, Constructable as C, Environment as E, HappyDOMOptions as H, JSDOMOptions as J, ModuleGraphData as M, Nullable as N, OnServerRestartHandler as O, ProvidedContext as P, ResolvedTestEnvironment as R, TransformMode as T, UserConsoleLog as U, VmEnvironmentReturn as V, EnvironmentReturn as a, Awaitable as b, Arrayable as c, ArgumentsType as d, MutableArray as e, EnvironmentOptions as f, ModuleCache as g };