vitest 1.2.1 → 1.3.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.
- package/LICENSE.md +29 -0
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -1
- package/dist/chunks/{api-setup.omeaEsoT.js → api-setup.Xh60JpeM.js} +27 -64
- package/dist/chunks/{integrations-globals.9QpVy4UR.js → integrations-globals.FlQVNhQx.js} +6 -6
- package/dist/chunks/{runtime-runBaseTests.S8ZSFig3.js → runtime-runBaseTests.0UwIvo_U.js} +9 -9
- package/dist/cli-wrapper.js +1 -1
- package/dist/cli.js +1314 -69
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/coverage.d.ts +3 -3
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +3 -3
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +74 -78
- package/dist/index.js +7 -7
- package/dist/node.d.ts +3 -3
- package/dist/node.js +21 -21
- package/dist/{reporters-rzC174PQ.d.ts → reporters-QGe8gs4b.d.ts} +147 -56
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +20 -6
- package/dist/runners.d.ts +6 -6
- package/dist/runners.js +10 -10
- package/dist/{suite-MFRDkZcV.d.ts → suite-xGC-mxBC.d.ts} +1 -1
- package/dist/suite.d.ts +3 -3
- package/dist/suite.js +3 -3
- package/dist/vendor/{base.4sEqnqgY.js → base.RpormaJz.js} +2 -2
- package/dist/vendor/{base.QYERqzkH.js → base.knFzp7G3.js} +1 -1
- package/dist/vendor/{benchmark.IlKmJkUU.js → benchmark.eeqk2rd8.js} +1 -1
- package/dist/vendor/{node.p6h5JSuL.js → cli-api.RIYLcWhB.js} +1559 -3672
- package/dist/vendor/{constants.i1PoEnhr.js → constants.K-Wf1PUy.js} +3 -1
- package/dist/vendor/{execute.edwByI27.js → execute.aFSzc0Da.js} +26 -26
- package/dist/vendor/{index.cAUulNDf.js → index.8bPxjt7g.js} +6 -1
- package/dist/vendor/{index.kwCLJK4i.js → index.CKbXK54q.js} +7 -3
- package/dist/vendor/{environments.sU0TD7wX.js → index.GVFv9dZ0.js} +3 -0
- package/dist/vendor/index.QcWmThJv.js +4927 -0
- package/dist/vendor/{index.rJjbcrrp.js → index.ir9i0ywP.js} +1 -1
- package/dist/vendor/{index.vs_-lzuF.js → index.n-Ib4UWN.js} +4 -3
- package/dist/vendor/{rpc.w4v8oCkK.js → rpc.joBhAkyK.js} +10 -1
- package/dist/vendor/setup-common.NSpEdAQm.js +45 -0
- package/dist/vendor/{vi.Bw2UL9c9.js → vi.-Nr_x6dl.js} +8 -5
- package/dist/vendor/{vm.9N6CwTZh.js → vm.UmCkcXp-.js} +39 -12
- package/dist/worker.js +5 -10
- package/dist/workers/forks.js +3 -3
- package/dist/workers/runVmTests.js +13 -9
- package/dist/workers/threads.js +3 -3
- package/dist/workers/vmForks.js +4 -4
- package/dist/workers/vmThreads.js +4 -4
- package/dist/workers.d.ts +3 -3
- package/dist/workers.js +8 -8
- package/globals.d.ts +2 -0
- package/jsdom.d.ts +6 -0
- package/package.json +26 -22
- package/dist/vendor/reporters.cA9x-5v-.js +0 -2664
- package/dist/vendor/setup-common.4GIL70qB.js +0 -29
|
@@ -56,7 +56,9 @@ const globalApis = [
|
|
|
56
56
|
"beforeAll",
|
|
57
57
|
"afterAll",
|
|
58
58
|
"beforeEach",
|
|
59
|
-
"afterEach"
|
|
59
|
+
"afterEach",
|
|
60
|
+
"onTestFinished",
|
|
61
|
+
"onTestFailed"
|
|
60
62
|
];
|
|
61
63
|
|
|
62
64
|
export { API_PATH as A, CONFIG_NAMES as C, EXIT_CODE_RESTART as E, defaultBrowserPort as a, configFiles as c, defaultPort as d, extraInlineDeps as e, globalApis as g, workspacesFiles as w };
|
|
@@ -2,12 +2,12 @@ import vm from 'node:vm';
|
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import { ViteNodeRunner, DEFAULT_REQUEST_STUBS } from 'vite-node/client';
|
|
4
4
|
import { isNodeBuiltin, isInternalRequest, toFilePath, isPrimitive } from 'vite-node/utils';
|
|
5
|
-
import { resolve, isAbsolute, dirname, join, basename, extname,
|
|
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 '../path.js';
|
|
8
8
|
import { existsSync, readdirSync } from 'node:fs';
|
|
9
9
|
import { highlight, getType } from '@vitest/utils';
|
|
10
|
-
import {
|
|
10
|
+
import { g as getAllMockableProperties } from './base.knFzp7G3.js';
|
|
11
11
|
|
|
12
12
|
const spyModulePath = resolve(distDir, "spy.js");
|
|
13
13
|
class RefTracker {
|
|
@@ -118,7 +118,7 @@ class VitestMocker {
|
|
|
118
118
|
if (mock.type === "unmock")
|
|
119
119
|
this.unmockPath(fsPath);
|
|
120
120
|
if (mock.type === "mock")
|
|
121
|
-
this.mockPath(mock.id, fsPath, external, mock.factory
|
|
121
|
+
this.mockPath(mock.id, fsPath, external, mock.factory);
|
|
122
122
|
}));
|
|
123
123
|
VitestMocker.pendingIds = [];
|
|
124
124
|
}
|
|
@@ -295,19 +295,8 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
295
295
|
delete mock[id];
|
|
296
296
|
this.deleteCachedItem(id);
|
|
297
297
|
}
|
|
298
|
-
mockPath(originalId, path, external, factory
|
|
299
|
-
var _a, _b, _c, _d;
|
|
298
|
+
mockPath(originalId, path, external, factory) {
|
|
300
299
|
const id = this.normalizePath(path);
|
|
301
|
-
const { config } = this.executor.state;
|
|
302
|
-
const isIsolatedThreads = config.pool === "threads" && (((_b = (_a = config.poolOptions) == null ? void 0 : _a.threads) == null ? void 0 : _b.isolate) ?? true);
|
|
303
|
-
const isIsolatedForks = config.pool === "forks" && (((_d = (_c = config.poolOptions) == null ? void 0 : _c.forks) == null ? void 0 : _d.isolate) ?? true);
|
|
304
|
-
if (throwIfExists && (isIsolatedThreads || isIsolatedForks || config.pool === "vmThreads")) {
|
|
305
|
-
const cached = this.moduleCache.has(id) && this.moduleCache.getByModuleId(id);
|
|
306
|
-
if (cached && cached.importers.size)
|
|
307
|
-
throw new Error(`[vitest] Cannot mock "${originalId}" because it is already loaded by "${[...cached.importers.values()].map((i) => relative(this.root, i)).join('", "')}".
|
|
308
|
-
|
|
309
|
-
Please, remove the import if you want static imports to be mocked, or clear module cache by calling "vi.resetModules()" before mocking if you are going to import the file again. See: https://vitest.dev/guide/common-errors.html#cannot-mock-mocked-file-js-because-it-is-already-loaded`);
|
|
310
|
-
}
|
|
311
300
|
const suitefile = this.getSuiteFilepath();
|
|
312
301
|
const mocks = this.mockMap.get(suitefile) || {};
|
|
313
302
|
const resolves = this.resolveCache.get(suitefile) || {};
|
|
@@ -380,12 +369,10 @@ async function createVitestExecutor(options) {
|
|
|
380
369
|
}
|
|
381
370
|
const externalizeMap = /* @__PURE__ */ new Map();
|
|
382
371
|
const bareVitestRegexp = /^@?vitest(\/|$)/;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
throw new Error(`process.exit unexpectedly called with "${code}"`);
|
|
388
|
-
};
|
|
372
|
+
const dispose = [];
|
|
373
|
+
function listenForErrors(state) {
|
|
374
|
+
dispose.forEach((fn) => fn());
|
|
375
|
+
dispose.length = 0;
|
|
389
376
|
function catchError(err, type) {
|
|
390
377
|
var _a;
|
|
391
378
|
const worker = state();
|
|
@@ -396,11 +383,24 @@ async function startVitestExecutor(options) {
|
|
|
396
383
|
error.VITEST_TEST_PATH = relative(state().config.root, worker.filepath);
|
|
397
384
|
error.VITEST_AFTER_ENV_TEARDOWN = worker.environmentTeardownRun;
|
|
398
385
|
}
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
process.on("
|
|
386
|
+
state().rpc.onUnhandledError(error, type);
|
|
387
|
+
}
|
|
388
|
+
const uncaughtException = (e) => catchError(e, "Uncaught Exception");
|
|
389
|
+
const unhandledRejection = (e) => catchError(e, "Unhandled Rejection");
|
|
390
|
+
process.on("uncaughtException", uncaughtException);
|
|
391
|
+
process.on("unhandledRejection", unhandledRejection);
|
|
392
|
+
dispose.push(() => {
|
|
393
|
+
process.off("uncaughtException", uncaughtException);
|
|
394
|
+
process.off("unhandledRejection", unhandledRejection);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
async function startVitestExecutor(options) {
|
|
398
|
+
const state = () => globalThis.__vitest_worker__ || options.state;
|
|
399
|
+
const rpc = () => state().rpc;
|
|
400
|
+
process.exit = (code = process.exitCode || 0) => {
|
|
401
|
+
throw new Error(`process.exit unexpectedly called with "${code}"`);
|
|
402
|
+
};
|
|
403
|
+
listenForErrors(state);
|
|
404
404
|
const getTransformMode = () => {
|
|
405
405
|
return state().environment.transformMode ?? "ssr";
|
|
406
406
|
};
|
|
@@ -35,7 +35,12 @@ function createBirpc(functions, options) {
|
|
|
35
35
|
let timeoutId;
|
|
36
36
|
if (timeout >= 0) {
|
|
37
37
|
timeoutId = setTimeout(() => {
|
|
38
|
-
|
|
38
|
+
try {
|
|
39
|
+
options.onTimeoutError?.(method, args);
|
|
40
|
+
throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
39
44
|
rpcPromiseMap.delete(id);
|
|
40
45
|
}, timeout).unref?.();
|
|
41
46
|
}
|
|
@@ -3,9 +3,9 @@ import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment';
|
|
|
3
3
|
import { resolve } from 'pathe';
|
|
4
4
|
import { distDir } from '../path.js';
|
|
5
5
|
import { g as getWorkerState } from './global.CkGT_TMy.js';
|
|
6
|
-
import { r as rpc } from './rpc.
|
|
6
|
+
import { r as rpc } from './rpc.joBhAkyK.js';
|
|
7
7
|
import { t as takeCoverageInsideWorker } from './coverage.E7sG1b3r.js';
|
|
8
|
-
import { l as loadDiffConfig } from './setup-common.
|
|
8
|
+
import { l as loadDiffConfig, a as loadSnapshotSerializers } from './setup-common.NSpEdAQm.js';
|
|
9
9
|
|
|
10
10
|
function setupChaiConfig(config) {
|
|
11
11
|
Object.assign(chai.config, config);
|
|
@@ -47,7 +47,11 @@ async function resolveTestRunner(config, executor) {
|
|
|
47
47
|
testRunner.config = config;
|
|
48
48
|
if (!testRunner.importFile)
|
|
49
49
|
throw new Error('Runner must implement "importFile" method.');
|
|
50
|
-
|
|
50
|
+
const [diffOptions] = await Promise.all([
|
|
51
|
+
loadDiffConfig(config, executor),
|
|
52
|
+
loadSnapshotSerializers(config, executor)
|
|
53
|
+
]);
|
|
54
|
+
testRunner.config.diffOptions = diffOptions;
|
|
51
55
|
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
52
56
|
testRunner.onTaskUpdate = async (task) => {
|
|
53
57
|
const p = rpc().onTaskUpdate(task);
|
|
@@ -472,6 +472,7 @@ var jsdom = {
|
|
|
472
472
|
);
|
|
473
473
|
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
474
474
|
dom.window.Buffer = Buffer;
|
|
475
|
+
dom.window.jsdom = dom;
|
|
475
476
|
const globalNames = [
|
|
476
477
|
"structuredClone",
|
|
477
478
|
"fetch",
|
|
@@ -536,10 +537,12 @@ var jsdom = {
|
|
|
536
537
|
);
|
|
537
538
|
const { keys, originals } = populateGlobal(global, dom.window, { bindFunctions: true });
|
|
538
539
|
const clearWindowErrors = catchWindowErrors(global);
|
|
540
|
+
global.jsdom = dom;
|
|
539
541
|
return {
|
|
540
542
|
teardown(global2) {
|
|
541
543
|
clearWindowErrors();
|
|
542
544
|
dom.window.close();
|
|
545
|
+
delete global2.jsdom;
|
|
543
546
|
keys.forEach((key) => delete global2[key]);
|
|
544
547
|
originals.forEach((v, k) => global2[k] = v);
|
|
545
548
|
}
|