vitest 0.29.7 → 0.30.0

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 (60) hide show
  1. package/LICENSE.md +3 -266
  2. package/dist/browser.d.ts +16 -4
  3. package/dist/browser.js +5 -4
  4. package/dist/child.js +12 -17
  5. package/dist/{chunk-api-setup.ac7748ac.js → chunk-api-setup.6662587e.js} +65 -51
  6. package/dist/{chunk-install-pkg.863031f2.js → chunk-install-pkg.6450b372.js} +33 -32
  7. package/dist/chunk-integrations-globals.d419838f.js +26 -0
  8. package/dist/{chunk-node-git.ed5bded8.js → chunk-node-git.4c43bd73.js} +4 -2
  9. package/dist/cli-wrapper.js +6 -5
  10. package/dist/cli.js +27 -26
  11. package/dist/config.cjs +15 -7
  12. package/dist/config.d.ts +15 -8
  13. package/dist/config.js +10 -6
  14. package/dist/coverage.d.ts +5 -2
  15. package/dist/coverage.js +6 -0
  16. package/dist/entry.js +35 -34
  17. package/dist/environments.d.ts +5 -2
  18. package/dist/environments.js +1 -1
  19. package/dist/index.d.ts +17 -21
  20. package/dist/index.js +9 -10
  21. package/dist/loader.js +396 -12
  22. package/dist/node.d.ts +9 -7
  23. package/dist/node.js +28 -30
  24. package/dist/runners.d.ts +5 -2
  25. package/dist/runners.js +34 -30
  26. package/dist/{types-fafda418.d.ts → types-f03c83c4.d.ts} +243 -317
  27. package/dist/utils.d.ts +1 -0
  28. package/dist/utils.js +1 -0
  29. package/dist/{chunk-node-pkg.f9696901.js → vendor-cli-api.c04eaa34.js} +3858 -5514
  30. package/dist/vendor-constants.538d9b49.js +54 -0
  31. package/dist/{chunk-integrations-coverage.e0a6acd2.js → vendor-coverage.a585b712.js} +5 -5
  32. package/dist/{chunk-runtime-mocker.344fec90.js → vendor-execute.8eaab47b.js} +9 -12
  33. package/dist/vendor-global.6795f91f.js +8 -0
  34. package/dist/vendor-index.4f82d248.js +161 -0
  35. package/dist/{chunk-env-node.affdd278.js → vendor-index.75f2b63d.js} +9 -2
  36. package/dist/{chunk-integrations-utils.d7c85bd9.js → vendor-index.81b9e499.js} +22 -21
  37. package/dist/{vendor-index.2cbcdd1e.js → vendor-index.c1e09929.js} +458 -373
  38. package/dist/vendor-index.fad2598b.js +44 -0
  39. package/dist/{vendor-index.534e612c.js → vendor-index.fc98d30f.js} +2 -2
  40. package/dist/{chunk-runtime-inspector.b1427a10.js → vendor-inspector.47fc8cbb.js} +5 -2
  41. package/dist/{chunk-runtime-rpc.1b5714dc.js → vendor-rpc.4d3d7a54.js} +5 -5
  42. package/dist/{chunk-integrations-run-once.a2b4758b.js → vendor-run-once.69ce7172.js} +3 -2
  43. package/dist/{chunk-runtime-setup.a49dc2f9.js → vendor-setup.common.cef38f4e.js} +2 -2
  44. package/dist/vendor-tasks.042d6084.js +14 -0
  45. package/dist/{chunk-utils-import.39ffe9c5.js → vendor-vi.a3ff54b1.js} +262 -3147
  46. package/dist/worker.js +13 -19
  47. package/package.json +40 -34
  48. package/utils.d.ts +1 -0
  49. package/dist/chunk-constants.bc18a549.js +0 -36
  50. package/dist/chunk-integrations-globals.a473e88a.js +0 -27
  51. package/dist/chunk-snapshot-env.a347d647.js +0 -11
  52. package/dist/chunk-utils-base.81f83dbd.js +0 -88
  53. package/dist/chunk-utils-env.04ffbef7.js +0 -70
  54. package/dist/chunk-utils-tasks.b41c8284.js +0 -107
  55. package/dist/env-afee91f0.d.ts +0 -10
  56. package/dist/vendor-index.783e7f3e.js +0 -71
  57. package/dist/vendor-index.bdee400f.js +0 -396
  58. package/dist/vendor-magic-string.es.b3bc5745.js +0 -1591
  59. /package/dist/{vendor-_commonjsHelpers.addc3445.js → vendor-_commonjsHelpers.76cdd49e.js} +0 -0
  60. /package/dist/{chunk-paths.e36446b4.js → vendor-paths.84fc7a99.js} +0 -0
