vitest 1.6.0 → 2.0.0-beta.10
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 +173 -1
- package/dist/browser.d.ts +22 -2
- package/dist/browser.js +6 -4
- package/dist/chunks/{environments-node.vcoXCoKs.js → environments-node.39w4gmlF.js} +2 -2
- package/dist/chunks/{install-pkg.LE8oaA1t.js → install-pkg.DNUmWFkO.js} +2 -2
- package/dist/chunks/integrations-globals.C6Ah-pUW.js +31 -0
- package/dist/chunks/{runtime-console.EO5ha7qv.js → runtime-console.DiVMr5d4.js} +62 -32
- package/dist/chunks/{runtime-runBaseTests.oAvMKtQC.js → runtime-runBaseTests.Cukyr5-I.js} +18 -18
- package/dist/cli.js +3 -3
- package/dist/config.cjs +4 -5
- package/dist/config.d.ts +2 -2
- package/dist/config.js +4 -5
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +34 -8
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +3 -2
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +777 -65
- package/dist/index.js +12 -12
- package/dist/node.d.ts +7 -7
- package/dist/node.js +24 -23
- package/dist/{reporters-yx5ZTtEV.d.ts → reporters-CYVC6LOl.d.ts} +439 -219
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +11 -12
- package/dist/runners.d.ts +4 -2
- package/dist/runners.js +25 -18
- package/dist/snapshot.js +3 -3
- package/dist/{suite-IbNSsUWN.d.ts → suite-Dpu9EC_k.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +4 -4
- package/dist/vendor/{base.Ybri3C14.js → base.Dln9yllP.js} +3 -3
- package/dist/vendor/{base.5NT-gWu5.js → base._gnK9Slw.js} +1 -2
- package/dist/vendor/{benchmark.yGkUTKnC.js → benchmark.BNLebNi5.js} +1 -1
- package/dist/vendor/{cac.EdDItJD-.js → cac.CtYFkoSJ.js} +66 -25
- package/dist/vendor/{cli-api.E07AF1Yq.js → cli-api.CUtJc4r3.js} +11851 -7276
- package/dist/vendor/{constants.5J7I254_.js → constants.TCjCaw2D.js} +4 -3
- package/dist/vendor/{execute.fL3szUAI.js → execute.BHj6OMh4.js} +4 -4
- package/dist/vendor/{index.DpVgvm2P.js → index.B5SKBLvV.js} +5 -5
- package/dist/vendor/{index.Q04MCqDO.js → index.BOMEjpjj.js} +680 -160
- package/dist/vendor/{index.8bPxjt7g.js → index.BpSiYbpB.js} +5 -1
- package/dist/vendor/{index.xL8XjTLv.js → index.CThipSqB.js} +2538 -2525
- package/dist/vendor/{index.dI9lHwVn.js → index.D3hs2WiI.js} +8 -6
- package/dist/vendor/{index.SMVOaj7F.js → index._7XLd8Kd.js} +2 -2
- package/dist/vendor/{index.GVFv9dZ0.js → index.kpsSqFiz.js} +2 -1
- package/dist/vendor/{rpc.joBhAkyK.js → rpc.DRDE9Pu1.js} +2 -2
- package/dist/vendor/{run-once.Olz_Zkd8.js → run-once.DLomgGUH.js} +1 -1
- package/dist/vendor/{setup-common.8nJLd4ay.js → setup-common.DAu7t7mY.js} +2 -2
- package/dist/vendor/spy.Cf_4R5Oe.js +22 -0
- package/dist/vendor/{tasks.IknbGB2n.js → tasks.WC7M-K-v.js} +4 -1
- package/dist/vendor/{utils.dEtNIEgr.js → utils.YuQ3LT2a.js} +2 -2
- package/dist/vendor/{vi.YFlodzP_.js → vi.hATFzZbX.js} +124 -56
- package/dist/vendor/{vm.QEE48c0T.js → vm.Ow-X2mkS.js} +47 -59
- package/dist/worker.js +6 -6
- package/dist/workers/forks.js +5 -5
- package/dist/workers/runVmTests.js +17 -17
- package/dist/workers/threads.js +5 -5
- package/dist/workers/vmForks.js +8 -8
- package/dist/workers/vmThreads.js +8 -8
- package/dist/workers.d.ts +1 -1
- package/dist/workers.js +13 -13
- package/package.json +35 -35
- package/suppress-warnings.cjs +2 -1
- package/vitest.mjs +1 -1
- package/dist/chunks/integrations-globals.kw4co3rx.js +0 -31
- package/dist/cli-wrapper.js +0 -119
- /package/dist/chunks/{node-git.Hw101KjS.js → node-git.CCI8evVZ.js} +0 -0
- /package/dist/vendor/{_commonjsHelpers.jjO7Zipk.js → _commonjsHelpers.BFTU3MAI.js} +0 -0
- /package/dist/vendor/{coverage.E7sG1b3r.js → coverage.ChSqD-qS.js} +0 -0
- /package/dist/vendor/{date.Ns1pGd_X.js → date.BKM1wewY.js} +0 -0
- /package/dist/vendor/{env.AtSIuHFg.js → env.bmJgw1qP.js} +0 -0
- /package/dist/vendor/{global.CkGT_TMy.js → global.7bFbnyXl.js} +0 -0
- /package/dist/vendor/{inspector.IgLX3ur5.js → inspector.hPQncR7V.js} +0 -0
- /package/dist/vendor/{utils.0uYuCbzo.js → utils.CUjzkRH7.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
2
|
-
import { b as bench } from './benchmark.
|
|
3
|
-
import { i as isFirstRun, a as runOnce } from './run-once.
|
|
4
|
-
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.
|
|
5
|
-
import { g as getWorkerState } from './global.
|
|
2
|
+
import { b as bench } from './benchmark.BNLebNi5.js';
|
|
3
|
+
import { i as isFirstRun, a as runOnce } from './run-once.DLomgGUH.js';
|
|
4
|
+
import { c as createExpect, a as globalExpect, v as vi, b as vitest } from './vi.hATFzZbX.js';
|
|
5
|
+
import { g as getWorkerState } from './global.7bFbnyXl.js';
|
|
6
6
|
import * as chai from 'chai';
|
|
7
7
|
import { assert, should } from 'chai';
|
|
8
8
|
|
|
@@ -61,7 +61,7 @@ var dist = {};
|
|
|
61
61
|
'branded',
|
|
62
62
|
];
|
|
63
63
|
const obj = {
|
|
64
|
-
/* eslint-disable
|
|
64
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
65
65
|
toBeAny: fn,
|
|
66
66
|
toBeUnknown: fn,
|
|
67
67
|
toBeNever: fn,
|
|
@@ -80,9 +80,11 @@ var dist = {};
|
|
|
80
80
|
toEqualTypeOf: fn,
|
|
81
81
|
toBeCallableWith: fn,
|
|
82
82
|
toBeConstructibleWith: fn,
|
|
83
|
-
/* eslint-enable
|
|
83
|
+
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
|
|
84
84
|
extract: exports.expectTypeOf,
|
|
85
85
|
exclude: exports.expectTypeOf,
|
|
86
|
+
pick: exports.expectTypeOf,
|
|
87
|
+
omit: exports.expectTypeOf,
|
|
86
88
|
toHaveProperty: exports.expectTypeOf,
|
|
87
89
|
parameter: exports.expectTypeOf,
|
|
88
90
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { relative } from 'pathe';
|
|
2
2
|
import '@vitest/runner/utils';
|
|
3
3
|
import '@vitest/utils';
|
|
4
|
-
import { g as getWorkerState } from './global.
|
|
5
|
-
import './env.
|
|
4
|
+
import { g as getWorkerState } from './global.7bFbnyXl.js';
|
|
5
|
+
import './env.bmJgw1qP.js';
|
|
6
6
|
|
|
7
7
|
function getRunMode() {
|
|
8
8
|
return getWorkerState().config.mode;
|
|
@@ -486,8 +486,9 @@ var jsdom = {
|
|
|
486
486
|
];
|
|
487
487
|
for (const name of globalNames) {
|
|
488
488
|
const value = globalThis[name];
|
|
489
|
-
if (typeof value !== "undefined" && typeof dom.window[name] === "undefined")
|
|
489
|
+
if (typeof value !== "undefined" && typeof dom.window[name] === "undefined") {
|
|
490
490
|
dom.window[name] = value;
|
|
491
|
+
}
|
|
491
492
|
}
|
|
492
493
|
return {
|
|
493
494
|
getVmContext() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSafeTimers } from '@vitest/utils';
|
|
2
|
-
import { c as createBirpc } from './index.
|
|
3
|
-
import { g as getWorkerState } from './global.
|
|
2
|
+
import { c as createBirpc } from './index.BpSiYbpB.js';
|
|
3
|
+
import { g as getWorkerState } from './global.7bFbnyXl.js';
|
|
4
4
|
|
|
5
5
|
const { get } = Reflect;
|
|
6
6
|
function withSafeTimers(fn) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setSafeTimers } from '@vitest/utils';
|
|
2
2
|
import { addSerializer } from '@vitest/snapshot';
|
|
3
|
-
import { r as resetRunOnceCounter } from './run-once.
|
|
3
|
+
import { r as resetRunOnceCounter } from './run-once.DLomgGUH.js';
|
|
4
4
|
|
|
5
5
|
let globalSetup = false;
|
|
6
6
|
async function setupCommonEnv(config) {
|
|
@@ -12,7 +12,7 @@ async function setupCommonEnv(config) {
|
|
|
12
12
|
globalSetup = true;
|
|
13
13
|
setSafeTimers();
|
|
14
14
|
if (config.globals)
|
|
15
|
-
(await import('../chunks/integrations-globals.
|
|
15
|
+
(await import('../chunks/integrations-globals.C6Ah-pUW.js')).registerApiGlobally();
|
|
16
16
|
}
|
|
17
17
|
function setupDefines(defines) {
|
|
18
18
|
for (const key in defines)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as spy$1 from '@vitest/spy';
|
|
2
|
+
|
|
3
|
+
function _mergeNamespaces(n, m) {
|
|
4
|
+
m.forEach(function (e) {
|
|
5
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
6
|
+
if (k !== 'default' && !(k in n)) {
|
|
7
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
8
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return e[k]; }
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
return Object.freeze(n);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var spy = /*#__PURE__*/_mergeNamespaces({
|
|
19
|
+
__proto__: null
|
|
20
|
+
}, [spy$1]);
|
|
21
|
+
|
|
22
|
+
export { spy as s };
|
|
@@ -10,5 +10,8 @@ function hasFailedSnapshot(suite) {
|
|
|
10
10
|
function getFullName(task, separator = " > ") {
|
|
11
11
|
return getNames(task).join(separator);
|
|
12
12
|
}
|
|
13
|
+
function getTestName(task, separator = " > ") {
|
|
14
|
+
return getNames(task).slice(1).join(separator);
|
|
15
|
+
}
|
|
13
16
|
|
|
14
|
-
export { getFullName as g, hasFailedSnapshot as h };
|
|
17
|
+
export { getFullName as a, getTestName as g, hasFailedSnapshot as h };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isAbsolute, relative, dirname, basename } from 'pathe';
|
|
2
2
|
import c from 'picocolors';
|
|
3
|
-
import { a as slash } from './base.
|
|
3
|
+
import { a as slash } from './base._gnK9Slw.js';
|
|
4
4
|
|
|
5
5
|
const F_RIGHT = "\u2192";
|
|
6
6
|
const F_DOWN = "\u2193";
|
|
@@ -214,4 +214,4 @@ var utils = /*#__PURE__*/Object.freeze({
|
|
|
214
214
|
spinnerMap: spinnerMap
|
|
215
215
|
});
|
|
216
216
|
|
|
217
|
-
export { F_RIGHT as F,
|
|
217
|
+
export { F_RIGHT as F, F_POINTER as a, getStateString as b, formatTimeString as c, countTestErrors as d, divider as e, formatProjectName as f, getStateSymbol as g, getCols as h, getHookStateSymbol as i, pointer as p, renderSnapshotSummary as r, stripAnsi as s, utils as u };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import * as chai$1 from 'chai';
|
|
2
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.
|
|
3
|
-
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT
|
|
2
|
+
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
3
|
+
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters } from '@vitest/expect';
|
|
4
4
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
5
5
|
import { getNames } from '@vitest/runner/utils';
|
|
6
6
|
import '@vitest/utils/error';
|
|
7
7
|
import { getCurrentTest } from '@vitest/runner';
|
|
8
|
-
import { g as
|
|
9
|
-
import { g as getWorkerState, a as getCurrentEnvironment } from './global.
|
|
8
|
+
import { g as getTestName } from './tasks.WC7M-K-v.js';
|
|
9
|
+
import { g as getWorkerState, a as getCurrentEnvironment } from './global.7bFbnyXl.js';
|
|
10
10
|
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
11
|
+
import 'pathe';
|
|
12
|
+
import './env.bmJgw1qP.js';
|
|
11
13
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
12
|
-
import { i as isChildProcess } from './base.
|
|
13
|
-
import { R as RealDate, r as resetDate, m as mockDate } from './date.
|
|
14
|
+
import { i as isChildProcess } from './base._gnK9Slw.js';
|
|
15
|
+
import { R as RealDate, r as resetDate, m as mockDate } from './date.BKM1wewY.js';
|
|
14
16
|
import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
|
|
15
17
|
|
|
16
18
|
function resetModules(modules, resetMocks = false) {
|
|
@@ -142,32 +144,6 @@ var chaiSubset = {exports: {}};
|
|
|
142
144
|
var chaiSubsetExports = chaiSubset.exports;
|
|
143
145
|
var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
|
|
144
146
|
|
|
145
|
-
const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
|
146
|
-
const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
|
147
|
-
const GLOBAL_EXPECT = Symbol.for("expect-global");
|
|
148
|
-
const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
|
|
149
|
-
|
|
150
|
-
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
|
151
|
-
const globalState = /* @__PURE__ */ new WeakMap();
|
|
152
|
-
const matchers = /* @__PURE__ */ Object.create(null);
|
|
153
|
-
const customEqualityTesters = [];
|
|
154
|
-
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
|
155
|
-
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
|
156
|
-
get: () => globalState
|
|
157
|
-
});
|
|
158
|
-
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
|
|
159
|
-
configurable: true,
|
|
160
|
-
get: () => ({
|
|
161
|
-
state: globalState.get(globalThis[GLOBAL_EXPECT]),
|
|
162
|
-
matchers,
|
|
163
|
-
customEqualityTesters
|
|
164
|
-
})
|
|
165
|
-
});
|
|
166
|
-
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
|
167
|
-
get: () => assymetricMatchers
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
147
|
function recordAsyncExpect(test, promise) {
|
|
172
148
|
if (test && promise instanceof Promise) {
|
|
173
149
|
promise = promise.finally(() => {
|
|
@@ -208,11 +184,10 @@ function getError(expected, promise) {
|
|
|
208
184
|
}
|
|
209
185
|
const SnapshotPlugin = (chai, utils) => {
|
|
210
186
|
const getTestNames = (test) => {
|
|
211
|
-
var _a;
|
|
212
187
|
if (!test)
|
|
213
188
|
return {};
|
|
214
189
|
return {
|
|
215
|
-
filepath:
|
|
190
|
+
filepath: test.file.filepath,
|
|
216
191
|
name: getNames(test).slice(1).join(" > ")
|
|
217
192
|
};
|
|
218
193
|
};
|
|
@@ -360,11 +335,85 @@ chai$1.use(Subset);
|
|
|
360
335
|
chai$1.use(SnapshotPlugin);
|
|
361
336
|
chai$1.use(JestAsymmetricMatchers);
|
|
362
337
|
|
|
338
|
+
const unsupported = [
|
|
339
|
+
// .poll is meant to retry matchers until they succeed, and
|
|
340
|
+
// snapshots will always succeed as long as the poll method doesn't thow an error
|
|
341
|
+
// in this case using the `vi.waitFor` method is more appropriate
|
|
342
|
+
"matchSnapshot",
|
|
343
|
+
"toMatchSnapshot",
|
|
344
|
+
"toMatchInlineSnapshot",
|
|
345
|
+
"toThrowErrorMatchingSnapshot",
|
|
346
|
+
"toThrowErrorMatchingInlineSnapshot",
|
|
347
|
+
// toThrow will never succeed because we call the poll callback until it doesn't throw
|
|
348
|
+
"throws",
|
|
349
|
+
"Throw",
|
|
350
|
+
"throw",
|
|
351
|
+
"toThrow",
|
|
352
|
+
"toThrowError"
|
|
353
|
+
// these are not supported because you can call them without `.poll`,
|
|
354
|
+
// we throw an error inside the rejects/resolves methods to prevent this
|
|
355
|
+
// rejects,
|
|
356
|
+
// resolves
|
|
357
|
+
];
|
|
358
|
+
function createExpectPoll(expect) {
|
|
359
|
+
return function poll(fn, options = {}) {
|
|
360
|
+
var _a;
|
|
361
|
+
const state = getWorkerState();
|
|
362
|
+
const defaults = ((_a = state.config.expect) == null ? void 0 : _a.poll) ?? {};
|
|
363
|
+
const {
|
|
364
|
+
interval = defaults.interval ?? 50,
|
|
365
|
+
timeout = defaults.timeout ?? 1e3,
|
|
366
|
+
message
|
|
367
|
+
} = options;
|
|
368
|
+
const assertion = expect(null, message).withContext({ poll: true });
|
|
369
|
+
const proxy = new Proxy(assertion, {
|
|
370
|
+
get(target, key, receiver) {
|
|
371
|
+
const result = Reflect.get(target, key, receiver);
|
|
372
|
+
if (typeof result !== "function")
|
|
373
|
+
return result instanceof chai$1.Assertion ? proxy : result;
|
|
374
|
+
if (key === "assert")
|
|
375
|
+
return result;
|
|
376
|
+
if (typeof key === "string" && unsupported.includes(key))
|
|
377
|
+
throw new SyntaxError(`expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`);
|
|
378
|
+
return function(...args) {
|
|
379
|
+
const STACK_TRACE_ERROR = new Error("STACK_TRACE_ERROR");
|
|
380
|
+
return new Promise((resolve, reject) => {
|
|
381
|
+
let intervalId;
|
|
382
|
+
let lastError;
|
|
383
|
+
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
384
|
+
const timeoutId = setTimeout(() => {
|
|
385
|
+
clearTimeout(intervalId);
|
|
386
|
+
reject(copyStackTrace$1(new Error(`Matcher did not succeed in ${timeout}ms`, { cause: lastError }), STACK_TRACE_ERROR));
|
|
387
|
+
}, timeout);
|
|
388
|
+
const check = async () => {
|
|
389
|
+
try {
|
|
390
|
+
chai$1.util.flag(this, "object", await fn());
|
|
391
|
+
resolve(await result.call(this, ...args));
|
|
392
|
+
clearTimeout(intervalId);
|
|
393
|
+
clearTimeout(timeoutId);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
lastError = err;
|
|
396
|
+
intervalId = setTimeout(check, interval);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
check();
|
|
400
|
+
});
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
return proxy;
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
function copyStackTrace$1(target, source) {
|
|
408
|
+
if (source.stack !== void 0)
|
|
409
|
+
target.stack = source.stack.replace(source.message, target.message);
|
|
410
|
+
return target;
|
|
411
|
+
}
|
|
412
|
+
|
|
363
413
|
function createExpect(test) {
|
|
364
|
-
var _a;
|
|
365
414
|
const expect = (value, message) => {
|
|
366
415
|
const { assertionCalls } = getState(expect);
|
|
367
|
-
setState({ assertionCalls: assertionCalls + 1
|
|
416
|
+
setState({ assertionCalls: assertionCalls + 1 }, expect);
|
|
368
417
|
const assert2 = chai$1.expect(value, message);
|
|
369
418
|
const _test = test || getCurrentTest();
|
|
370
419
|
if (_test)
|
|
@@ -373,10 +422,11 @@ function createExpect(test) {
|
|
|
373
422
|
return assert2;
|
|
374
423
|
};
|
|
375
424
|
Object.assign(expect, chai$1.expect);
|
|
376
|
-
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT
|
|
425
|
+
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
|
|
377
426
|
expect.getState = () => getState(expect);
|
|
378
427
|
expect.setState = (state) => setState(state, expect);
|
|
379
|
-
const globalState = getState(globalThis[GLOBAL_EXPECT
|
|
428
|
+
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
|
|
429
|
+
const testPath = getTestFile(test);
|
|
380
430
|
setState({
|
|
381
431
|
// this should also add "snapshotState" that is added conditionally
|
|
382
432
|
...globalState,
|
|
@@ -386,18 +436,15 @@ function createExpect(test) {
|
|
|
386
436
|
expectedAssertionsNumber: null,
|
|
387
437
|
expectedAssertionsNumberErrorGen: null,
|
|
388
438
|
environment: getCurrentEnvironment(),
|
|
389
|
-
testPath
|
|
390
|
-
currentTestName: test ?
|
|
439
|
+
testPath,
|
|
440
|
+
currentTestName: test ? getTestName(test) : globalState.currentTestName
|
|
391
441
|
}, expect);
|
|
392
442
|
expect.extend = (matchers) => chai$1.expect.extend(expect, matchers);
|
|
393
443
|
expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
|
|
394
444
|
expect.soft = (...args) => {
|
|
395
|
-
|
|
396
|
-
expect.setState({
|
|
397
|
-
soft: true
|
|
398
|
-
});
|
|
399
|
-
return assert2;
|
|
445
|
+
return expect(...args).withContext({ soft: true });
|
|
400
446
|
};
|
|
447
|
+
expect.poll = createExpectPoll(expect);
|
|
401
448
|
expect.unreachable = (message) => {
|
|
402
449
|
chai$1.assert.fail(`expected${message ? ` "${message}" ` : " "}not to be reached`);
|
|
403
450
|
};
|
|
@@ -423,8 +470,14 @@ function createExpect(test) {
|
|
|
423
470
|
chai$1.util.addMethod(expect, "hasAssertions", hasAssertions);
|
|
424
471
|
return expect;
|
|
425
472
|
}
|
|
473
|
+
function getTestFile(test) {
|
|
474
|
+
if (test)
|
|
475
|
+
return test.file.filepath;
|
|
476
|
+
const state = getWorkerState();
|
|
477
|
+
return state.filepath;
|
|
478
|
+
}
|
|
426
479
|
const globalExpect = createExpect();
|
|
427
|
-
Object.defineProperty(globalThis, GLOBAL_EXPECT
|
|
480
|
+
Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
428
481
|
value: globalExpect,
|
|
429
482
|
writable: true,
|
|
430
483
|
configurable: true
|
|
@@ -3223,6 +3276,8 @@ function waitFor(callback, options = {}) {
|
|
|
3223
3276
|
resolve(result);
|
|
3224
3277
|
};
|
|
3225
3278
|
const handleTimeout = () => {
|
|
3279
|
+
if (intervalId)
|
|
3280
|
+
clearInterval(intervalId);
|
|
3226
3281
|
let error = lastError;
|
|
3227
3282
|
if (!error)
|
|
3228
3283
|
error = copyStackTrace(new Error("Timed out in waitFor!"), STACK_TRACE_ERROR);
|
|
@@ -3271,6 +3326,8 @@ function waitUntil(callback, options = {}) {
|
|
|
3271
3326
|
let timeoutId;
|
|
3272
3327
|
let intervalId;
|
|
3273
3328
|
const onReject = (error) => {
|
|
3329
|
+
if (intervalId)
|
|
3330
|
+
clearInterval(intervalId);
|
|
3274
3331
|
if (!error)
|
|
3275
3332
|
error = copyStackTrace(new Error("Timed out in waitUntil!"), STACK_TRACE_ERROR);
|
|
3276
3333
|
reject(error);
|
|
@@ -3338,10 +3395,13 @@ function createVitest() {
|
|
|
3338
3395
|
const _stubsGlobal = /* @__PURE__ */ new Map();
|
|
3339
3396
|
const _stubsEnv = /* @__PURE__ */ new Map();
|
|
3340
3397
|
const _envBooleans = ["PROD", "DEV", "SSR"];
|
|
3341
|
-
const getImporter = () => {
|
|
3342
|
-
const stackTrace = createSimpleStackTrace({ stackTraceLimit:
|
|
3343
|
-
const
|
|
3344
|
-
const
|
|
3398
|
+
const getImporter = (name) => {
|
|
3399
|
+
const stackTrace = createSimpleStackTrace({ stackTraceLimit: 5 });
|
|
3400
|
+
const stackArray = stackTrace.split("\n");
|
|
3401
|
+
const importerStackIndex = stackArray.findIndex((stack2) => {
|
|
3402
|
+
return stack2.includes(` at Object.${name}`) || stack2.includes(`${name}@`);
|
|
3403
|
+
});
|
|
3404
|
+
const stack = parseSingleStack(stackArray[importerStackIndex + 1]);
|
|
3345
3405
|
return (stack == null ? void 0 : stack.file) || "";
|
|
3346
3406
|
};
|
|
3347
3407
|
const utils = {
|
|
@@ -3434,7 +3494,9 @@ function createVitest() {
|
|
|
3434
3494
|
return factory();
|
|
3435
3495
|
},
|
|
3436
3496
|
mock(path, factory) {
|
|
3437
|
-
|
|
3497
|
+
if (typeof path !== "string")
|
|
3498
|
+
throw new Error(`vi.mock() expects a string path, but received a ${typeof path}`);
|
|
3499
|
+
const importer = getImporter("mock");
|
|
3438
3500
|
_mocker.queueMock(
|
|
3439
3501
|
path,
|
|
3440
3502
|
importer,
|
|
@@ -3443,10 +3505,14 @@ function createVitest() {
|
|
|
3443
3505
|
);
|
|
3444
3506
|
},
|
|
3445
3507
|
unmock(path) {
|
|
3446
|
-
|
|
3508
|
+
if (typeof path !== "string")
|
|
3509
|
+
throw new Error(`vi.unmock() expects a string path, but received a ${typeof path}`);
|
|
3510
|
+
_mocker.queueUnmock(path, getImporter("unmock"));
|
|
3447
3511
|
},
|
|
3448
3512
|
doMock(path, factory) {
|
|
3449
|
-
|
|
3513
|
+
if (typeof path !== "string")
|
|
3514
|
+
throw new Error(`vi.doMock() expects a string path, but received a ${typeof path}`);
|
|
3515
|
+
const importer = getImporter("doMock");
|
|
3450
3516
|
_mocker.queueMock(
|
|
3451
3517
|
path,
|
|
3452
3518
|
importer,
|
|
@@ -3455,17 +3521,19 @@ function createVitest() {
|
|
|
3455
3521
|
);
|
|
3456
3522
|
},
|
|
3457
3523
|
doUnmock(path) {
|
|
3458
|
-
|
|
3524
|
+
if (typeof path !== "string")
|
|
3525
|
+
throw new Error(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
|
|
3526
|
+
_mocker.queueUnmock(path, getImporter("doUnmock"));
|
|
3459
3527
|
},
|
|
3460
3528
|
async importActual(path) {
|
|
3461
3529
|
return _mocker.importActual(
|
|
3462
3530
|
path,
|
|
3463
|
-
getImporter(),
|
|
3531
|
+
getImporter("importActual"),
|
|
3464
3532
|
_mocker.getMockContext().callstack
|
|
3465
3533
|
);
|
|
3466
3534
|
},
|
|
3467
3535
|
async importMock(path) {
|
|
3468
|
-
return _mocker.importMock(path, getImporter());
|
|
3536
|
+
return _mocker.importMock(path, getImporter("importMock"));
|
|
3469
3537
|
},
|
|
3470
3538
|
// this is typed in the interface so it's not necessary to type it here
|
|
3471
3539
|
mocked(item, _options = {}) {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import vm, { isContext } from 'node:vm';
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
|
|
4
|
-
import { createCustomConsole } from '../chunks/runtime-console.
|
|
5
|
-
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.
|
|
4
|
+
import { createCustomConsole } from '../chunks/runtime-console.DiVMr5d4.js';
|
|
5
|
+
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.BHj6OMh4.js';
|
|
6
6
|
import { distDir } from '../path.js';
|
|
7
7
|
import { dirname as dirname$1 } from 'node:path';
|
|
8
|
-
import { statSync, existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import { statSync, existsSync, promises, readFileSync } from 'node:fs';
|
|
9
9
|
import { isNodeBuiltin, isPrimitive, toArray, getCachedData, setCacheData } from 'vite-node/utils';
|
|
10
10
|
import { createRequire, Module } from 'node:module';
|
|
11
11
|
import { CSS_LANGS_RE, KNOWN_ASSET_RE } from 'vite-node/constants';
|
|
12
12
|
import '@vitest/runner/utils';
|
|
13
13
|
import '@vitest/utils';
|
|
14
|
-
import { p as provideWorkerState } from './global.
|
|
15
|
-
import './env.
|
|
14
|
+
import { p as provideWorkerState } from './global.7bFbnyXl.js';
|
|
15
|
+
import './env.bmJgw1qP.js';
|
|
16
16
|
|
|
17
17
|
const _require = createRequire(import.meta.url);
|
|
18
18
|
const requiresCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -245,24 +245,14 @@ const SyntheticModule$1 = vm.SyntheticModule;
|
|
|
245
245
|
const SourceTextModule = vm.SourceTextModule;
|
|
246
246
|
|
|
247
247
|
var __defProp$1 = Object.defineProperty;
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
251
|
-
return value;
|
|
252
|
-
};
|
|
253
|
-
var __accessCheck$1 = (obj, member, msg) => {
|
|
254
|
-
if (!member.has(obj))
|
|
255
|
-
throw TypeError("Cannot " + msg);
|
|
256
|
-
};
|
|
257
|
-
var __privateGet$1 = (obj, member, getter) => {
|
|
258
|
-
__accessCheck$1(obj, member, "read from private field");
|
|
259
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
260
|
-
};
|
|
261
|
-
var __privateAdd$1 = (obj, member, value) => {
|
|
262
|
-
if (member.has(obj))
|
|
263
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
264
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
248
|
+
var __typeError$1 = (msg) => {
|
|
249
|
+
throw TypeError(msg);
|
|
265
250
|
};
|
|
251
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
252
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
253
|
+
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
|
254
|
+
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
255
|
+
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
266
256
|
var _httpIp;
|
|
267
257
|
const dataURIRegex = /^data:(?<mime>text\/javascript|application\/json|application\/wasm)(?:;(?<encoding>charset=utf-8|base64))?,(?<code>.*)$/;
|
|
268
258
|
class EsmExecutor {
|
|
@@ -286,12 +276,17 @@ class EsmExecutor {
|
|
|
286
276
|
await m.evaluate();
|
|
287
277
|
return m;
|
|
288
278
|
}
|
|
289
|
-
async createEsModule(
|
|
290
|
-
const cached = this.moduleCache.get(
|
|
279
|
+
async createEsModule(fileURL, getCode) {
|
|
280
|
+
const cached = this.moduleCache.get(fileURL);
|
|
291
281
|
if (cached)
|
|
292
282
|
return cached;
|
|
283
|
+
const promise = this.loadEsModule(fileURL, getCode);
|
|
284
|
+
this.moduleCache.set(fileURL, promise);
|
|
285
|
+
return promise;
|
|
286
|
+
}
|
|
287
|
+
async loadEsModule(fileURL, getCode) {
|
|
293
288
|
const code = await getCode();
|
|
294
|
-
if (
|
|
289
|
+
if (fileURL.endsWith(".json")) {
|
|
295
290
|
const m2 = new SyntheticModule$1(
|
|
296
291
|
["default"],
|
|
297
292
|
() => {
|
|
@@ -299,13 +294,13 @@ class EsmExecutor {
|
|
|
299
294
|
m2.setExport("default", result);
|
|
300
295
|
}
|
|
301
296
|
);
|
|
302
|
-
this.moduleCache.set(
|
|
297
|
+
this.moduleCache.set(fileURL, m2);
|
|
303
298
|
return m2;
|
|
304
299
|
}
|
|
305
300
|
const m = new SourceTextModule(
|
|
306
301
|
code,
|
|
307
302
|
{
|
|
308
|
-
identifier:
|
|
303
|
+
identifier: fileURL,
|
|
309
304
|
context: this.context,
|
|
310
305
|
importModuleDynamically: this.executor.importModuleDynamically,
|
|
311
306
|
initializeImportMeta: (meta, mod) => {
|
|
@@ -321,7 +316,7 @@ class EsmExecutor {
|
|
|
321
316
|
}
|
|
322
317
|
}
|
|
323
318
|
);
|
|
324
|
-
this.moduleCache.set(
|
|
319
|
+
this.moduleCache.set(fileURL, m);
|
|
325
320
|
return m;
|
|
326
321
|
}
|
|
327
322
|
async createWebAssemblyModule(fileUrl, getCode) {
|
|
@@ -523,29 +518,15 @@ class ViteExecutor {
|
|
|
523
518
|
}
|
|
524
519
|
|
|
525
520
|
var __defProp = Object.defineProperty;
|
|
526
|
-
var
|
|
527
|
-
|
|
528
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
529
|
-
return value;
|
|
530
|
-
};
|
|
531
|
-
var __accessCheck = (obj, member, msg) => {
|
|
532
|
-
if (!member.has(obj))
|
|
533
|
-
throw TypeError("Cannot " + msg);
|
|
534
|
-
};
|
|
535
|
-
var __privateGet = (obj, member, getter) => {
|
|
536
|
-
__accessCheck(obj, member, "read from private field");
|
|
537
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
538
|
-
};
|
|
539
|
-
var __privateAdd = (obj, member, value) => {
|
|
540
|
-
if (member.has(obj))
|
|
541
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
542
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
543
|
-
};
|
|
544
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
545
|
-
__accessCheck(obj, member, "write to private field");
|
|
546
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
547
|
-
return value;
|
|
521
|
+
var __typeError = (msg) => {
|
|
522
|
+
throw TypeError(msg);
|
|
548
523
|
};
|
|
524
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
525
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
526
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
527
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
528
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
529
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
549
530
|
var _networkSupported;
|
|
550
531
|
const SyntheticModule = vm.SyntheticModule;
|
|
551
532
|
const nativeResolve = import.meta.resolve;
|
|
@@ -562,7 +543,7 @@ class ExternalModulesExecutor {
|
|
|
562
543
|
// dynamic import can be used in both ESM and CJS, so we have it in the executor
|
|
563
544
|
__publicField(this, "importModuleDynamically", async (specifier, referencer) => {
|
|
564
545
|
const module = await this.resolveModule(specifier, referencer.identifier);
|
|
565
|
-
return this.esm.evaluateModule(module);
|
|
546
|
+
return await this.esm.evaluateModule(module);
|
|
566
547
|
});
|
|
567
548
|
__publicField(this, "resolveModule", async (specifier, referencer) => {
|
|
568
549
|
let identifier = this.resolve(specifier, referencer);
|
|
@@ -699,7 +680,7 @@ class ExternalModulesExecutor {
|
|
|
699
680
|
}
|
|
700
681
|
switch (type) {
|
|
701
682
|
case "data":
|
|
702
|
-
return this.esm.createDataModule(identifier);
|
|
683
|
+
return await this.esm.createDataModule(identifier);
|
|
703
684
|
case "builtin": {
|
|
704
685
|
const exports = this.require(identifier);
|
|
705
686
|
return this.wrapCoreSynteticModule(identifier, exports);
|
|
@@ -709,14 +690,13 @@ class ExternalModulesExecutor {
|
|
|
709
690
|
case "wasm":
|
|
710
691
|
return await this.esm.createWebAssemblyModule(url, () => this.fs.readBuffer(path));
|
|
711
692
|
case "module":
|
|
712
|
-
return await this.esm.createEsModule(url, () => this.fs.
|
|
693
|
+
return await this.esm.createEsModule(url, () => this.fs.readFileAsync(path));
|
|
713
694
|
case "commonjs": {
|
|
714
695
|
const exports = this.require(path);
|
|
715
696
|
return this.wrapCommonJsSynteticModule(identifier, exports);
|
|
716
697
|
}
|
|
717
|
-
case "network":
|
|
718
|
-
return this.esm.createNetworkModule(url);
|
|
719
|
-
}
|
|
698
|
+
case "network":
|
|
699
|
+
return await this.esm.createNetworkModule(url);
|
|
720
700
|
default: {
|
|
721
701
|
const _deadend = type;
|
|
722
702
|
return _deadend;
|
|
@@ -741,9 +721,17 @@ _networkSupported = new WeakMap();
|
|
|
741
721
|
class FileMap {
|
|
742
722
|
fsCache = /* @__PURE__ */ new Map();
|
|
743
723
|
fsBufferCache = /* @__PURE__ */ new Map();
|
|
724
|
+
async readFileAsync(path) {
|
|
725
|
+
const cached = this.fsCache.get(path);
|
|
726
|
+
if (cached != null)
|
|
727
|
+
return cached;
|
|
728
|
+
const source = await promises.readFile(path, "utf-8");
|
|
729
|
+
this.fsCache.set(path, source);
|
|
730
|
+
return source;
|
|
731
|
+
}
|
|
744
732
|
readFile(path) {
|
|
745
733
|
const cached = this.fsCache.get(path);
|
|
746
|
-
if (cached)
|
|
734
|
+
if (cached != null)
|
|
747
735
|
return cached;
|
|
748
736
|
const source = readFileSync(path, "utf-8");
|
|
749
737
|
this.fsCache.set(path, source);
|
|
@@ -751,7 +739,7 @@ class FileMap {
|
|
|
751
739
|
}
|
|
752
740
|
readBuffer(path) {
|
|
753
741
|
const cached = this.fsBufferCache.get(path);
|
|
754
|
-
if (cached)
|
|
742
|
+
if (cached != null)
|
|
755
743
|
return cached;
|
|
756
744
|
const buffer = readFileSync(path);
|
|
757
745
|
this.fsBufferCache.set(path, buffer);
|
|
@@ -783,7 +771,7 @@ async function runVmTests(state) {
|
|
|
783
771
|
provideWorkerState(context, state);
|
|
784
772
|
context.process = process;
|
|
785
773
|
context.global = context;
|
|
786
|
-
context.console = state.config.disableConsoleIntercept ? console : createCustomConsole();
|
|
774
|
+
context.console = state.config.disableConsoleIntercept ? console : createCustomConsole(state);
|
|
787
775
|
context.setImmediate = setImmediate;
|
|
788
776
|
context.clearImmediate = clearImmediate;
|
|
789
777
|
const stubs = getDefaultRequestStubs(context);
|