vitest 0.0.117 → 0.0.121
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/dist/cli.js +28 -10
- package/dist/{constants-080f26e8.js → constants-22bbd600.js} +1 -1
- package/dist/{diff-80c47cfa.js → diff-a295cb37.js} +1 -1
- package/dist/entry.js +81 -32
- package/dist/{global-d95ee155.js → global-f5814404.js} +5 -5
- package/dist/{index-bf29f0e6.js → index-090545ef.js} +1 -19
- package/dist/{index-33d800eb.js → index-123a18df.js} +60 -36
- package/dist/{index-2b1f526f.js → index-32bc2073.js} +2 -2
- package/dist/index.d.ts +93 -60
- package/dist/index.js +4 -4
- package/dist/{jest-mock-4a754991.js → jest-mock-038a01b3.js} +1 -1
- package/dist/node.d.ts +14 -3
- package/dist/node.js +4 -4
- package/dist/{setup-95b119ff.js → setup-c9c7cb5b.js} +3 -3
- package/dist/utils.js +1 -1
- package/dist/{vi-39f06eb7.js → vi-db2bc738.js} +104 -24
- package/dist/worker.js +36 -22
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as dirname$2, b as basename$2, k as resolve, p as mergeSlashes, q as join$2, s as slash, m as toFilePath } from './index-090545ef.js';
|
|
2
2
|
import { c as createBirpc } from './index-e909c175.js';
|
|
3
|
-
import { c as distDir } from './constants-
|
|
3
|
+
import { c as distDir } from './constants-22bbd600.js';
|
|
4
4
|
import { builtinModules, createRequire } from 'module';
|
|
5
5
|
import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
|
|
6
6
|
import vm from 'vm';
|
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
import fs, { promises, realpathSync, statSync, Stats, existsSync, readdirSync } from 'fs';
|
|
9
9
|
import assert from 'assert';
|
|
10
10
|
import { format as format$2, inspect } from 'util';
|
|
11
|
-
import { a as spyOn, s as spies } from './jest-mock-
|
|
11
|
+
import { a as spyOn, s as spies } from './jest-mock-038a01b3.js';
|
|
12
12
|
import { r as rpc } from './rpc-8c7cc374.js';
|
|
13
13
|
import 'tty';
|
|
14
14
|
import 'local-pkg';
|
|
@@ -9218,13 +9218,15 @@ var __spreadValues = (a, b) => {
|
|
|
9218
9218
|
};
|
|
9219
9219
|
function resolveMockPath(mockPath, root, nmName) {
|
|
9220
9220
|
if (nmName) {
|
|
9221
|
-
const
|
|
9221
|
+
const mockDirname = dirname$2(nmName);
|
|
9222
|
+
const baseFilename = basename$2(nmName);
|
|
9223
|
+
const mockFolder = resolve(root, "__mocks__", mockDirname);
|
|
9222
9224
|
if (!existsSync(mockFolder))
|
|
9223
9225
|
return null;
|
|
9224
9226
|
const files = readdirSync(mockFolder);
|
|
9225
9227
|
for (const file of files) {
|
|
9226
9228
|
const [basename2] = file.split(".");
|
|
9227
|
-
if (basename2 ===
|
|
9229
|
+
if (basename2 === baseFilename)
|
|
9228
9230
|
return resolve(mockFolder, file).replace(root, "");
|
|
9229
9231
|
}
|
|
9230
9232
|
return null;
|
|
@@ -9306,6 +9308,11 @@ function createMocker(root, mockMap) {
|
|
|
9306
9308
|
s.mockClear();
|
|
9307
9309
|
});
|
|
9308
9310
|
}
|
|
9311
|
+
function resolveDependency(dep) {
|
|
9312
|
+
if (dep.startsWith("/node_modules/"))
|
|
9313
|
+
return mergeSlashes(`/@fs/${join$2(root, dep)}`);
|
|
9314
|
+
return dep;
|
|
9315
|
+
}
|
|
9309
9316
|
return {
|
|
9310
9317
|
mockPath,
|
|
9311
9318
|
unmockPath,
|
|
@@ -9313,12 +9320,14 @@ function createMocker(root, mockMap) {
|
|
|
9313
9320
|
getActualPath,
|
|
9314
9321
|
mockObject,
|
|
9315
9322
|
getSuiteFilepath,
|
|
9316
|
-
resolveMockPath
|
|
9323
|
+
resolveMockPath,
|
|
9324
|
+
resolveDependency
|
|
9317
9325
|
};
|
|
9318
9326
|
}
|
|
9319
9327
|
|
|
9320
9328
|
const defaultInline = [
|
|
9321
9329
|
"vitest/dist",
|
|
9330
|
+
/vitest-virtual-\w+\/dist/,
|
|
9322
9331
|
/virtual:/,
|
|
9323
9332
|
/\.ts$/,
|
|
9324
9333
|
/\/esm\/.*\.js$/,
|
|
@@ -9343,29 +9352,33 @@ const stubRequests = {
|
|
|
9343
9352
|
}
|
|
9344
9353
|
}
|
|
9345
9354
|
};
|
|
9355
|
+
function hasNestedDefault(target) {
|
|
9356
|
+
return "__esModule" in target && target.__esModule && "default" in target.default;
|
|
9357
|
+
}
|
|
9358
|
+
function proxyMethod(name, isNested) {
|
|
9359
|
+
return function(target, key, ...args) {
|
|
9360
|
+
const result = Reflect[name](target, key, ...args);
|
|
9361
|
+
if (isNested && key === "default" || !result)
|
|
9362
|
+
return Reflect[name](target.default, key, ...args);
|
|
9363
|
+
return result;
|
|
9364
|
+
};
|
|
9365
|
+
}
|
|
9346
9366
|
async function interpretedImport(path, interpretDefault) {
|
|
9347
9367
|
const mod = await import(path);
|
|
9348
9368
|
if (interpretDefault && "default" in mod) {
|
|
9369
|
+
const isNested = hasNestedDefault(mod);
|
|
9349
9370
|
return new Proxy(mod, {
|
|
9350
|
-
get(
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
return Reflect.set(target, key, value, receiver) || Reflect.set(target.default, key, value, receiver);
|
|
9355
|
-
},
|
|
9356
|
-
has(target, key) {
|
|
9357
|
-
return Reflect.has(target, key) || Reflect.has(target.default, key);
|
|
9358
|
-
},
|
|
9359
|
-
deleteProperty(target, key) {
|
|
9360
|
-
return Reflect.deleteProperty(target, key) || Reflect.deleteProperty(target.default, key);
|
|
9361
|
-
}
|
|
9371
|
+
get: proxyMethod("get", isNested),
|
|
9372
|
+
set: proxyMethod("set", isNested),
|
|
9373
|
+
has: proxyMethod("has", isNested),
|
|
9374
|
+
deleteProperty: proxyMethod("deleteProperty", isNested)
|
|
9362
9375
|
});
|
|
9363
9376
|
}
|
|
9364
9377
|
return mod;
|
|
9365
9378
|
}
|
|
9366
9379
|
async function executeInViteNode(options) {
|
|
9367
9380
|
const { moduleCache, root, files, fetch, mockMap } = options;
|
|
9368
|
-
const externalCache =
|
|
9381
|
+
const externalCache = new Map();
|
|
9369
9382
|
builtinModules.forEach((m) => externalCache.set(m, true));
|
|
9370
9383
|
const {
|
|
9371
9384
|
getActualPath,
|
|
@@ -9374,7 +9387,8 @@ async function executeInViteNode(options) {
|
|
|
9374
9387
|
mockPath,
|
|
9375
9388
|
clearMocks,
|
|
9376
9389
|
unmockPath,
|
|
9377
|
-
resolveMockPath
|
|
9390
|
+
resolveMockPath,
|
|
9391
|
+
resolveDependency
|
|
9378
9392
|
} = createMocker(root, mockMap);
|
|
9379
9393
|
const result = [];
|
|
9380
9394
|
for (const file of files)
|
|
@@ -9397,7 +9411,7 @@ async function executeInViteNode(options) {
|
|
|
9397
9411
|
var _a;
|
|
9398
9412
|
if (canMock) {
|
|
9399
9413
|
const mocks2 = mockMap[suite || ""] || {};
|
|
9400
|
-
const mock = mocks2[dep];
|
|
9414
|
+
const mock = mocks2[resolveDependency(dep)];
|
|
9401
9415
|
if (typeof mock === "function")
|
|
9402
9416
|
return callFunctionMock(dep, mock);
|
|
9403
9417
|
if (typeof mock === "string")
|
|
@@ -9554,7 +9568,7 @@ function patchWindowsImportPath(path) {
|
|
|
9554
9568
|
}
|
|
9555
9569
|
|
|
9556
9570
|
let _viteNode;
|
|
9557
|
-
const moduleCache =
|
|
9571
|
+
const moduleCache = new Map();
|
|
9558
9572
|
const mockMap = {};
|
|
9559
9573
|
async function startViteNode(ctx) {
|
|
9560
9574
|
if (_viteNode)
|