@@ -1,396 +0,0 @@
1
- import 'acorn';
2
- import { builtinModules } from 'node:module';
3
- import 'node:fs';
4
- import { pathToFileURL } from 'node:url';
5
- import 'pathe';
6
- import assert from 'node:assert';
7
- import process$1 from 'node:process';
8
- import 'node:path';
9
- import v8 from 'node:v8';
10
- import { format, inspect } from 'node:util';
11
-
12
- const BUILTIN_MODULES = new Set(builtinModules);
13
-
14
- /**
15
- * @typedef ErrnoExceptionFields
16
- * @property {number | undefined} [errnode]
17
- * @property {string | undefined} [code]
18
- * @property {string | undefined} [path]
19
- * @property {string | undefined} [syscall]
20
- * @property {string | undefined} [url]
21
- *
22
- * @typedef {Error & ErrnoExceptionFields} ErrnoException
23
- */
24
-
25
- const isWindows = process$1.platform === 'win32';
26
-
27
- const own$1 = {}.hasOwnProperty;
28
-
29
- /**
30
- * Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
31
- * We cannot use Intl.ListFormat because it's not available in
32
- * --without-intl builds.
33
- *
34
- * @param {Array<string>} array
35
- * An array of strings.
36
- * @param {string} [type]
37
- * The list type to be inserted before the last element.
38
- * @returns {string}
39
- */
40
- function formatList(array, type = 'and') {
41
- return array.length < 3
42
- ? array.join(` ${type} `)
43
- : `${array.slice(0, -1).join(', ')}, ${type} ${array[array.length - 1]}`
44
- }
45
-
46
- /** @type {Map<string, MessageFunction|string>} */
47
- const messages = new Map();
48
- const nodeInternalPrefix = '__node_internal_';
49
- /** @type {number} */
50
- let userStackTraceLimit;
51
-
52
- createError(
53
- 'ERR_INVALID_MODULE_SPECIFIER',
54
- /**
55
- * @param {string} request
56
- * @param {string} reason
57
- * @param {string} [base]
58
- */
59
- (request, reason, base = undefined) => {
60
- return `Invalid module "${request}" ${reason}${
61
- base ? ` imported from ${base}` : ''
62
- }`
63
- },
64
- TypeError
65
- );
66
-
67
- createError(
68
- 'ERR_INVALID_PACKAGE_CONFIG',
69
- /**
70
- * @param {string} path
71
- * @param {string} [base]
72
- * @param {string} [message]
73
- */
74
- (path, base, message) => {
75
- return `Invalid package config ${path}${
76
- base ? ` while importing ${base}` : ''
77
- }${message ? `. ${message}` : ''}`
78
- },
79
- Error
80
- );
81
-
82
- createError(
83
- 'ERR_INVALID_PACKAGE_TARGET',
84
- /**
85
- * @param {string} pkgPath
86
- * @param {string} key
87
- * @param {unknown} target
88
- * @param {boolean} [isImport=false]
89
- * @param {string} [base]
90
- */
91
- (pkgPath, key, target, isImport = false, base = undefined) => {
92
- const relError =
93
- typeof target === 'string' &&
94
- !isImport &&
95
- target.length > 0 &&
96
- !target.startsWith('./');
97
- if (key === '.') {
98
- assert(isImport === false);
99
- return (
100
- `Invalid "exports" main target ${JSON.stringify(target)} defined ` +
101
- `in the package config ${pkgPath}package.json${
102
- base ? ` imported from ${base}` : ''
103
- }${relError ? '; targets must start with "./"' : ''}`
104
- )
105
- }
106
-
107
- return `Invalid "${
108
- isImport ? 'imports' : 'exports'
109
- }" target ${JSON.stringify(
110
- target
111
- )} defined for '${key}' in the package config ${pkgPath}package.json${
112
- base ? ` imported from ${base}` : ''
113
- }${relError ? '; targets must start with "./"' : ''}`
114
- },
115
- Error
116
- );
117
-
118
- createError(
119
- 'ERR_MODULE_NOT_FOUND',
120
- /**
121
- * @param {string} path
122
- * @param {string} base
123
- * @param {string} [type]
124
- */
125
- (path, base, type = 'package') => {
126
- return `Cannot find ${type} '${path}' imported from ${base}`
127
- },
128
- Error
129
- );
130
-
131
- createError(
132
- 'ERR_NETWORK_IMPORT_DISALLOWED',
133
- "import of '%s' by %s is not supported: %s",
134
- Error
135
- );
136
-
137
- createError(
138
- 'ERR_PACKAGE_IMPORT_NOT_DEFINED',
139
- /**
140
- * @param {string} specifier
141
- * @param {string} packagePath
142
- * @param {string} base
143
- */
144
- (specifier, packagePath, base) => {
145
- return `Package import specifier "${specifier}" is not defined${
146
- packagePath ? ` in package ${packagePath}package.json` : ''
147
- } imported from ${base}`
148
- },
149
- TypeError
150
- );
151
-
152
- createError(
153
- 'ERR_PACKAGE_PATH_NOT_EXPORTED',
154
- /**
155
- * @param {string} pkgPath
156
- * @param {string} subpath
157
- * @param {string} [base]
158
- */
159
- (pkgPath, subpath, base = undefined) => {
160
- if (subpath === '.')
161
- return `No "exports" main defined in ${pkgPath}package.json${
162
- base ? ` imported from ${base}` : ''
163
- }`
164
- return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${
165
- base ? ` imported from ${base}` : ''
166
- }`
167
- },
168
- Error
169
- );
170
-
171
- createError(
172
- 'ERR_UNSUPPORTED_DIR_IMPORT',
173
- "Directory import '%s' is not supported " +
174
- 'resolving ES modules imported from %s',
175
- Error
176
- );
177
-
178
- createError(
179
- 'ERR_UNKNOWN_FILE_EXTENSION',
180
- /**
181
- * @param {string} ext
182
- * @param {string} path
183
- */
184
- (ext, path) => {
185
- return `Unknown file extension "${ext}" for ${path}`
186
- },
187
- TypeError
188
- );
189
-
190
- createError(
191
- 'ERR_INVALID_ARG_VALUE',
192
- /**
193
- * @param {string} name
194
- * @param {unknown} value
195
- * @param {string} [reason='is invalid']
196
- */
197
- (name, value, reason = 'is invalid') => {
198
- let inspected = inspect(value);
199
-
200
- if (inspected.length > 128) {
201
- inspected = `${inspected.slice(0, 128)}...`;
202
- }
203
-
204
- const type = name.includes('.') ? 'property' : 'argument';
205
-
206
- return `The ${type} '${name}' ${reason}. Received ${inspected}`
207
- },
208
- TypeError
209
- // Note: extra classes have been shaken out.
210
- // , RangeError
211
- );
212
-
213
- createError(
214
- 'ERR_UNSUPPORTED_ESM_URL_SCHEME',
215
- /**
216
- * @param {URL} url
217
- * @param {Array<string>} supported
218
- */
219
- (url, supported) => {
220
- let message = `Only URLs with a scheme in: ${formatList(
221
- supported
222
- )} are supported by the default ESM loader`;
223
-
224
- if (isWindows && url.protocol.length === 2) {
225
- message += '. On Windows, absolute paths must be valid file:// URLs';
226
- }
227
-
228
- message += `. Received protocol '${url.protocol}'`;
229
- return message
230
- },
231
- Error
232
- );
233
-
234
- /**
235
- * Utility function for registering the error codes. Only used here. Exported
236
- * *only* to allow for testing.
237
- * @param {string} sym
238
- * @param {MessageFunction|string} value
239
- * @param {ErrorConstructor} def
240
- * @returns {new (...args: Array<any>) => Error}
241
- */
242
- function createError(sym, value, def) {
243
- // Special case for SystemError that formats the error message differently
244
- // The SystemErrors only have SystemError as their base classes.
245
- messages.set(sym, value);
246
-
247
- return makeNodeErrorWithCode(def, sym)
248
- }
249
-
250
- /**
251
- * @param {ErrorConstructor} Base
252
- * @param {string} key
253
- * @returns {ErrorConstructor}
254
- */
255
- function makeNodeErrorWithCode(Base, key) {
256
- // @ts-expect-error It’s a Node error.
257
- return NodeError
258
- /**
259
- * @param {Array<unknown>} args
260
- */
261
- function NodeError(...args) {
262
- const limit = Error.stackTraceLimit;
263
- if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
264
- const error = new Base();
265
- // Reset the limit and setting the name property.
266
- if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
267
- const message = getMessage(key, args, error);
268
- Object.defineProperties(error, {
269
- // Note: no need to implement `kIsNodeError` symbol, would be hard,
270
- // probably.
271
- message: {
272
- value: message,
273
- enumerable: false,
274
- writable: true,
275
- configurable: true
276
- },
277
- toString: {
278
- /** @this {Error} */
279
- value() {
280
- return `${this.name} [${key}]: ${this.message}`
281
- },
282
- enumerable: false,
283
- writable: true,
284
- configurable: true
285
- }
286
- });
287
-
288
- captureLargerStackTrace(error);
289
- // @ts-expect-error It’s a Node error.
290
- error.code = key;
291
- return error
292
- }
293
- }
294
-
295
- /**
296
- * @returns {boolean}
297
- */
298
- function isErrorStackTraceLimitWritable() {
299
- // Do no touch Error.stackTraceLimit as V8 would attempt to install
300
- // it again during deserialization.
301
- try {
302
- // @ts-expect-error: not in types?
303
- if (v8.startupSnapshot.isBuildingSnapshot()) {
304
- return false
305
- }
306
- } catch {}
307
-
308
- const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit');
309
- if (desc === undefined) {
310
- return Object.isExtensible(Error)
311
- }
312
-
313
- return own$1.call(desc, 'writable') && desc.writable !== undefined
314
- ? desc.writable
315
- : desc.set !== undefined
316
- }
317
-
318
- /**
319
- * This function removes unnecessary frames from Node.js core errors.
320
- * @template {(...args: unknown[]) => unknown} T
321
- * @param {T} fn
322
- * @returns {T}
323
- */
324
- function hideStackFrames(fn) {
325
- // We rename the functions that will be hidden to cut off the stacktrace
326
- // at the outermost one
327
- const hidden = nodeInternalPrefix + fn.name;
328
- Object.defineProperty(fn, 'name', {value: hidden});
329
- return fn
330
- }
331
-
332
- const captureLargerStackTrace = hideStackFrames(
333
- /**
334
- * @param {Error} error
335
- * @returns {Error}
336
- */
337
- // @ts-expect-error: fine
338
- function (error) {
339
- const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
340
- if (stackTraceLimitIsWritable) {
341
- userStackTraceLimit = Error.stackTraceLimit;
342
- Error.stackTraceLimit = Number.POSITIVE_INFINITY;
343
- }
344
-
345
- Error.captureStackTrace(error);
346
-
347
- // Reset the limit
348
- if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
349
-
350
- return error
351
- }
352
- );
353
-
354
- /**
355
- * @param {string} key
356
- * @param {Array<unknown>} args
357
- * @param {Error} self
358
- * @returns {string}
359
- */
360
- function getMessage(key, args, self) {
361
- const message = messages.get(key);
362
- assert(typeof message !== 'undefined', 'expected `message` to be found');
363
-
364
- if (typeof message === 'function') {
365
- assert(
366
- message.length <= args.length, // Default options do not count.
367
- `Code: ${key}; The provided arguments length (${args.length}) does not ` +
368
- `match the required ones (${message.length}).`
369
- );
370
- return Reflect.apply(message, self, args)
371
- }
372
-
373
- const regex = /%[dfijoOs]/g;
374
- let expectedLength = 0;
375
- while (regex.exec(message) !== null) expectedLength++;
376
- assert(
377
- expectedLength === args.length,
378
- `Code: ${key}; The provided arguments length (${args.length}) does not ` +
379
- `match the required ones (${expectedLength}).`
380
- );
381
- if (args.length === 0) return message
382
-
383
- args.unshift(message);
384
- return Reflect.apply(format, null, args)
385
- }
386
- function isNodeBuiltin(id = "") {
387
- id = id.replace(/^node:/, "").split("/")[0];
388
- return BUILTIN_MODULES.has(id);
389
- }
390
- pathToFileURL(process.cwd());
391
- const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
392
- function hasCJSSyntax(code) {
393
- return CJS_RE.test(code);
394
- }
395
-
396
- export { hasCJSSyntax as h, isNodeBuiltin as i };