vitest 0.25.8 → 0.26.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 (33) hide show
  1. package/LICENSE.md +0 -142
  2. package/dist/browser.d.ts +6 -3
  3. package/dist/browser.js +9 -10
  4. package/dist/{chunk-api-setup.dc71e384.js → chunk-api-setup.08f3b356.js} +39 -42
  5. package/dist/{chunk-integrations-globals.4d261bb8.js → chunk-integrations-globals.cab94a09.js} +5 -5
  6. package/dist/{chunk-runtime-chain.f86e5250.js → chunk-runtime-chain.e655f6cc.js} +4 -5
  7. package/dist/{chunk-runtime-error.616e92ca.js → chunk-runtime-error.dfbbf9be.js} +5 -5
  8. package/dist/{chunk-runtime-mocker.99b910d0.js → chunk-runtime-mocker.35fabb8b.js} +65 -64
  9. package/dist/{chunk-runtime-rpc.42aebbb9.js → chunk-runtime-rpc.7959fc79.js} +1 -1
  10. package/dist/{chunk-runtime-setup.5398e2c4.js → chunk-runtime-setup.4c1b529e.js} +16 -29
  11. package/dist/{chunk-vite-node-externalize.b9495318.js → chunk-snapshot-manager.7d978f79.js} +36 -322
  12. package/dist/{chunk-typecheck-constants.ed987901.js → chunk-typecheck-constants.3f865d14.js} +5 -4
  13. package/dist/{chunk-runtime-test-state.3f86f48f.js → chunk-utils-import.ca62c9d7.js} +49 -18
  14. package/dist/{chunk-utils-source-map.29ff1088.js → chunk-utils-source-map.5bbb50cd.js} +6 -4
  15. package/dist/cli.js +12 -13
  16. package/dist/config.d.ts +4 -1
  17. package/dist/entry.js +9 -9
  18. package/dist/environments.d.ts +4 -1
  19. package/dist/{index-5aad25c1.d.ts → index-c3f83a58.d.ts} +1 -1
  20. package/dist/index.d.ts +28 -10
  21. package/dist/index.js +6 -6
  22. package/dist/loader.js +7 -6
  23. package/dist/node.d.ts +18 -18
  24. package/dist/node.js +14 -14
  25. package/dist/suite.js +4 -4
  26. package/dist/{types-71ccd11d.d.ts → types-56bcd6c3.d.ts} +16 -273
  27. package/dist/vendor-index.783e7f3e.js +71 -0
  28. package/dist/vendor-index.96e022fd.js +211 -0
  29. package/dist/worker.js +12 -14
  30. package/package.json +4 -4
  31. package/dist/chunk-vite-node-source-map.b4ea5792.js +0 -446
  32. package/dist/chunk-vite-node-utils.0e4a6a88.js +0 -1385
  33. package/dist/vendor-source-map-support.1ce17397.js +0 -707
@@ -1,5 +1,8 @@
1
- import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, CommonServerOptions, AliasOptions } from 'vite';
1
+ import { UserConfig as UserConfig$1, ViteDevServer, CommonServerOptions, AliasOptions } from 'vite';
2
2
  import { Task as Task$1, TaskResult as TaskResult$1, Bench, Options } from 'tinybench';
3
+ import { ViteNodeRunner } from 'vite-node/client';
4
+ import { ViteNodeServer } from 'vite-node/server';
5
+ import { RawSourceMap, ViteNodeResolveId, FetchFunction, ModuleCacheMap } from 'vite-node';
3
6
  import { Stats } from 'fs';
4
7
  import { MessagePort } from 'worker_threads';
5
8
 
@@ -156,276 +159,6 @@ interface FakeTimerInstallOpts {
156
159
  shouldClearNativeTimers?: boolean | undefined;
157
160
  }
158
161
 
