vitest 0.25.8 → 0.26.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.
- package/LICENSE.md +0 -142
- package/browser.d.ts +1 -0
- package/dist/browser.d.ts +8 -5
- package/dist/browser.js +17 -16
- package/dist/{chunk-api-setup.dc71e384.js → chunk-api-setup.adeab271.js} +45 -46
- package/dist/{chunk-env-node.67948209.js → chunk-env-node.b3664da2.js} +1 -1
- package/dist/{chunk-install-pkg.579a5a27.js → chunk-install-pkg.6dd2bae6.js} +19 -19
- package/dist/chunk-integrations-globals.96914902.js +27 -0
- package/dist/{chunk-node-git.5a1b1656.js → chunk-node-git.a90c0582.js} +10 -6
- package/dist/{chunk-runtime-chain.f86e5250.js → chunk-runtime-chain.4cd984be.js} +8 -8
- package/dist/{chunk-runtime-error.616e92ca.js → chunk-runtime-error.f5c8aaf2.js} +10 -8
- package/dist/{chunk-runtime-mocker.99b910d0.js → chunk-runtime-mocker.3fa602ba.js} +73 -65
- package/dist/{chunk-runtime-rpc.42aebbb9.js → chunk-runtime-rpc.54d72169.js} +2 -2
- package/dist/{chunk-runtime-setup.5398e2c4.js → chunk-runtime-setup.9cdedce6.js} +21 -34
- package/dist/{chunk-vite-node-externalize.b9495318.js → chunk-snapshot-manager.e54d78b8.js} +82 -358
- package/dist/{chunk-typecheck-constants.ed987901.js → chunk-typecheck-constants.06e1fe5b.js} +8 -7
- package/dist/{chunk-utils-env.03f840f2.js → chunk-utils-env.3fdc1793.js} +8 -8
- package/dist/{chunk-runtime-test-state.3f86f48f.js → chunk-utils-import.afe2ffde.js} +50 -19
- package/dist/{chunk-utils-source-map.29ff1088.js → chunk-utils-source-map.59ba6b0a.js} +6 -4
- package/dist/{chunk-utils-timers.793fd179.js → chunk-utils-timers.715da787.js} +31 -15
- package/dist/cli-wrapper.js +10 -5
- package/dist/cli.js +30 -25
- package/dist/config.d.ts +6 -3
- package/dist/entry.js +18 -16
- package/dist/environments.d.ts +6 -3
- package/dist/environments.js +2 -2
- package/dist/{index-5aad25c1.d.ts → index-1e9f7f83.d.ts} +1 -1
- package/dist/index.d.ts +30 -12
- package/dist/index.js +12 -10
- package/dist/loader.js +12 -7
- package/dist/node.d.ts +21 -20
- package/dist/node.js +33 -25
- package/dist/suite.js +10 -8
- package/dist/{types-71ccd11d.d.ts → types-c41bae41.d.ts} +39 -279
- package/dist/vendor-index.2e96c50b.js +215 -0
- package/dist/vendor-index.783e7f3e.js +71 -0
- package/dist/{vendor-index.e1d4cf84.js → vendor-index.7a2cebfe.js} +16 -16
- package/dist/{vendor-index.737c3cff.js → vendor-index.b2fdde54.js} +9 -8
- package/dist/worker.js +21 -18
- package/environments.d.ts +1 -0
- package/package.json +4 -4
- package/dist/chunk-integrations-globals.4d261bb8.js +0 -25
- package/dist/chunk-vite-node-source-map.b4ea5792.js +0 -446
- package/dist/chunk-vite-node-utils.0e4a6a88.js +0 -1385
- package/dist/vendor-source-map-support.1ce17397.js +0 -707
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ViteNodeRunner } from 'vite-node/client';
|
|
2
|
+
import { isInternalRequest } from 'vite-node/utils';
|
|
2
3
|
import { normalizePath } from 'vite';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { p as picocolors, d as dirname, j as join, c as basename, l as extname
|
|
4
|
+
import { i as isNodeBuiltin } from './vendor-index.2e96c50b.js';
|
|
5
|
+
import { g as getWorkerState, y as getType, K as getAllMockableProperties, e as getCurrentEnvironment } from './chunk-typecheck-constants.06e1fe5b.js';
|
|
6
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
7
|
+
import { b as resolve, e as distDir, g as isAbsolute, p as picocolors, d as dirname, j as join, c as basename, l as extname } from './chunk-utils-env.3fdc1793.js';
|
|
7
8
|
|
|
8
9
|
class RefTracker {
|
|
9
10
|
constructor() {
|
|
@@ -27,20 +28,21 @@ function isSpecialProp(prop, parentType) {
|
|
|
27
28
|
return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
|
|
28
29
|
}
|
|
29
30
|
const _VitestMocker = class {
|
|
30
|
-
constructor(
|
|
31
|
-
this.
|
|
32
|
-
this.moduleCache = moduleCache;
|
|
33
|
-
this.request = request;
|
|
31
|
+
constructor(runner) {
|
|
32
|
+
this.runner = runner;
|
|
34
33
|
this.resolveCache = /* @__PURE__ */ new Map();
|
|
35
34
|
}
|
|
36
35
|
get root() {
|
|
37
|
-
return this.options.root;
|
|
36
|
+
return this.runner.options.root;
|
|
38
37
|
}
|
|
39
38
|
get base() {
|
|
40
|
-
return this.options.base;
|
|
39
|
+
return this.runner.options.base;
|
|
41
40
|
}
|
|
42
41
|
get mockMap() {
|
|
43
|
-
return this.options.mockMap;
|
|
42
|
+
return this.runner.options.mockMap;
|
|
43
|
+
}
|
|
44
|
+
get moduleCache() {
|
|
45
|
+
return this.runner.moduleCache;
|
|
44
46
|
}
|
|
45
47
|
getSuiteFilepath() {
|
|
46
48
|
return getWorkerState().filepath || "global";
|
|
@@ -54,21 +56,22 @@ const _VitestMocker = class {
|
|
|
54
56
|
...suiteMocks
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
|
-
async resolvePath(
|
|
58
|
-
const
|
|
59
|
-
const external =
|
|
59
|
+
async resolvePath(rawId, importer) {
|
|
60
|
+
const [id, fsPath] = await this.runner.resolveUrl(rawId, importer);
|
|
61
|
+
const external = !isAbsolute(fsPath) || fsPath.includes("/node_modules/") ? rawId : null;
|
|
60
62
|
return {
|
|
61
|
-
|
|
63
|
+
id,
|
|
64
|
+
fsPath,
|
|
62
65
|
external
|
|
63
66
|
};
|
|
64
67
|
}
|
|
65
68
|
async resolveMocks() {
|
|
66
69
|
await Promise.all(_VitestMocker.pendingIds.map(async (mock) => {
|
|
67
|
-
const {
|
|
70
|
+
const { fsPath, external } = await this.resolvePath(mock.id, mock.importer);
|
|
68
71
|
if (mock.type === "unmock")
|
|
69
|
-
this.unmockPath(
|
|
72
|
+
this.unmockPath(fsPath);
|
|
70
73
|
if (mock.type === "mock")
|
|
71
|
-
this.mockPath(mock.id,
|
|
74
|
+
this.mockPath(mock.id, fsPath, external, mock.factory);
|
|
72
75
|
}));
|
|
73
76
|
_VitestMocker.pendingIds = [];
|
|
74
77
|
}
|
|
@@ -82,15 +85,15 @@ const _VitestMocker = class {
|
|
|
82
85
|
exports = await mock();
|
|
83
86
|
} catch (err) {
|
|
84
87
|
const vitestError = new Error(
|
|
85
|
-
|
|
88
|
+
'[vitest] There was an error, when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/#vi-mock'
|
|
86
89
|
);
|
|
87
90
|
vitestError.cause = err;
|
|
88
91
|
throw vitestError;
|
|
89
92
|
}
|
|
90
|
-
|
|
91
|
-
throw new Error('[vitest] vi.mock(path: string, factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?');
|
|
92
|
-
const filepath = dep.slice("mock:".length);
|
|
93
|
+
const filepath = dep.slice(5);
|
|
93
94
|
const mockpath = ((_b = this.resolveCache.get(this.getSuiteFilepath())) == null ? void 0 : _b[filepath]) || filepath;
|
|
95
|
+
if (exports === null || typeof exports !== "object")
|
|
96
|
+
throw new Error(`[vitest] vi.mock("${mockpath}", factory?: () => unknown) is not returning an object. Did you mean to return an object with a "default" key?`);
|
|
94
97
|
const moduleExports = new Proxy(exports, {
|
|
95
98
|
get(target, prop) {
|
|
96
99
|
const val = target[prop];
|
|
@@ -106,7 +109,7 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
|
|
|
106
109
|
const actual = await vi.importActual("${mockpath}")
|
|
107
110
|
return {
|
|
108
111
|
...actual,
|
|
109
|
-
// your
|
|
112
|
+
// your mocked methods
|
|
110
113
|
},
|
|
111
114
|
})`)}
|
|
112
115
|
`
|
|
@@ -125,15 +128,10 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
|
|
|
125
128
|
return this.getMocks()[id];
|
|
126
129
|
}
|
|
127
130
|
normalizePath(path) {
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
getFsPath(path, external) {
|
|
131
|
-
if (external)
|
|
132
|
-
return mergeSlashes(`/@fs/${path}`);
|
|
133
|
-
return normalizeRequestId(path, this.base);
|
|
131
|
+
return this.moduleCache.normalizePath(path);
|
|
134
132
|
}
|
|
135
133
|
resolveMockPath(mockPath, external) {
|
|
136
|
-
const path =
|
|
134
|
+
const path = external || mockPath;
|
|
137
135
|
if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
|
|
138
136
|
const mockDirname = dirname(path);
|
|
139
137
|
const mockFolder = join(this.root, "__mocks__", mockDirname);
|
|
@@ -235,41 +233,35 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
|
|
|
235
233
|
this.mockMap.set(suitefile, mocks);
|
|
236
234
|
this.resolveCache.set(suitefile, resolves);
|
|
237
235
|
}
|
|
238
|
-
async importActual(
|
|
239
|
-
const {
|
|
240
|
-
const
|
|
241
|
-
const result = await this.request(fsPath);
|
|
236
|
+
async importActual(rawId, importee) {
|
|
237
|
+
const { id, fsPath } = await this.resolvePath(rawId, importee);
|
|
238
|
+
const result = await this.runner.cachedRequest(id, fsPath, [importee]);
|
|
242
239
|
return result;
|
|
243
240
|
}
|
|
244
|
-
async importMock(
|
|
245
|
-
const {
|
|
246
|
-
const fsPath = this.getFsPath(path, external);
|
|
241
|
+
async importMock(rawId, importee) {
|
|
242
|
+
const { id, fsPath, external } = await this.resolvePath(rawId, importee);
|
|
247
243
|
const normalizedId = this.normalizePath(fsPath);
|
|
248
244
|
let mock = this.getDependencyMock(normalizedId);
|
|
249
245
|
if (mock === void 0)
|
|
250
246
|
mock = this.resolveMockPath(fsPath, external);
|
|
251
247
|
if (mock === null) {
|
|
252
|
-
await this.
|
|
253
|
-
const mod = await this.request(fsPath);
|
|
248
|
+
const mod = await this.runner.cachedRequest(id, fsPath, [importee]);
|
|
254
249
|
return this.mockObject(mod);
|
|
255
250
|
}
|
|
256
251
|
if (typeof mock === "function")
|
|
257
252
|
return this.callFunctionMock(fsPath, mock);
|
|
258
|
-
return this.
|
|
253
|
+
return this.runner.dependencyRequest(mock, mock, [importee]);
|
|
259
254
|
}
|
|
260
|
-
async
|
|
255
|
+
async initializeSpyModule() {
|
|
261
256
|
if (_VitestMocker.spyModule)
|
|
262
257
|
return;
|
|
263
|
-
_VitestMocker.spyModule = await this.
|
|
264
|
-
}
|
|
265
|
-
async requestWithMock(
|
|
266
|
-
|
|
267
|
-
this.
|
|
268
|
-
|
|
269
|
-
]);
|
|
270
|
-
const id = this.normalizePath(dep);
|
|
258
|
+
_VitestMocker.spyModule = await this.runner.executeId(_VitestMocker.spyModulePath);
|
|
259
|
+
}
|
|
260
|
+
async requestWithMock(url, callstack) {
|
|
261
|
+
if (_VitestMocker.pendingIds.length)
|
|
262
|
+
await this.resolveMocks();
|
|
263
|
+
const id = this.normalizePath(url);
|
|
271
264
|
const mock = this.getDependencyMock(id);
|
|
272
|
-
const callstack = this.request.callstack;
|
|
273
265
|
const mockPath = this.getMockPath(id);
|
|
274
266
|
if (mock === null) {
|
|
275
267
|
const cache = this.moduleCache.get(mockPath);
|
|
@@ -277,11 +269,11 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
|
|
|
277
269
|
return cache.exports;
|
|
278
270
|
const exports = {};
|
|
279
271
|
this.moduleCache.set(mockPath, { exports });
|
|
280
|
-
const mod = await this.
|
|
272
|
+
const mod = await this.runner.directRequest(url, url, []);
|
|
281
273
|
this.mockObject(mod, exports);
|
|
282
274
|
return exports;
|
|
283
275
|
}
|
|
284
|
-
if (typeof mock === "function" && !callstack.includes(mockPath)) {
|
|
276
|
+
if (typeof mock === "function" && !callstack.includes(mockPath) && !callstack.includes(url)) {
|
|
285
277
|
callstack.push(mockPath);
|
|
286
278
|
const result = await this.callFunctionMock(mockPath, mock);
|
|
287
279
|
const indexMock = callstack.indexOf(mockPath);
|
|
@@ -289,8 +281,8 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
|
|
|
289
281
|
return result;
|
|
290
282
|
}
|
|
291
283
|
if (typeof mock === "string" && !callstack.includes(mock))
|
|
292
|
-
|
|
293
|
-
return
|
|
284
|
+
url = mock;
|
|
285
|
+
return url;
|
|
294
286
|
}
|
|
295
287
|
queueMock(id, importer, factory) {
|
|
296
288
|
_VitestMocker.pendingIds.push({ type: "mock", id, importer, factory });
|
|
@@ -301,10 +293,12 @@ ${picocolors.exports.green(`vi.mock("${mockpath}", async () => {
|
|
|
301
293
|
};
|
|
302
294
|
let VitestMocker = _VitestMocker;
|
|
303
295
|
VitestMocker.pendingIds = [];
|
|
296
|
+
VitestMocker.spyModulePath = resolve(distDir, "spy.js");
|
|
304
297
|
|
|
305
298
|
async function executeInViteNode(options) {
|
|
306
299
|
const runner = new VitestRunner(options);
|
|
307
300
|
await runner.executeId("/@vite/env");
|
|
301
|
+
await runner.mocker.initializeSpyModule();
|
|
308
302
|
const result = [];
|
|
309
303
|
for (const file of options.files)
|
|
310
304
|
result.push(await runner.executeFile(file));
|
|
@@ -314,25 +308,39 @@ class VitestRunner extends ViteNodeRunner {
|
|
|
314
308
|
constructor(options) {
|
|
315
309
|
super(options);
|
|
316
310
|
this.options = options;
|
|
311
|
+
this.mocker = new VitestMocker(this);
|
|
312
|
+
}
|
|
313
|
+
shouldResolveId(id, _importee) {
|
|
314
|
+
if (isInternalRequest(id))
|
|
315
|
+
return false;
|
|
316
|
+
const environment = getCurrentEnvironment();
|
|
317
|
+
return environment === "node" ? !isNodeBuiltin(id) : true;
|
|
318
|
+
}
|
|
319
|
+
async resolveUrl(id, importee) {
|
|
320
|
+
if (importee && importee.startsWith("mock:"))
|
|
321
|
+
importee = importee.slice(5);
|
|
322
|
+
return super.resolveUrl(id, importee);
|
|
323
|
+
}
|
|
324
|
+
async dependencyRequest(id, fsPath, callstack) {
|
|
325
|
+
const mocked = await this.mocker.requestWithMock(fsPath, callstack);
|
|
326
|
+
if (typeof mocked === "string")
|
|
327
|
+
return super.dependencyRequest(mocked, mocked, callstack);
|
|
328
|
+
if (mocked && typeof mocked === "object")
|
|
329
|
+
return mocked;
|
|
330
|
+
return super.dependencyRequest(id, fsPath, callstack);
|
|
317
331
|
}
|
|
318
332
|
prepareContext(context) {
|
|
319
|
-
const request = context.__vite_ssr_import__;
|
|
320
|
-
const resolveId = context.__vitest_resolve_id__;
|
|
321
|
-
const resolveUrl = async (dep) => {
|
|
322
|
-
const [id, resolvedId] = await resolveId(dep);
|
|
323
|
-
return resolvedId || id;
|
|
324
|
-
};
|
|
325
|
-
const mocker = new VitestMocker(this.options, this.moduleCache, request);
|
|
326
333
|
const workerState = getWorkerState();
|
|
327
334
|
if (workerState.filepath && normalizePath(workerState.filepath) === normalizePath(context.__filename)) {
|
|
328
335
|
Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalThis.__vitest_index__ });
|
|
329
336
|
}
|
|
330
337
|
return Object.assign(context, {
|
|
331
|
-
|
|
332
|
-
__vite_ssr_dynamic_import__: async (dep) => mocker.requestWithMock(await resolveUrl(dep)),
|
|
333
|
-
__vitest_mocker__: mocker
|
|
338
|
+
__vitest_mocker__: this.mocker
|
|
334
339
|
});
|
|
335
340
|
}
|
|
341
|
+
shouldInterop(path, mod) {
|
|
342
|
+
return this.options.interopDefault ?? (getCurrentEnvironment() !== "node" && super.shouldInterop(path, mod));
|
|
343
|
+
}
|
|
336
344
|
}
|
|
337
345
|
|
|
338
346
|
export { VitestRunner as V, executeInViteNode as e };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getWorkerState } from './chunk-typecheck-constants.
|
|
2
|
-
import { s as safeSetTimeout } from './chunk-utils-timers.
|
|
1
|
+
import { g as getWorkerState } from './chunk-typecheck-constants.06e1fe5b.js';
|
|
2
|
+
import { s as safeSetTimeout } from './chunk-utils-timers.715da787.js';
|
|
3
3
|
|
|
4
4
|
const safeRandom = Math.random;
|
|
5
5
|
function withSafeTimers(fn) {
|
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
import { performance } from 'perf_hooks';
|
|
2
2
|
import { s as someTasksAreOnly, i as interpretTaskModes, t as takeCoverageInsideWorker, p as pLimit } from './chunk-integrations-coverage.befed097.js';
|
|
3
|
-
import { r as resetRunOnceCounter, i as index, v as vi, s as setCurrentTest } from './chunk-
|
|
4
|
-
import { g as getWorkerState, R as RealDate, t as toArray,
|
|
5
|
-
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getBenchOptions, n as getFn, o as setState, G as GLOBAL_EXPECT, p as getState } from './chunk-runtime-chain.
|
|
6
|
-
import { r as rpc } from './chunk-runtime-rpc.
|
|
7
|
-
import { p as processError } from './chunk-runtime-error.
|
|
8
|
-
import {
|
|
9
|
-
import { e as environments } from './chunk-env-node.
|
|
10
|
-
import { i as isNode, a as isBrowser } from './chunk-utils-env.
|
|
11
|
-
import { b as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.
|
|
12
|
-
|
|
13
|
-
function installSourcemapsSupport(options) {
|
|
14
|
-
sourceMapSupport.exports.install({
|
|
15
|
-
environment: "node",
|
|
16
|
-
handleUncaughtExceptions: false,
|
|
17
|
-
retrieveSourceMap(source) {
|
|
18
|
-
const map = options.getSourceMap(source);
|
|
19
|
-
if (map) {
|
|
20
|
-
return {
|
|
21
|
-
url: source,
|
|
22
|
-
map
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
3
|
+
import { r as resetRunOnceCounter, i as index, v as vi, s as setCurrentTest } from './chunk-utils-import.afe2ffde.js';
|
|
4
|
+
import { g as getWorkerState, R as RealDate, t as toArray, l as relativePath, j as isRunningInBenchmark, p as partitionSuiteChildren, q as shuffle, u as hasTests, v as hasFailed, w as createDefer, f as getFullName } from './chunk-typecheck-constants.06e1fe5b.js';
|
|
5
|
+
import { f as clearCollectorContext, h as defaultSuite, j as setHooks, k as getHooks, l as collectorContext, m as getBenchOptions, n as getFn, o as setState, G as GLOBAL_EXPECT, p as getState } from './chunk-runtime-chain.4cd984be.js';
|
|
6
|
+
import { r as rpc } from './chunk-runtime-rpc.54d72169.js';
|
|
7
|
+
import { p as processError } from './chunk-runtime-error.f5c8aaf2.js';
|
|
8
|
+
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
9
|
+
import { e as environments } from './chunk-env-node.b3664da2.js';
|
|
10
|
+
import { i as isNode, a as isBrowser } from './chunk-utils-env.3fdc1793.js';
|
|
11
|
+
import { b as safeClearTimeout, s as safeSetTimeout } from './chunk-utils-timers.715da787.js';
|
|
29
12
|
|
|
30
13
|
let globalSetup = false;
|
|
31
14
|
async function setupGlobalEnv(config) {
|
|
@@ -46,7 +29,7 @@ async function setupGlobalEnv(config) {
|
|
|
46
29
|
await setupConsoleLogSpy();
|
|
47
30
|
}
|
|
48
31
|
if (config.globals)
|
|
49
|
-
(await import('./chunk-integrations-globals.
|
|
32
|
+
(await import('./chunk-integrations-globals.96914902.js')).registerApiGlobally();
|
|
50
33
|
}
|
|
51
34
|
function setupDefines(defines) {
|
|
52
35
|
for (const key in defines)
|
|
@@ -57,8 +40,8 @@ async function setupConsoleLogSpy() {
|
|
|
57
40
|
const stderrBuffer = /* @__PURE__ */ new Map();
|
|
58
41
|
const timers = /* @__PURE__ */ new Map();
|
|
59
42
|
const unknownTestId = "__vitest__unknown_test__";
|
|
60
|
-
const { Writable } = await import('stream');
|
|
61
|
-
const { Console } = await import('console');
|
|
43
|
+
const { Writable } = await import('node:stream');
|
|
44
|
+
const { Console } = await import('node:console');
|
|
62
45
|
function schedule(taskId) {
|
|
63
46
|
const timer = timers.get(taskId);
|
|
64
47
|
const { stdoutTime, stderrTime } = timer;
|
|
@@ -346,7 +329,7 @@ const callCleanupHooks = async (cleanups) => {
|
|
|
346
329
|
async function runTest(test) {
|
|
347
330
|
var _a, _b, _c;
|
|
348
331
|
if (test.mode !== "run") {
|
|
349
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
332
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.4cd984be.js').then(function (n) { return n.r; });
|
|
350
333
|
getSnapshotClient().skipTestSnapshots(test);
|
|
351
334
|
return;
|
|
352
335
|
}
|
|
@@ -363,7 +346,7 @@ async function runTest(test) {
|
|
|
363
346
|
clearModuleMocks();
|
|
364
347
|
setCurrentTest(test);
|
|
365
348
|
if (isNode) {
|
|
366
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
349
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.4cd984be.js').then(function (n) { return n.r; });
|
|
367
350
|
await getSnapshotClient().setTest(test);
|
|
368
351
|
}
|
|
369
352
|
const workerState = getWorkerState();
|
|
@@ -426,7 +409,7 @@ async function runTest(test) {
|
|
|
426
409
|
console.error(test.result.error.message, test.result.error.stackStr);
|
|
427
410
|
setCurrentTest(void 0);
|
|
428
411
|
if (isNode) {
|
|
429
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
412
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.4cd984be.js').then(function (n) { return n.r; });
|
|
430
413
|
getSnapshotClient().clearTest();
|
|
431
414
|
}
|
|
432
415
|
test.result.duration = now() - start;
|
|
@@ -632,7 +615,7 @@ async function startTestsBrowser(paths, config) {
|
|
|
632
615
|
async function startTestsNode(paths, config) {
|
|
633
616
|
const files = await collectTests(paths, config);
|
|
634
617
|
rpc().onCollected(files);
|
|
635
|
-
const { getSnapshotClient } = await import('./chunk-runtime-chain.
|
|
618
|
+
const { getSnapshotClient } = await import('./chunk-runtime-chain.4cd984be.js').then(function (n) { return n.r; });
|
|
636
619
|
getSnapshotClient().clear();
|
|
637
620
|
await runFiles(files, config);
|
|
638
621
|
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
@@ -647,13 +630,17 @@ async function startTests(paths, config) {
|
|
|
647
630
|
return startTestsNode(paths, config);
|
|
648
631
|
}
|
|
649
632
|
function clearModuleMocks() {
|
|
650
|
-
const { clearMocks, mockReset, restoreMocks } = getWorkerState().config;
|
|
633
|
+
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = getWorkerState().config;
|
|
651
634
|
if (restoreMocks)
|
|
652
635
|
vi.restoreAllMocks();
|
|
653
636
|
else if (mockReset)
|
|
654
637
|
vi.resetAllMocks();
|
|
655
638
|
else if (clearMocks)
|
|
656
639
|
vi.clearAllMocks();
|
|
640
|
+
if (unstubEnvs)
|
|
641
|
+
vi.unstubAllEnvs();
|
|
642
|
+
if (unstubGlobals)
|
|
643
|
+
vi.unstubAllGlobals();
|
|
657
644
|
}
|
|
658
645
|
|
|
659
646
|
export { setupGlobalEnv as a, startTests as s, withEnv as w };
|