vitest 1.0.4 → 1.1.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/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/child.js +3 -4
- package/dist/chunks/{integrations-globals.8mr2ENps.js → integrations-globals.nOa2-o57.js} +2 -2
- package/dist/cli.js +12 -4
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +25 -24
- package/dist/config.js +1 -0
- package/dist/coverage.d.ts +1 -1
- package/dist/entry-vm.js +2 -2
- package/dist/entry.js +2 -2
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -2
- package/dist/execute.d.ts +10 -2
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/node.d.ts +2 -2
- package/dist/node.js +3 -3
- package/dist/{reporters-OH1c16Kq.d.ts → reporters-O4LBziQ_.d.ts} +34 -1
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +1 -1
- package/dist/runners.d.ts +3 -4
- package/dist/runners.js +19 -14
- package/dist/{suite-9ReVEt_h.d.ts → suite-dF4WyktM.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/vendor/{environments.v4R4vGad.js → environments.QJtma9XQ.js} +6 -7
- package/dist/vendor/{execute.1R_t2FPL.js → execute.vStuEOaI.js} +30 -8
- package/dist/vendor/{index.uQelX_YY.js → index.n6c6aC2Y.js} +1 -1
- package/dist/vendor/{loader.zIj6SiI8.js → loader.L9CYwKn1.js} +1 -1
- package/dist/vendor/{node.vEetZgP7.js → node.d5m7SYoI.js} +109 -87
- package/dist/vendor/{reporters.r0gTYN3L.js → reporters.oUR9etwS.js} +12 -5
- package/dist/vendor/{vi.pk4NToBt.js → vi.ciwVQ0al.js} +7 -3
- package/dist/vm.js +3 -4
- package/dist/worker.js +3 -4
- package/package.json +8 -8
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Console } from 'node:console';
|
|
2
|
-
import { importModule } from 'local-pkg';
|
|
3
2
|
|
|
4
3
|
const denyList = /* @__PURE__ */ new Set([
|
|
5
4
|
"GLOBAL",
|
|
@@ -440,7 +439,7 @@ var jsdom = {
|
|
|
440
439
|
JSDOM,
|
|
441
440
|
ResourceLoader,
|
|
442
441
|
VirtualConsole
|
|
443
|
-
} = await
|
|
442
|
+
} = await import('jsdom');
|
|
444
443
|
const {
|
|
445
444
|
html = "<!DOCTYPE html>",
|
|
446
445
|
userAgent,
|
|
@@ -503,7 +502,7 @@ var jsdom = {
|
|
|
503
502
|
JSDOM,
|
|
504
503
|
ResourceLoader,
|
|
505
504
|
VirtualConsole
|
|
506
|
-
} = await
|
|
505
|
+
} = await import('jsdom');
|
|
507
506
|
const {
|
|
508
507
|
html = "<!DOCTYPE html>",
|
|
509
508
|
userAgent,
|
|
@@ -549,7 +548,7 @@ var happy = {
|
|
|
549
548
|
name: "happy-dom",
|
|
550
549
|
transformMode: "web",
|
|
551
550
|
async setupVM({ happyDOM = {} }) {
|
|
552
|
-
const { Window } = await
|
|
551
|
+
const { Window } = await import('happy-dom');
|
|
553
552
|
const win = new Window({
|
|
554
553
|
...happyDOM,
|
|
555
554
|
console: console && globalThis.console ? globalThis.console : void 0,
|
|
@@ -572,7 +571,7 @@ var happy = {
|
|
|
572
571
|
};
|
|
573
572
|
},
|
|
574
573
|
async setup(global, { happyDOM = {} }) {
|
|
575
|
-
const { Window, GlobalWindow } = await
|
|
574
|
+
const { Window, GlobalWindow } = await import('happy-dom');
|
|
576
575
|
const win = new (GlobalWindow || Window)({
|
|
577
576
|
...happyDOM,
|
|
578
577
|
console: console && global.console ? global.console : void 0,
|
|
@@ -601,7 +600,7 @@ var edge = {
|
|
|
601
600
|
name: "edge-runtime",
|
|
602
601
|
transformMode: "ssr",
|
|
603
602
|
async setupVM() {
|
|
604
|
-
const { EdgeVM } = await
|
|
603
|
+
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
605
604
|
const vm = new EdgeVM({
|
|
606
605
|
extend: (context) => {
|
|
607
606
|
context.global = context;
|
|
@@ -618,7 +617,7 @@ var edge = {
|
|
|
618
617
|
};
|
|
619
618
|
},
|
|
620
619
|
async setup(global) {
|
|
621
|
-
const { EdgeVM } = await
|
|
620
|
+
const { EdgeVM } = await import('@edge-runtime/vm');
|
|
622
621
|
const vm = new EdgeVM({
|
|
623
622
|
extend: (context) => {
|
|
624
623
|
context.global = context;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
2
2
|
import vm from 'node:vm';
|
|
3
3
|
import { ModuleCacheMap, ViteNodeRunner, DEFAULT_REQUEST_STUBS } from 'vite-node/client';
|
|
4
|
-
import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData, isInternalRequest } from 'vite-node/utils';
|
|
4
|
+
import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData, isInternalRequest, toFilePath } from 'vite-node/utils';
|
|
5
5
|
import { resolve, isAbsolute, dirname, join, basename, extname, normalize, relative } from 'pathe';
|
|
6
6
|
import { processError } from '@vitest/utils/error';
|
|
7
7
|
import { distDir } from '../paths.js';
|
|
@@ -48,6 +48,9 @@ class VitestMocker {
|
|
|
48
48
|
resolveCache = /* @__PURE__ */ new Map();
|
|
49
49
|
primitives;
|
|
50
50
|
filterPublicKeys;
|
|
51
|
+
mockContext = {
|
|
52
|
+
callstack: null
|
|
53
|
+
};
|
|
51
54
|
get root() {
|
|
52
55
|
return this.executor.options.root;
|
|
53
56
|
}
|
|
@@ -151,10 +154,10 @@ class VitestMocker {
|
|
|
151
154
|
const c = getColors();
|
|
152
155
|
throw this.createError(
|
|
153
156
|
`[vitest] No "${String(prop)}" export is defined on the "${mockpath}" mock. Did you forget to return it from "vi.mock"?
|
|
154
|
-
If you need to partially mock a module, you can use "
|
|
157
|
+
If you need to partially mock a module, you can use "importOriginal" helper inside:
|
|
155
158
|
|
|
156
|
-
${c.green(`vi.mock("${mockpath}", async () => {
|
|
157
|
-
const actual = await
|
|
159
|
+
${c.green(`vi.mock("${mockpath}", async (importOriginal) => {
|
|
160
|
+
const actual = await importOriginal()
|
|
158
161
|
return {
|
|
159
162
|
...actual,
|
|
160
163
|
// your mocked methods
|
|
@@ -169,6 +172,9 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
169
172
|
this.moduleCache.set(dep, { exports: moduleExports });
|
|
170
173
|
return moduleExports;
|
|
171
174
|
}
|
|
175
|
+
getMockContext() {
|
|
176
|
+
return this.mockContext;
|
|
177
|
+
}
|
|
172
178
|
getMockPath(dep) {
|
|
173
179
|
return `mock:${dep}`;
|
|
174
180
|
}
|
|
@@ -303,9 +309,9 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
303
309
|
this.resolveCache.set(suitefile, resolves);
|
|
304
310
|
this.deleteCachedItem(id);
|
|
305
311
|
}
|
|
306
|
-
async importActual(rawId,
|
|
307
|
-
const { id, fsPath } = await this.resolvePath(rawId,
|
|
308
|
-
const result = await this.executor.cachedRequest(id, fsPath, [
|
|
312
|
+
async importActual(rawId, importer, callstack) {
|
|
313
|
+
const { id, fsPath } = await this.resolvePath(rawId, importer);
|
|
314
|
+
const result = await this.executor.cachedRequest(id, fsPath, callstack || [importer]);
|
|
309
315
|
return result;
|
|
310
316
|
}
|
|
311
317
|
async importMock(rawId, importee) {
|
|
@@ -339,8 +345,10 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
339
345
|
if (typeof mock === "function" && !callstack.includes(mockPath) && !callstack.includes(url)) {
|
|
340
346
|
try {
|
|
341
347
|
callstack.push(mockPath);
|
|
348
|
+
this.mockContext.callstack = callstack;
|
|
342
349
|
return await this.callFunctionMock(mockPath, mock);
|
|
343
350
|
} finally {
|
|
351
|
+
this.mockContext.callstack = null;
|
|
344
352
|
const indexMock = callstack.indexOf(mockPath);
|
|
345
353
|
callstack.splice(indexMock, 1);
|
|
346
354
|
}
|
|
@@ -998,6 +1006,7 @@ const packageCache = /* @__PURE__ */ new Map();
|
|
|
998
1006
|
const moduleCache = new ModuleCacheMap();
|
|
999
1007
|
const mockMap = /* @__PURE__ */ new Map();
|
|
1000
1008
|
const fileMap = new FileMap();
|
|
1009
|
+
const externalizeMap = /* @__PURE__ */ new Map();
|
|
1001
1010
|
async function startViteNode(options) {
|
|
1002
1011
|
if (_viteNode)
|
|
1003
1012
|
return _viteNode;
|
|
@@ -1006,6 +1015,7 @@ async function startViteNode(options) {
|
|
|
1006
1015
|
_viteNode = { run, executor };
|
|
1007
1016
|
return _viteNode;
|
|
1008
1017
|
}
|
|
1018
|
+
const bareVitestRegexp = /^@?vitest(\/|$)/;
|
|
1009
1019
|
async function startVitestExecutor(options) {
|
|
1010
1020
|
const state = () => globalThis.__vitest_worker__ || options.state;
|
|
1011
1021
|
const rpc = () => state().rpc;
|
|
@@ -1034,7 +1044,19 @@ async function startVitestExecutor(options) {
|
|
|
1034
1044
|
return state().environment.transformMode ?? "ssr";
|
|
1035
1045
|
};
|
|
1036
1046
|
return await createVitestExecutor({
|
|
1037
|
-
fetchModule(id) {
|
|
1047
|
+
async fetchModule(id) {
|
|
1048
|
+
if (externalizeMap.has(id))
|
|
1049
|
+
return { externalize: externalizeMap.get(id) };
|
|
1050
|
+
if (id.includes(distDir)) {
|
|
1051
|
+
const { path } = toFilePath(id, state().config.root);
|
|
1052
|
+
const externalize = pathToFileURL(path).toString();
|
|
1053
|
+
externalizeMap.set(id, externalize);
|
|
1054
|
+
return { externalize };
|
|
1055
|
+
}
|
|
1056
|
+
if (bareVitestRegexp.test(id)) {
|
|
1057
|
+
externalizeMap.set(id, id);
|
|
1058
|
+
return { externalize: id };
|
|
1059
|
+
}
|
|
1038
1060
|
return rpc().fetch(id, getTransformMode());
|
|
1039
1061
|
},
|
|
1040
1062
|
resolveId(id, importer) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, suite, test } from '@vitest/runner';
|
|
2
2
|
import { b as bench } from './benchmark.WVm6DARl.js';
|
|
3
3
|
import { i as isFirstRun, r as runOnce } from './run-once.X3E7xx3F.js';
|
|
4
|
-
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.
|
|
4
|
+
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.ciwVQ0al.js';
|
|
5
5
|
import { g as getWorkerState } from './global.L7JRz1qU.js';
|
|
6
6
|
import * as chai from 'chai';
|
|
7
7
|
import { assert, should } from 'chai';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve, normalize } from 'pathe';
|
|
2
2
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
3
|
-
import { e as environments } from './environments.
|
|
3
|
+
import { e as environments } from './environments.QJtma9XQ.js';
|
|
4
4
|
|
|
5
5
|
function isBuiltinEnvironment(env) {
|
|
6
6
|
return env in environments;
|