159
- interface UpdatePayload {
160
- type: 'update'
161
- updates: Update[]
162
- }
163
-
164
- interface Update {
165
- type: 'js-update' | 'css-update'
166
- path: string
167
- acceptedPath: string
168
- timestamp: number
169
- /**
170
- * @experimental internal
171
- */
172
- explicitImportRequired?: boolean | undefined
173
- }
174
-
175
- interface PrunePayload {
176
- type: 'prune'
177
- paths: string[]
178
- }
179
-
180
- interface FullReloadPayload {
181
- type: 'full-reload'
182
- path?: string
183
- }
184
-
185
- interface ErrorPayload {
186
- type: 'error'
187
- err: {
188
- [name: string]: any
189
- message: string
190
- stack: string
191
- id?: string
192
- frame?: string
193
- plugin?: string
194
- pluginCode?: string
195
- loc?: {
196
- file?: string
197
- line: number
198
- column: number
199
- }
200
- }
201
- }
202
-
203
- interface CustomEventMap {
204
- 'vite:beforeUpdate': UpdatePayload
205
- 'vite:afterUpdate': UpdatePayload
206
- 'vite:beforePrune': PrunePayload
207
- 'vite:beforeFullReload': FullReloadPayload
208
- 'vite:error': ErrorPayload
209
- 'vite:invalidate': InvalidatePayload
210
- }
211
-
212
- interface InvalidatePayload {
213
- path: string
214
- message: string | undefined
215
- }
216
-
217
- type InferCustomEventPayload<T extends string> =
218
- T extends keyof CustomEventMap ? CustomEventMap[T] : any
219
-
220
- type ModuleNamespace = Record<string, any> & {
221
- [Symbol.toStringTag]: 'Module'
222
- }
223
-
224
- interface ViteHotContext {
225
- readonly data: any
226
-
227
- accept(): void
228
- accept(cb: (mod: ModuleNamespace | undefined) => void): void
229
- accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
230
- accept(
231
- deps: readonly string[],
232
- cb: (mods: Array<ModuleNamespace | undefined>) => void,
233
- ): void
234
-
235
- acceptExports(
236
- exportNames: string | readonly string[],
237
- cb?: (mod: ModuleNamespace | undefined) => void,
238
- ): void
239
-
240
- dispose(cb: (data: any) => void): void
241
- prune(cb: (data: any) => void): void
242
- invalidate(message?: string): void
243
-
244
- on<T extends string>(
245
- event: T,
246
- cb: (payload: InferCustomEventPayload<T>) => void,
247
- ): void
248
- send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
249
- }
250
- declare class ModuleCacheMap extends Map<string, ModuleCache$1> {
251
- normalizePath(fsPath: string): string;
252
- /**
253
- * Assign partial data to the map
254
- */
255
- update(fsPath: string, mod: Partial<ModuleCache$1>): this;
256
- set(fsPath: string, mod: ModuleCache$1): this;
257
- get(fsPath: string): ModuleCache$1;
258
- delete(fsPath: string): boolean;
259
- /**
260
- * Invalidate modules that dependent on the given modules, up to the main entry
261
- */
262
- invalidateDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
263
- /**
264
- * Invalidate dependency modules of the given modules, down to the bottom-level dependencies
265
- */
266
- invalidateSubDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
267
- /**
268
- * Return parsed source map based on inlined source map of the module
269
- */
270
- getSourceMap(id: string): RawSourceMap | null;
271
- }
272
- declare class ViteNodeRunner {
273
- options: ViteNodeRunnerOptions;
274
- root: string;
275
- debug: boolean;
276
- /**
277
- * Holds the cache of modules
278
- * Keys of the map are filepaths, or plain package names
279
- */
280
- moduleCache: ModuleCacheMap;
281
- constructor(options: ViteNodeRunnerOptions);
282
- executeFile(file: string): Promise<any>;
283
- executeId(id: string): Promise<any>;
284
- getSourceMap(id: string): RawSourceMap | null;
285
- /** @internal */
286
- cachedRequest(rawId: string, callstack: string[]): Promise<any>;
287
- /** @internal */
288
- directRequest(id: string, fsPath: string, _callstack: string[]): Promise<any>;
289
- prepareContext(context: Record<string, any>): Record<string, any>;
290
- shouldResolveId(dep: string): boolean;
291
- /**
292
- * Define if a module should be interop-ed
293
- * This function mostly for the ability to override by subclass
294
- */
295
- shouldInterop(path: string, mod: any): boolean;
296
- /**
297
- * Import a module and interop it
298
- */
299
- interopedImport(path: string): Promise<any>;
300
- hasNestedDefault(target: any): any;
301
- }
302
- interface DepsHandlingOptions {
303
- external?: (string | RegExp)[];
304
- inline?: (string | RegExp)[] | true;
305
- /**
306
- * Try to guess the CJS version of a package when it's invalid ESM
307
- * @default false
308
- */
309
- fallbackCJS?: boolean;
310
- }
311
- interface StartOfSourceMap {
312
- file?: string;
313
- sourceRoot?: string;
314
- }
315
- interface RawSourceMap extends StartOfSourceMap {
316
- version: string;
317
- sources: string[];
318
- names: string[];
319
- sourcesContent?: string[];
320
- mappings: string;
321
- }
322
- interface FetchResult {
323
- code?: string;
324
- externalize?: string;
325
- map?: RawSourceMap;
326
- }
327
- type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
328
- type FetchFunction = (id: string) => Promise<FetchResult>;
329
- type ResolveIdFunction$1 = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
330
- type CreateHotContextFunction = (runner: ViteNodeRunner, url: string) => HotContext;
331
- interface ModuleCache$1 {
332
- promise?: Promise<any>;
333
- exports?: any;
334
- evaluated?: boolean;
335
- code?: string;
336
- map?: RawSourceMap;
337
- /**
338
- * Module ids that imports this module
339
- */
340
- importers?: Set<string>;
341
- }
342
- interface ViteNodeRunnerOptions {
343
- root: string;
344
- fetchModule: FetchFunction;
345
- resolveId?: ResolveIdFunction$1;
346
- createHotContext?: CreateHotContextFunction;
347
- base?: string;
348
- moduleCache?: ModuleCacheMap;
349
- interopDefault?: boolean;
350
- requestStubs?: Record<string, any>;
351
- debug?: boolean;
352
- }
353
- interface ViteNodeResolveId {
354
- external?: boolean | 'absolute' | 'relative';
355
- id: string;
356
- meta?: Record<string, any> | null;
357
- moduleSideEffects?: boolean | 'no-treeshake' | null;
358
- syntheticNamedExports?: boolean | string | null;
359
- }
360
- interface ViteNodeServerOptions {
361
- /**
362
- * Inject inline sourcemap to modules
363
- * @default 'inline'
364
- */
365
- sourcemap?: 'inline' | boolean;
366
- /**
367
- * Deps handling
368
- */
369
- deps?: DepsHandlingOptions;
370
- /**
371
- * Transform method for modules
372
- */
373
- transformMode?: {
374
- ssr?: RegExp[];
375
- web?: RegExp[];
376
- };
377
- debug?: DebuggerOptions;
378
- }
379
- interface DebuggerOptions {
380
- /**
381
- * Dump the transformed module to filesystem
382
- * Passing a string will dump to the specified path
383
- */
384
- dumpModules?: boolean | string;
385
- /**
386
- * Read dumpped module from filesystem whenever exists.
387
- * Useful for debugging by modifying the dump result from the filesystem.
388
- */
389
- loadDumppedModules?: boolean;
390
- }
391
-
392
- declare class Debugger {
393
- options: DebuggerOptions;
394
- dumpDir: string | undefined;
395
- initPromise: Promise<void> | undefined;
396
- externalizeMap: Map<string, string>;
397
- constructor(root: string, options: DebuggerOptions);
398
- clearDump(): Promise<void>;
399
- encodeId(id: string): string;
400
- recordExternalize(id: string, path: string): Promise<void>;
401
- dumpFile(id: string, result: TransformResult$1 | null): Promise<void>;
402
- loadDump(id: string): Promise<TransformResult$1 | null>;
403
- writeInfo(): Promise<void>;
404
- }
405
-
406
- declare class ViteNodeServer {
407
- server: ViteDevServer;
408
- options: ViteNodeServerOptions;
409
- private fetchPromiseMap;
410
- private transformPromiseMap;
411
- fetchCache: Map<string, {
412
- duration?: number | undefined;
413
- timestamp: number;
414
- result: FetchResult;
415
- }>;
416
- externalizeCache: Map<string, Promise<string | false>>;
417
- debugger?: Debugger;
418
- constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
419
- shouldExternalize(id: string): Promise<string | false>;
420
- resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
421
- getSourceMap(source: string): RawSourceMap | null;
422
- fetchModule(id: string): Promise<FetchResult>;
423
- transformRequest(id: string): Promise<TransformResult$1 | null | undefined>;
424
- getTransformMode(id: string): "web" | "ssr";
425
- private _fetchModule;
426
- private _transformRequest;
427
- }
428
-
429
162
  declare class SnapshotManager {
430
163
  options: SnapshotStateOptions;
431
164
  summary: SnapshotSummary;
@@ -1833,7 +1566,7 @@ interface InlineConfig {
1833
1566
  * Custom reporter for output. Can contain one or more built-in report names, reporter instances,
1834
1567
  * and/or paths to custom reporters
1835
1568
  */
1836
- reporters?: Arrayable<BuiltinReporters | Reporter | Omit<string, BuiltinReporters>>;
1569
+ reporters?: Arrayable<BuiltinReporters | 'html' | Reporter | Omit<string, BuiltinReporters>>;
1837
1570
  /**
1838
1571
  * diff output length
1839
1572
  */
@@ -1938,6 +1671,16 @@ interface InlineConfig {
1938
1671
  * @default false
1939
1672
  */
1940
1673
  restoreMocks?: boolean;
1674
+ /**
1675
+ * Will restore all global stubs to their original values before each test
1676
+ * @default false
1677
+ */
1678
+ unstubGlobals?: boolean;
1679
+ /**
1680
+ * Will restore all env stubs to their original values before each test
1681
+ * @default false
1682
+ */
1683
+ unstubEnvs?: boolean;
1941
1684
  /**
1942
1685
  * Serve API options.
1943
1686
  *
@@ -2483,4 +2226,4 @@ type Context = RootAndTarget & {
2483
2226
  lastActivePath?: string;
2484
2227
  };
2485
2228
 
2486
- export { WorkerContext as $, ApiConfig as A, BuiltinEnvironment as B, CollectLineNumbers as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, SuiteFactory as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, RuntimeContext as K, TestContext as L, ModuleGraphData as M, Vitest as N, OnTestFailedHandler as O, SnapshotData as P, SnapshotUpdateState as Q, RuntimeConfig as R, SequenceHooks as S, TaskResultPack as T, UserConfig as U, VitestEnvironment as V, SnapshotStateOptions as W, SnapshotMatchOptions as X, SnapshotResult as Y, UncheckedSnapshot as Z, SnapshotSummary as _, File as a, ResolveIdFunction as a0, AfterSuiteRunMeta as a1, WorkerRPC as a2, WorkerGlobalState as a3, Awaitable as a4, Nullable as a5, Arrayable as a6, ArgumentsType$1 as a7, MergeInsertions as a8, DeepMerge as a9, ViteNodeRunner as aA, TestSequencer as aB, startVitest as aC, TestSequencerConstructor as aD, MutableArray as aa, Constructable as ab, ModuleCache as ac, EnvironmentReturn as ad, Environment as ae, UserConsoleLog as af, Position as ag, ParsedStack as ah, ErrorWithDiff as ai, OnServerRestartHandler as aj, CoverageProvider as ak, CoverageProviderModule as al, CoverageReporter as am, CoverageOptions as an, ResolvedCoverageOptions as ao, BaseCoverageOptions as ap, CoverageIstanbulOptions as aq, CoverageC8Options as ar, BenchmarkUserOptions as as, Benchmark as at, BenchmarkResult as au, BenchFunction as av, BenchmarkAPI as aw, ModuleCacheMap as ax, ViteNodeRunnerOptions as ay, MockMap as az, ResolvedConfig as b, Reporter as c, RawErrsMap as d, TscErrorInfo as e, CollectLines as f, RootAndTarget as g, Context as h, CSSModuleScopeStrategy as i, VitestRunMode as j, TypecheckConfig as k, RunMode as l, TaskState as m, TaskBase as n, TaskResult as o, Suite as p, Test as q, TypeCheck as r, Task as s, TestFunction as t, TestOptions as u, TestAPI as v, SuiteAPI as w, HookCleanupCallback as x, SuiteHooks as y, SuiteCollector as z };
2229
+ export { WorkerContext as $, ApiConfig as A, BuiltinEnvironment as B, CollectLineNumbers as C, DoneCallback as D, EnvironmentOptions as E, FakeTimerInstallOpts as F, SuiteFactory as G, HookListener as H, InlineConfig as I, JSDOMOptions as J, RuntimeContext as K, TestContext as L, ModuleGraphData as M, Vitest as N, OnTestFailedHandler as O, SnapshotData as P, SnapshotUpdateState as Q, RuntimeConfig as R, SequenceHooks as S, TaskResultPack as T, UserConfig as U, VitestEnvironment as V, SnapshotStateOptions as W, SnapshotMatchOptions as X, SnapshotResult as Y, UncheckedSnapshot as Z, SnapshotSummary as _, File as a, ResolveIdFunction as a0, AfterSuiteRunMeta as a1, WorkerRPC as a2, WorkerGlobalState as a3, Awaitable as a4, Nullable as a5, Arrayable as a6, ArgumentsType$1 as a7, MergeInsertions as a8, DeepMerge as a9, TestSequencerConstructor as aA, MutableArray as aa, Constructable as ab, ModuleCache as ac, EnvironmentReturn as ad, Environment as ae, UserConsoleLog as af, Position as ag, ParsedStack as ah, ErrorWithDiff as ai, OnServerRestartHandler as aj, CoverageProvider as ak, CoverageProviderModule as al, CoverageReporter as am, CoverageOptions as an, ResolvedCoverageOptions as ao, BaseCoverageOptions as ap, CoverageIstanbulOptions as aq, CoverageC8Options as ar, BenchmarkUserOptions as as, Benchmark as at, BenchmarkResult as au, BenchFunction as av, BenchmarkAPI as aw, MockMap as ax, TestSequencer as ay, startVitest as az, ResolvedConfig as b, Reporter as c, RawErrsMap as d, TscErrorInfo as e, CollectLines as f, RootAndTarget as g, Context as h, CSSModuleScopeStrategy as i, VitestRunMode as j, TypecheckConfig as k, RunMode as l, TaskState as m, TaskBase as n, TaskResult as o, Suite as p, Test as q, TypeCheck as r, Task as s, TestFunction as t, TestOptions as u, TestAPI as v, SuiteAPI as w, HookCleanupCallback as x, SuiteHooks as y, SuiteCollector as z };
@@ -0,0 +1,71 @@
1
+ const DEFAULT_TIMEOUT = 6e4;
2
+ function createBirpc(functions, options) {
3
+ const {
4
+ post,
5
+ on,
6
+ eventNames = [],
7
+ serialize = (i) => i,
8
+ deserialize = (i) => i,
9
+ timeout = DEFAULT_TIMEOUT
10
+ } = options;
11
+ const rpcPromiseMap = /* @__PURE__ */ new Map();
12
+ const rpc = new Proxy({}, {
13
+ get(_, method) {
14
+ const sendEvent = (...args) => {
15
+ post(serialize({ m: method, a: args, t: "q" }));
16
+ };
17
+ if (eventNames.includes(method)) {
18
+ sendEvent.asEvent = sendEvent;
19
+ return sendEvent;
20
+ }
21
+ const sendCall = (...args) => {
22
+ return new Promise((resolve, reject) => {
23
+ const id = nanoid();
24
+ rpcPromiseMap.set(id, { resolve, reject });
25
+ post(serialize({ m: method, a: args, i: id, t: "q" }));
26
+ if (timeout >= 0) {
27
+ setTimeout(() => {
28
+ reject(new Error(`[birpc] timeout on calling "${method}"`));
29
+ rpcPromiseMap.delete(id);
30
+ }, timeout);
31
+ }
32
+ });
33
+ };
34
+ sendCall.asEvent = sendEvent;
35
+ return sendCall;
36
+ }
37
+ });
38
+ on(async (data, ...extra) => {
39
+ const msg = deserialize(data);
40
+ if (msg.t === "q") {
41
+ const { m: method, a: args } = msg;
42
+ let result, error;
43
+ try {
44
+ result = await functions[method].apply(rpc, args);
45
+ } catch (e) {
46
+ error = e;
47
+ }
48
+ if (msg.i)
49
+ post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
50
+ } else {
51
+ const { i: ack, r: result, e: error } = msg;
52
+ const promise = rpcPromiseMap.get(ack);
53
+ if (error)
54
+ promise?.reject(error);
55
+ else
56
+ promise?.resolve(result);
57
+ rpcPromiseMap.delete(ack);
58
+ }
59
+ });
60
+ return rpc;
61
+ }
62
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
63
+ function nanoid(size = 21) {
64
+ let id = "";
65
+ let i = size;
66
+ while (i--)
67
+ id += urlAlphabet[Math.random() * 64 | 0];
68
+ return id;
69
+ }
70
+
71
+ export { createBirpc as c };
@@ -0,0 +1,211 @@
1
+ import 'acorn';
2
+ import { builtinModules } from 'module';
3
+ import 'fs';
4
+ import { pathToFileURL } from 'url';
5
+ import 'path';
6
+ import assert from 'assert';
7
+ import { format, inspect } from 'util';
8
+
9
+ const BUILTIN_MODULES = new Set(builtinModules);
10
+
11
+ const isWindows = process.platform === "win32";
12
+ const own$1 = {}.hasOwnProperty;
13
+ const messages = /* @__PURE__ */ new Map();
14
+ const nodeInternalPrefix = "__node_internal_";
15
+ let userStackTraceLimit;
16
+ createError(
17
+ "ERR_INVALID_MODULE_SPECIFIER",
18
+ (request, reason, base = void 0) => {
19
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
20
+ },
21
+ TypeError
22
+ );
23
+ createError(
24
+ "ERR_INVALID_PACKAGE_CONFIG",
25
+ (path, base, message) => {
26
+ return `Invalid package config ${path}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
27
+ },
28
+ Error
29
+ );
30
+ createError(
31
+ "ERR_INVALID_PACKAGE_TARGET",
32
+ (pkgPath, key, target, isImport = false, base = void 0) => {
33
+ const relError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
34
+ if (key === ".") {
35
+ assert(isImport === false);
36
+ return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ""}${relError ? '; targets must start with "./"' : ""}`;
37
+ }
38
+ return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(
39
+ target
40
+ )} defined for '${key}' in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ""}${relError ? '; targets must start with "./"' : ""}`;
41
+ },
42
+ Error
43
+ );
44
+ createError(
45
+ "ERR_MODULE_NOT_FOUND",
46
+ (path, base, type = "package") => {
47
+ return `Cannot find ${type} '${path}' imported from ${base}`;
48
+ },
49
+ Error
50
+ );
51
+ createError(
52
+ "ERR_PACKAGE_IMPORT_NOT_DEFINED",
53
+ (specifier, packagePath, base) => {
54
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ""} imported from ${base}`;
55
+ },
56
+ TypeError
57
+ );
58
+ createError(
59
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
60
+ (pkgPath, subpath, base = void 0) => {
61
+ if (subpath === ".") {
62
+ return `No "exports" main defined in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`;
63
+ }
64
+ return `Package subpath '${subpath}' is not defined by "exports" in ${pkgPath}package.json${base ? ` imported from ${base}` : ""}`;
65
+ },
66
+ Error
67
+ );
68
+ createError(
69
+ "ERR_UNSUPPORTED_DIR_IMPORT",
70
+ "Directory import '%s' is not supported resolving ES modules imported from %s",
71
+ Error
72
+ );
73
+ createError(
74
+ "ERR_UNKNOWN_FILE_EXTENSION",
75
+ 'Unknown file extension "%s" for %s',
76
+ TypeError
77
+ );
78
+ createError(
79
+ "ERR_INVALID_ARG_VALUE",
80
+ (name, value, reason = "is invalid") => {
81
+ let inspected = inspect(value);
82
+ if (inspected.length > 128) {
83
+ inspected = `${inspected.slice(0, 128)}...`;
84
+ }
85
+ const type = name.includes(".") ? "property" : "argument";
86
+ return `The ${type} '${name}' ${reason}. Received ${inspected}`;
87
+ },
88
+ TypeError
89
+ );
90
+ createError(
91
+ "ERR_UNSUPPORTED_ESM_URL_SCHEME",
92
+ (url) => {
93
+ let message = "Only file and data URLs are supported by the default ESM loader";
94
+ if (isWindows && url.protocol.length === 2) {
95
+ message += ". On Windows, absolute paths must be valid file:// URLs";
96
+ }
97
+ message += `. Received protocol '${url.protocol}'`;
98
+ return message;
99
+ },
100
+ Error
101
+ );
102
+ function createError(sym, value, def) {
103
+ messages.set(sym, value);
104
+ return makeNodeErrorWithCode(def, sym);
105
+ }
106
+ function makeNodeErrorWithCode(Base, key) {
107
+ return NodeError;
108
+ function NodeError(...args) {
109
+ const limit = Error.stackTraceLimit;
110
+ if (isErrorStackTraceLimitWritable()) {
111
+ Error.stackTraceLimit = 0;
112
+ }
113
+ const error = new Base();
114
+ if (isErrorStackTraceLimitWritable()) {
115
+ Error.stackTraceLimit = limit;
116
+ }
117
+ const message = getMessage(key, args, error);
118
+ Object.defineProperty(error, "message", {
119
+ value: message,
120
+ enumerable: false,
121
+ writable: true,
122
+ configurable: true
123
+ });
124
+ Object.defineProperty(error, "toString", {
125
+ value() {
126
+ return `${this.name} [${key}]: ${this.message}`;
127
+ },
128
+ enumerable: false,
129
+ writable: true,
130
+ configurable: true
131
+ });
132
+ addCodeToName(error, Base.name, key);
133
+ error.code = key;
134
+ return error;
135
+ }
136
+ }
137
+ const addCodeToName = hideStackFrames(
138
+ function(error, name, code) {
139
+ error = captureLargerStackTrace(error);
140
+ error.name = `${name} [${code}]`;
141
+ error.stack;
142
+ if (name === "SystemError") {
143
+ Object.defineProperty(error, "name", {
144
+ value: name,
145
+ enumerable: false,
146
+ writable: true,
147
+ configurable: true
148
+ });
149
+ } else {
150
+ delete error.name;
151
+ }
152
+ }
153
+ );
154
+ function isErrorStackTraceLimitWritable() {
155
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
156
+ if (desc === void 0) {
157
+ return Object.isExtensible(Error);
158
+ }
159
+ return own$1.call(desc, "writable") ? desc.writable : desc.set !== void 0;
160
+ }
161
+ function hideStackFrames(fn) {
162
+ const hidden = nodeInternalPrefix + fn.name;
163
+ Object.defineProperty(fn, "name", { value: hidden });
164
+ return fn;
165
+ }
166
+ const captureLargerStackTrace = hideStackFrames(
167
+ function(error) {
168
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
169
+ if (stackTraceLimitIsWritable) {
170
+ userStackTraceLimit = Error.stackTraceLimit;
171
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
172
+ }
173
+ Error.captureStackTrace(error);
174
+ if (stackTraceLimitIsWritable) {
175
+ Error.stackTraceLimit = userStackTraceLimit;
176
+ }
177
+ return error;
178
+ }
179
+ );
180
+ function getMessage(key, args, self) {
181
+ const message = messages.get(key);
182
+ if (typeof message === "function") {
183
+ assert(
184
+ message.length <= args.length,
185
+ `Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${message.length}).`
186
+ );
187
+ return Reflect.apply(message, self, args);
188
+ }
189
+ const expectedLength = (message.match(/%[dfijoOs]/g) || []).length;
190
+ assert(
191
+ expectedLength === args.length,
192
+ `Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${expectedLength}).`
193
+ );
194
+ if (args.length === 0) {
195
+ return message;
196
+ }
197
+ args.unshift(message);
198
+ return Reflect.apply(format, null, args);
199
+ }
200
+ Object.freeze(["node", "import"]);
201
+ function isNodeBuiltin(id = "") {
202
+ id = id.replace(/^node:/, "").split("/")[0];
203
+ return BUILTIN_MODULES.has(id);
204
+ }
205
+ pathToFileURL(process.cwd());
206
+ const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
207
+ function hasCJSSyntax(code) {
208
+ return CJS_RE.test(code);
209
+ }
210
+
211
+ export { hasCJSSyntax as h, isNodeBuiltin as i };
package/dist/worker.js CHANGED
@@ -1,25 +1,22 @@
1
1
  import { b as resolve, e as distDir } from './chunk-utils-env.03f840f2.js';
2
- import { c as createBirpc, M as ModuleCacheMap } from './chunk-vite-node-source-map.b4ea5792.js';
2
+ import { c as createBirpc } from './vendor-index.783e7f3e.js';
3
3
  import { workerId } from 'tinypool';
4
- import { g as getWorkerState } from './chunk-typecheck-constants.ed987901.js';
5
- import { e as executeInViteNode } from './chunk-runtime-mocker.99b910d0.js';
6
- import { r as rpc } from './chunk-runtime-rpc.42aebbb9.js';
7
- import { p as processError } from './chunk-runtime-error.616e92ca.js';
4
+ import { ModuleCacheMap } from 'vite-node/client';
5
+ import { g as getWorkerState } from './chunk-typecheck-constants.3f865d14.js';
6
+ import { e as executeInViteNode } from './chunk-runtime-mocker.35fabb8b.js';
7
+ import { r as rpc } from './chunk-runtime-rpc.7959fc79.js';
8
+ import { p as processError } from './chunk-runtime-error.dfbbf9be.js';
8
9
  import 'tty';
9
10
  import 'url';
10
11
  import 'path';
11
- import 'module';
12
- import 'vm';
13
- import './chunk-vite-node-utils.0e4a6a88.js';
12
+ import 'local-pkg';
13
+ import 'vite';
14
14
  import 'fs';
15
+ import './vendor-index.96e022fd.js';
15
16
  import 'acorn';
17
+ import 'module';
16
18
  import 'assert';
17
19
  import 'util';
18
- import 'debug';
19
- import './vendor-source-map-support.1ce17397.js';
20
- import 'source-map';
21
- import 'local-pkg';
22
- import 'vite';
23
20
  import './chunk-utils-timers.793fd179.js';
24
21
  import 'chai';
25
22
 
@@ -53,7 +50,7 @@ async function startViteNode(ctx) {
53
50
  },
54
51
  moduleCache,
55
52
  mockMap,
56
- interopDefault: config.deps.interopDefault ?? true,
53
+ interopDefault: config.deps.interopDefault,
57
54
  root: config.root,
58
55
  base: config.base
59
56
  }))[0];
@@ -66,6 +63,7 @@ function init(ctx) {
66
63
  const { config, port, workerId: workerId$1 } = ctx;
67
64
  process.env.VITEST_WORKER_ID = String(workerId$1);
68
65
  process.env.VITEST_POOL_ID = String(workerId);
66
+ globalThis.__vitest_environment__ = config.environment;
69
67
  globalThis.__vitest_worker__ = {
70
68
  ctx,
71
69
  moduleCache,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.25.8",
4
+ "version": "0.26.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -113,7 +113,8 @@
113
113
  "tinybench": "^2.3.1",
114
114
  "tinypool": "^0.3.0",
115
115
  "tinyspy": "^1.0.2",
116
- "vite": "^3.0.0 || ^4.0.0"
116
+ "vite": "^3.0.0 || ^4.0.0",
117
+ "vite-node": "0.26.0"
117
118
  },
118
119
  "devDependencies": {
119
120
  "@antfu/install-pkg": "^0.1.1",
@@ -154,8 +155,7 @@
154
155
  "strip-ansi": "^7.0.1",
155
156
  "typescript": "^4.9.4",
156
157
  "ws": "^8.11.0",
157
- "@vitest/ui": "0.25.8",
158
- "vite-node": "0.25.8"
158
+ "@vitest/ui": "0.26.0"
159
159
  },
160
160
  "scripts": {
161
161
  "build": "rimraf dist && rollup -c",