@voidzero-dev/vite-plus-test 0.1.9 → 0.1.11
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 +181 -1
- package/dist/@vitest/browser/client/.vite/manifest.json +6 -6
- package/dist/@vitest/browser/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +49 -4
- package/dist/@vitest/browser/client/__vitest__/index.html +2 -2
- package/dist/@vitest/browser/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/@vitest/browser/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +168 -59
- package/dist/@vitest/browser/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/@vitest/browser/client/favicon.svg +49 -4
- package/dist/@vitest/browser/client/orchestrator.html +2 -2
- package/dist/@vitest/browser/client/tester/tester.html +2 -2
- package/dist/@vitest/browser/client.js +20 -13
- package/dist/@vitest/browser/context.d.ts +160 -10
- package/dist/@vitest/browser/context.js +108 -22
- package/dist/@vitest/browser/expect-element.js +23 -28
- package/dist/@vitest/browser/index-5Pe7X7sp.js +7 -0
- package/dist/@vitest/browser/index.d.ts +20 -2
- package/dist/@vitest/browser/index.js +5706 -159
- package/dist/@vitest/browser/locators.d.ts +14 -3
- package/dist/@vitest/browser/locators.js +1 -1
- package/dist/@vitest/browser-playwright/index.d.ts +23 -6
- package/dist/@vitest/browser-playwright/index.js +169 -61
- package/dist/@vitest/browser-playwright/locators.js +1 -1
- package/dist/@vitest/browser-preview/index.d.ts +14 -1
- package/dist/@vitest/browser-preview/locators.js +32 -20
- package/dist/@vitest/browser-webdriverio/index.d.ts +17 -3
- package/dist/@vitest/browser-webdriverio/index.js +22 -2
- package/dist/@vitest/browser-webdriverio/locators.js +85 -9
- package/dist/@vitest/expect/index.d.ts +172 -54
- package/dist/@vitest/expect/index.js +124 -67
- package/dist/@vitest/mocker/auto-register.js +1 -0
- package/dist/@vitest/mocker/automock.d.ts +1 -0
- package/dist/@vitest/mocker/automock.js +5 -0
- package/dist/@vitest/mocker/browser.d.ts +4 -4
- package/dist/@vitest/mocker/browser.js +1 -0
- package/dist/@vitest/mocker/chunk-automock.js +182 -14
- package/dist/@vitest/mocker/chunk-helpers.js +44 -0
- package/dist/@vitest/mocker/chunk-hoistMocks.js +659 -0
- package/dist/@vitest/mocker/chunk-mocker.js +41 -30
- package/dist/@vitest/mocker/chunk-registry.js +21 -7
- package/dist/@vitest/mocker/chunk-utils.js +18 -7
- package/dist/@vitest/mocker/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/@vitest/mocker/{index.d-C-sLYZi-.d.ts → index.d-B41z0AuW.d.ts} +1 -1
- package/dist/@vitest/mocker/index.d.ts +2 -2
- package/dist/@vitest/mocker/index.js +18 -3
- package/dist/@vitest/mocker/{mocker.d-TnKRhz7N.d.ts → mocker.d-QEntlm6J.d.ts} +10 -5
- package/dist/@vitest/mocker/node.d.ts +5 -734
- package/dist/@vitest/mocker/node.js +29 -587
- package/dist/@vitest/mocker/redirect.js +4 -4
- package/dist/@vitest/mocker/register.d.ts +3 -3
- package/dist/@vitest/mocker/register.js +1 -0
- package/dist/@vitest/mocker/transforms.d.ts +6 -0
- package/dist/@vitest/mocker/transforms.js +8 -0
- package/dist/@vitest/mocker/{types.d-B8CCKmHt.d.ts → types.d-BjI5eAwu.d.ts} +23 -7
- package/dist/@vitest/pretty-format/index.d.ts +11 -1
- package/dist/@vitest/pretty-format/index.js +33 -4
- package/dist/@vitest/runner/chunk-tasks.js +305 -37
- package/dist/@vitest/runner/index.d.ts +5 -6
- package/dist/@vitest/runner/index.js +1146 -455
- package/dist/@vitest/runner/{tasks.d-C7UxawJ9.d.ts → tasks.d-D2GKpdwQ.d.ts} +726 -55
- package/dist/@vitest/runner/types.d.ts +2 -182
- package/dist/@vitest/runner/utils.d.ts +16 -8
- package/dist/@vitest/runner/utils.js +1 -1
- package/dist/@vitest/snapshot/{environment.d-DHdQ1Csl.d.ts → environment.d-DOJxxZV9.d.ts} +2 -7
- package/dist/@vitest/snapshot/environment.d.ts +2 -1
- package/dist/@vitest/snapshot/environment.js +1 -1
- package/dist/@vitest/snapshot/index.d.ts +4 -3
- package/dist/@vitest/snapshot/index.js +21 -550
- package/dist/@vitest/snapshot/manager.d.ts +3 -2
- package/dist/@vitest/snapshot/manager.js +1 -1
- package/dist/@vitest/snapshot/{rawSnapshot.d-lFsMJFUd.d.ts → rawSnapshot.d-U2kJUxDr.d.ts} +1 -1
- package/dist/@vitest/spy/index.d.ts +34 -4
- package/dist/@vitest/spy/index.js +69 -19
- package/dist/@vitest/utils/diff.js +11 -9
- package/dist/@vitest/utils/display.d.ts +2 -1
- package/dist/@vitest/utils/display.js +38 -5
- package/dist/@vitest/utils/error.d.ts +2 -1
- package/dist/@vitest/utils/error.js +1 -2
- package/dist/@vitest/utils/helpers.d.ts +4 -1
- package/dist/@vitest/utils/helpers.js +43 -1
- package/dist/@vitest/utils/resolver.js +1 -2
- package/dist/@vitest/utils/serialize.js +6 -6
- package/dist/@vitest/utils/source-map/node.d.ts +6 -0
- package/dist/@vitest/utils/source-map/node.js +23 -0
- package/dist/@vitest/utils/source-map.js +15 -5
- package/dist/browser.d.ts +3 -2
- package/dist/browser.js +2 -2
- package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
- package/dist/chunks/{base.CJ0Y4ePK.js → base.DM0-RqVb.js} +54 -16
- package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.D0SlKNbZ.js} +1 -1
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.X3SXoOCV.d.ts} +4 -1
- package/dist/chunks/{cac.DVeoLl0M.js → cac.CWGDZnXT.js} +979 -20
- package/dist/chunks/{cli-api.B7PN_QUv.js → cli-api.DuT9iuvY.js} +8764 -7898
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.EJLVE3es.d.ts} +30 -15
- package/dist/chunks/{console.Cf-YriPC.js → console.3WNpx0tS.js} +3 -2
- package/dist/chunks/{constants.D_Q9UYh-.js → constants.CPYnjOGj.js} +4 -2
- package/dist/chunks/coverage.Bri33R1t.js +1050 -0
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.DgVhQm5q.js} +35 -4
- package/dist/chunks/{defaults.BOqNVLsY.js → defaults.CdU2lD-q.js} +4 -3
- package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.x-ILCfAE.d.ts} +1 -2
- package/dist/chunks/{globals.DOayXfHP.js → globals.BXNGLnTL.js} +11 -10
- package/dist/chunks/{coverage.AVPTjMgw.js → index.BCY_7LL2.js} +5 -959
- package/dist/chunks/{index.C5r1PdPD.js → index.CEzQDJGb.js} +1 -1
- package/dist/chunks/{index.D3XRDfWc.js → index.CMESou6r.js} +26 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.DGNSnENe.js} +95 -9
- package/dist/chunks/{index.M8mOzt4Y.js → index.DXMFO5MJ.js} +3279 -2914
- package/dist/chunks/{index.Z5E_ObnR.js → index.DlDSLQD3.js} +7 -3
- package/dist/chunks/{index.CyBMJtT7.js → index.EY6TCHpo.js} +10 -8
- package/dist/chunks/{index.D4KonVSU.js → index.og1WyBLx.js} +18 -3
- package/dist/chunks/{init-forks._y3TW739.js → init-forks.DeArv0jT.js} +1 -1
- package/dist/chunks/{init-threads.DBO2kn-p.js → init-threads.-2OUl4Nn.js} +1 -1
- package/dist/chunks/{init.B6MLFIaN.js → init.DICorXCo.js} +52 -13
- package/dist/chunks/native.DPzPHdi5.js +148 -0
- package/dist/chunks/nativeModuleMocker.DndvSdL6.js +206 -0
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
- package/dist/chunks/{node.Ce0vMQM7.js → node.COQbm6gK.js} +1 -1
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.BuW-flqo.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.DVUYHHhe.d.ts} +328 -79
- package/dist/chunks/rpc.MzXet3jl.js +144 -0
- package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.BFMWpdph.d.ts} +10 -2
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.B41N_kPE.js} +3 -3
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startVitestModuleRunner.C3ZR-4J3.js} +265 -405
- package/dist/chunks/{suite.d.BJWk38HB.d.ts → suite.d.udJtyAgw.d.ts} +1 -1
- package/dist/chunks/{vi.2VT5v0um.js → test.CTcmp4Su.js} +538 -181
- package/dist/chunks/{utils.DvEY5TfP.js → utils.BX5Fg8C4.js} +8 -1
- package/dist/chunks/{vm.D3epNOPZ.js → vm.Dh2rTtmP.js} +48 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.B84sVRy0.d.ts} +2 -2
- package/dist/cli.js +6 -5
- package/dist/client/.vite/manifest.json +6 -6
- package/dist/client/__vitest__/assets/index-Da0hb3oU.css +1 -0
- package/dist/client/__vitest__/assets/index-Di71CKDo.js +63 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +49 -4
- package/dist/client/__vitest__/index.html +2 -2
- package/dist/client/__vitest_browser__/{orchestrator-S_3e_uzt.js → orchestrator-CXs6qrFe.js} +70 -28
- package/dist/client/__vitest_browser__/{tester-k74mgIRa.js → tester-K5NNxh1O.js} +167 -58
- package/dist/client/__vitest_browser__/{utils-uxqdqUz8.js → utils-C2ISqq1C.js} +2 -2
- package/dist/client/favicon.svg +49 -4
- package/dist/client/orchestrator.html +2 -2
- package/dist/client/tester/tester.html +2 -2
- package/dist/client.js +20 -13
- package/dist/config.cjs +3 -2
- package/dist/config.d.ts +13 -12
- package/dist/config.js +2 -2
- package/dist/context.js +108 -22
- package/dist/coverage.d.ts +12 -8
- package/dist/coverage.js +8 -5
- package/dist/environments.js +3 -1
- package/dist/expect-element.js +23 -23
- package/dist/index-5Pe7X7sp.js +7 -0
- package/dist/index.d.ts +66 -27
- package/dist/index.js +10 -9
- package/dist/locators.d.ts +14 -3
- package/dist/locators.js +1 -1
- package/dist/module-evaluator.d.ts +11 -1
- package/dist/module-evaluator.js +43 -26
- package/dist/node.d.ts +28 -14
- package/dist/node.js +42 -40
- package/dist/nodejs-worker-loader.js +41 -0
- package/dist/plugins/mocker-transforms.mjs +2 -0
- package/dist/plugins/utils-source-map-node.mjs +2 -0
- package/dist/reporters.d.ts +8 -8
- package/dist/reporters.js +7 -5
- package/dist/runners.d.ts +24 -5
- package/dist/runners.js +6 -6
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +35 -0
- package/dist/snapshot.js +4 -2
- package/dist/suite.d.ts +1 -1
- package/dist/suite.js +4 -2
- package/dist/vendor/blazediff_core.d.mts +1 -0
- package/dist/vendor/blazediff_core.mjs +117 -0
- package/dist/vendor/chai.mjs +4 -249
- package/dist/vendor/convert-source-map.d.mts +1 -0
- package/dist/vendor/convert-source-map.mjs +150 -0
- package/dist/vendor/expect-type.d.mts +14 -7
- package/dist/vendor/expect-type.mjs +5 -5
- package/dist/vendor/std-env.d.mts +131 -40
- package/dist/vendor/std-env.mjs +114 -117
- package/dist/worker.d.ts +6 -6
- package/dist/worker.js +27 -21
- package/dist/workers/forks.js +23 -17
- package/dist/workers/runVmTests.js +18 -16
- package/dist/workers/threads.js +23 -17
- package/dist/workers/vmForks.js +15 -12
- package/dist/workers/vmThreads.js +15 -12
- package/globals.d.ts +2 -0
- package/package.json +35 -26
- package/suppress-warnings.cjs +1 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/@vitest/browser/index-D6m36C6U.js +0 -11
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +0 -5
- package/dist/@vitest/utils/highlight.d.ts +0 -9
- package/dist/@vitest/utils/highlight.js +0 -538
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +0 -57
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +0 -1
- package/dist/index-D6m36C6U.js +0 -6
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { g as getWorkerState, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.DvEY5TfP.js';
|
|
1
|
+
import { getCurrentTest, updateTask, createTaskCollector, getCurrentSuite, getHooks, getFn } from '../@vitest/runner/index.js';
|
|
2
|
+
import { assertTypes, createSimpleStackTrace, createDefer } from '../@vitest/utils/helpers.js';
|
|
4
3
|
import { getSafeTimers, delay } from '../@vitest/utils/timers.js';
|
|
5
|
-
import {
|
|
4
|
+
import { a as getBenchOptions, g as getBenchFn } from './benchmark.D0SlKNbZ.js';
|
|
5
|
+
import { g as getWorkerState, i as isChildProcess, w as waitForImportsToResolve, r as resetModules } from './utils.BX5Fg8C4.js';
|
|
6
|
+
import { chai, wrapAssertion, recordAsyncExpect, createAssertionMessage, equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, ChaiStyleAssertions, JestAsymmetricMatchers, GLOBAL_EXPECT, ASYMMETRIC_MATCHERS_OBJECT, getState, setState, addCustomEqualityTesters, customMatchers } from '../@vitest/expect/index.js';
|
|
7
|
+
import { getNames, getTests, getTestName, createChainable } from '../@vitest/runner/utils.js';
|
|
8
|
+
import { processError } from '../@vitest/utils/error.js';
|
|
9
|
+
import { normalize } from '../vendor/pathe.mjs';
|
|
6
10
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '../@vitest/snapshot/index.js';
|
|
7
|
-
import '../@vitest/utils/error.js';
|
|
8
|
-
import { assertTypes, createSimpleStackTrace } from '../@vitest/utils/helpers.js';
|
|
9
11
|
import { fn, spyOn, restoreAllMocks, resetAllMocks, clearAllMocks, isMockFunction } from '../@vitest/spy/index.js';
|
|
10
12
|
import '../@vitest/utils/offset.js';
|
|
11
13
|
import { parseSingleStack } from '../@vitest/utils/source-map.js';
|
|
12
14
|
import { c as commonjsGlobal } from './_commonjsHelpers.D26ty3Ew.js';
|
|
13
|
-
import { R as RealDate,
|
|
15
|
+
import { R as RealDate, b as resetDate, m as mockDate, r as rpc } from './rpc.MzXet3jl.js';
|
|
14
16
|
|
|
15
17
|
// these matchers are not supported because they don't make sense with poll
|
|
16
18
|
const unsupported = [
|
|
@@ -61,6 +63,7 @@ function createExpectPoll(expect) {
|
|
|
61
63
|
hasTimedOut = true;
|
|
62
64
|
}, timeout);
|
|
63
65
|
chai.util.flag(assertion, "_name", key);
|
|
66
|
+
const onSettled = chai.util.flag(assertion, "_poll.onSettled");
|
|
64
67
|
try {
|
|
65
68
|
while (true) {
|
|
66
69
|
const isLastAttempt = hasTimedOut;
|
|
@@ -70,9 +73,20 @@ function createExpectPoll(expect) {
|
|
|
70
73
|
const obj = await fn();
|
|
71
74
|
chai.util.flag(assertion, "object", obj);
|
|
72
75
|
executionPhase = "assertion";
|
|
73
|
-
|
|
76
|
+
const output = await assertionFunction.call(assertion, ...args);
|
|
77
|
+
await onSettled?.({
|
|
78
|
+
assertion,
|
|
79
|
+
status: "pass"
|
|
80
|
+
});
|
|
81
|
+
return output;
|
|
74
82
|
} catch (err) {
|
|
75
|
-
if (isLastAttempt || executionPhase === "assertion" && chai.util.flag(assertion, "_poll.assert_once"))
|
|
83
|
+
if (isLastAttempt || executionPhase === "assertion" && chai.util.flag(assertion, "_poll.assert_once")) {
|
|
84
|
+
await onSettled?.({
|
|
85
|
+
assertion,
|
|
86
|
+
status: "fail"
|
|
87
|
+
});
|
|
88
|
+
throwWithCause(err, STACK_TRACE_ERROR);
|
|
89
|
+
}
|
|
76
90
|
await delay(interval, setTimeout);
|
|
77
91
|
}
|
|
78
92
|
}
|
|
@@ -98,9 +112,11 @@ function createExpectPoll(expect) {
|
|
|
98
112
|
return (resultPromise ||= promise()).then(onFulfilled, onRejected);
|
|
99
113
|
},
|
|
100
114
|
catch(onRejected) {
|
|
115
|
+
awaited = true;
|
|
101
116
|
return (resultPromise ||= promise()).catch(onRejected);
|
|
102
117
|
},
|
|
103
118
|
finally(onFinally) {
|
|
119
|
+
awaited = true;
|
|
104
120
|
return (resultPromise ||= promise()).finally(onFinally);
|
|
105
121
|
},
|
|
106
122
|
[Symbol.toStringTag]: "Promise"
|
|
@@ -115,55 +131,6 @@ function copyStackTrace$1(target, source) {
|
|
|
115
131
|
return target;
|
|
116
132
|
}
|
|
117
133
|
|
|
118
|
-
function createAssertionMessage(util, assertion, hasArgs) {
|
|
119
|
-
const not = util.flag(assertion, "negate") ? "not." : "";
|
|
120
|
-
const name = `${util.flag(assertion, "_name")}(${"expected" })`;
|
|
121
|
-
const promiseName = util.flag(assertion, "promise");
|
|
122
|
-
return `expect(actual)${promiseName ? `.${promiseName}` : ""}.${not}${name}`;
|
|
123
|
-
}
|
|
124
|
-
function recordAsyncExpect(_test, promise, assertion, error) {
|
|
125
|
-
const test = _test;
|
|
126
|
-
// record promise for test, that resolves before test ends
|
|
127
|
-
if (test && promise instanceof Promise) {
|
|
128
|
-
// if promise is explicitly awaited, remove it from the list
|
|
129
|
-
promise = promise.finally(() => {
|
|
130
|
-
if (!test.promises) return;
|
|
131
|
-
const index = test.promises.indexOf(promise);
|
|
132
|
-
if (index !== -1) test.promises.splice(index, 1);
|
|
133
|
-
});
|
|
134
|
-
// record promise
|
|
135
|
-
if (!test.promises) test.promises = [];
|
|
136
|
-
test.promises.push(promise);
|
|
137
|
-
let resolved = false;
|
|
138
|
-
test.onFinished ??= [];
|
|
139
|
-
test.onFinished.push(() => {
|
|
140
|
-
if (!resolved) {
|
|
141
|
-
const stack = (globalThis.__vitest_worker__?.onFilterStackTrace || ((s) => s || ""))(error.stack);
|
|
142
|
-
console.warn([
|
|
143
|
-
`Promise returned by \`${assertion}\` was not awaited. `,
|
|
144
|
-
"Vitest currently auto-awaits hanging assertions at the end of the test, but this will cause the test to fail in Vitest 3. ",
|
|
145
|
-
"Please remember to await the assertion.\n",
|
|
146
|
-
stack
|
|
147
|
-
].join(""));
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
return {
|
|
151
|
-
then(onFulfilled, onRejected) {
|
|
152
|
-
resolved = true;
|
|
153
|
-
return promise.then(onFulfilled, onRejected);
|
|
154
|
-
},
|
|
155
|
-
catch(onRejected) {
|
|
156
|
-
return promise.catch(onRejected);
|
|
157
|
-
},
|
|
158
|
-
finally(onFinally) {
|
|
159
|
-
return promise.finally(onFinally);
|
|
160
|
-
},
|
|
161
|
-
[Symbol.toStringTag]: "Promise"
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
return promise;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
134
|
let _client;
|
|
168
135
|
function getSnapshotClient() {
|
|
169
136
|
if (!_client) _client = new SnapshotClient({ isEqual: (received, expected) => {
|
|
@@ -197,7 +164,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
197
164
|
if (!test) throw new Error(`'${assertionName}' cannot be used without test context`);
|
|
198
165
|
return test;
|
|
199
166
|
}
|
|
200
|
-
for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai.Assertion.prototype, key, function(properties, message) {
|
|
167
|
+
for (const key of ["matchSnapshot", "toMatchSnapshot"]) utils.addMethod(chai.Assertion.prototype, key, wrapAssertion(utils, key, function(properties, message) {
|
|
201
168
|
utils.flag(this, "_name", key);
|
|
202
169
|
if (utils.flag(this, "negate")) throw new Error(`${key} cannot be used with "not"`);
|
|
203
170
|
const expected = utils.flag(this, "object");
|
|
@@ -215,7 +182,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
215
182
|
errorMessage,
|
|
216
183
|
...getTestNames(test)
|
|
217
184
|
});
|
|
218
|
-
});
|
|
185
|
+
}));
|
|
219
186
|
utils.addMethod(chai.Assertion.prototype, "toMatchFileSnapshot", function(file, message) {
|
|
220
187
|
utils.flag(this, "_name", "toMatchFileSnapshot");
|
|
221
188
|
if (utils.flag(this, "negate")) throw new Error("toMatchFileSnapshot cannot be used with \"not\"");
|
|
@@ -230,13 +197,12 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
230
197
|
rawSnapshot: { file },
|
|
231
198
|
errorMessage,
|
|
232
199
|
...getTestNames(test)
|
|
233
|
-
}), createAssertionMessage(utils, this), error);
|
|
200
|
+
}), createAssertionMessage(utils, this, true), error, utils.flag(this, "soft"));
|
|
234
201
|
});
|
|
235
|
-
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", function
|
|
202
|
+
utils.addMethod(chai.Assertion.prototype, "toMatchInlineSnapshot", wrapAssertion(utils, "toMatchInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(properties, inlineSnapshot, message) {
|
|
236
203
|
utils.flag(this, "_name", "toMatchInlineSnapshot");
|
|
237
204
|
if (utils.flag(this, "negate")) throw new Error("toMatchInlineSnapshot cannot be used with \"not\"");
|
|
238
205
|
const test = getTest("toMatchInlineSnapshot", this);
|
|
239
|
-
if (test.each || test.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
240
206
|
const expected = utils.flag(this, "object");
|
|
241
207
|
const error = utils.flag(this, "error");
|
|
242
208
|
if (typeof properties === "string") {
|
|
@@ -256,8 +222,8 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
256
222
|
errorMessage,
|
|
257
223
|
...getTestNames(test)
|
|
258
224
|
});
|
|
259
|
-
});
|
|
260
|
-
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", function(message) {
|
|
225
|
+
}));
|
|
226
|
+
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingSnapshot", wrapAssertion(utils, "toThrowErrorMatchingSnapshot", function(properties, message) {
|
|
261
227
|
utils.flag(this, "_name", "toThrowErrorMatchingSnapshot");
|
|
262
228
|
if (utils.flag(this, "negate")) throw new Error("toThrowErrorMatchingSnapshot cannot be used with \"not\"");
|
|
263
229
|
const expected = utils.flag(this, "object");
|
|
@@ -270,11 +236,10 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
270
236
|
errorMessage,
|
|
271
237
|
...getTestNames(test)
|
|
272
238
|
});
|
|
273
|
-
});
|
|
274
|
-
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", function
|
|
239
|
+
}));
|
|
240
|
+
utils.addMethod(chai.Assertion.prototype, "toThrowErrorMatchingInlineSnapshot", wrapAssertion(utils, "toThrowErrorMatchingInlineSnapshot", function __INLINE_SNAPSHOT_OFFSET_3__(inlineSnapshot, message) {
|
|
275
241
|
if (utils.flag(this, "negate")) throw new Error("toThrowErrorMatchingInlineSnapshot cannot be used with \"not\"");
|
|
276
242
|
const test = getTest("toThrowErrorMatchingInlineSnapshot", this);
|
|
277
|
-
if (test.each || test.suite?.each) throw new Error("InlineSnapshot cannot be used inside of test.each or describe.each");
|
|
278
243
|
const expected = utils.flag(this, "object");
|
|
279
244
|
const error = utils.flag(this, "error");
|
|
280
245
|
const promise = utils.flag(this, "promise");
|
|
@@ -289,12 +254,13 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
289
254
|
errorMessage,
|
|
290
255
|
...getTestNames(test)
|
|
291
256
|
});
|
|
292
|
-
});
|
|
257
|
+
}));
|
|
293
258
|
utils.addMethod(chai.expect, "addSnapshotSerializer", addSerializer);
|
|
294
259
|
};
|
|
295
260
|
|
|
296
261
|
chai.use(JestExtend);
|
|
297
262
|
chai.use(JestChaiExpect);
|
|
263
|
+
chai.use(ChaiStyleAssertions);
|
|
298
264
|
chai.use(SnapshotPlugin);
|
|
299
265
|
chai.use(JestAsymmetricMatchers);
|
|
300
266
|
|
|
@@ -1326,6 +1292,30 @@ function requireFakeTimersSrc () {
|
|
|
1326
1292
|
}
|
|
1327
1293
|
}
|
|
1328
1294
|
|
|
1295
|
+
/**
|
|
1296
|
+
* @typedef {"nextAsync" | "manual" | "interval"} TickMode
|
|
1297
|
+
*/
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* @typedef {object} NextAsyncTickMode
|
|
1301
|
+
* @property {"nextAsync"} mode
|
|
1302
|
+
*/
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* @typedef {object} ManualTickMode
|
|
1306
|
+
* @property {"manual"} mode
|
|
1307
|
+
*/
|
|
1308
|
+
|
|
1309
|
+
/**
|
|
1310
|
+
* @typedef {object} IntervalTickMode
|
|
1311
|
+
* @property {"interval"} mode
|
|
1312
|
+
* @property {number} [delta]
|
|
1313
|
+
*/
|
|
1314
|
+
|
|
1315
|
+
/**
|
|
1316
|
+
* @typedef {IntervalTickMode | NextAsyncTickMode | ManualTickMode} TimerTickMode
|
|
1317
|
+
*/
|
|
1318
|
+
|
|
1329
1319
|
/**
|
|
1330
1320
|
* @typedef {object} IdleDeadline
|
|
1331
1321
|
* @property {boolean} didTimeout - whether or not the callback was called before reaching the optional timeout
|
|
@@ -1411,6 +1401,7 @@ function requireFakeTimersSrc () {
|
|
|
1411
1401
|
* @property {{methodName:string, original:any}[] | undefined} timersModuleMethods
|
|
1412
1402
|
* @property {{methodName:string, original:any}[] | undefined} timersPromisesModuleMethods
|
|
1413
1403
|
* @property {Map<function(): void, AbortSignal>} abortListenerMap
|
|
1404
|
+
* @property {function(TimerTickMode): void} setTickMode
|
|
1414
1405
|
*/
|
|
1415
1406
|
/* eslint-enable jsdoc/require-property-description */
|
|
1416
1407
|
|
|
@@ -2208,10 +2199,9 @@ function requireFakeTimersSrc () {
|
|
|
2208
2199
|
|
|
2209
2200
|
/**
|
|
2210
2201
|
* @param {Clock} clock
|
|
2211
|
-
* @param {Config} config
|
|
2212
2202
|
* @returns {Timer[]}
|
|
2213
2203
|
*/
|
|
2214
|
-
function uninstall(clock
|
|
2204
|
+
function uninstall(clock) {
|
|
2215
2205
|
let method, i, l;
|
|
2216
2206
|
const installedHrTime = "_hrtime";
|
|
2217
2207
|
const installedNextTick = "_nextTick";
|
|
@@ -2269,9 +2259,7 @@ function requireFakeTimersSrc () {
|
|
|
2269
2259
|
}
|
|
2270
2260
|
}
|
|
2271
2261
|
|
|
2272
|
-
|
|
2273
|
-
_global.clearInterval(clock.attachedInterval);
|
|
2274
|
-
}
|
|
2262
|
+
clock.setTickMode("manual");
|
|
2275
2263
|
|
|
2276
2264
|
// Prevent multiple executions which will completely remove these props
|
|
2277
2265
|
clock.methods = [];
|
|
@@ -2427,6 +2415,8 @@ function requireFakeTimersSrc () {
|
|
|
2427
2415
|
}
|
|
2428
2416
|
|
|
2429
2417
|
const originalSetTimeout = _global.setImmediate || _global.setTimeout;
|
|
2418
|
+
const originalClearInterval = _global.clearInterval;
|
|
2419
|
+
const originalSetInterval = _global.setInterval;
|
|
2430
2420
|
|
|
2431
2421
|
/**
|
|
2432
2422
|
* @param {Date|number} [start] the system time - non-integer values are floored
|
|
@@ -2445,6 +2435,7 @@ function requireFakeTimersSrc () {
|
|
|
2445
2435
|
now: start,
|
|
2446
2436
|
Date: createDate(),
|
|
2447
2437
|
loopLimit: loopLimit,
|
|
2438
|
+
tickMode: { mode: "manual", counter: 0, delta: undefined },
|
|
2448
2439
|
};
|
|
2449
2440
|
|
|
2450
2441
|
clock.Date.clock = clock;
|
|
@@ -2511,6 +2502,74 @@ function requireFakeTimersSrc () {
|
|
|
2511
2502
|
clock.Intl.clock = clock;
|
|
2512
2503
|
}
|
|
2513
2504
|
|
|
2505
|
+
/**
|
|
2506
|
+
* @param {TimerTickMode} tickModeConfig - The new configuration for how the clock should tick.
|
|
2507
|
+
*/
|
|
2508
|
+
clock.setTickMode = function (tickModeConfig) {
|
|
2509
|
+
const { mode: newMode, delta: newDelta } = tickModeConfig;
|
|
2510
|
+
const { mode: oldMode, delta: oldDelta } = clock.tickMode;
|
|
2511
|
+
if (newMode === oldMode && newDelta === oldDelta) {
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
if (oldMode === "interval") {
|
|
2516
|
+
originalClearInterval(clock.attachedInterval);
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
clock.tickMode = {
|
|
2520
|
+
counter: clock.tickMode.counter + 1,
|
|
2521
|
+
mode: newMode,
|
|
2522
|
+
delta: newDelta,
|
|
2523
|
+
};
|
|
2524
|
+
|
|
2525
|
+
if (newMode === "nextAsync") {
|
|
2526
|
+
advanceUntilModeChanges();
|
|
2527
|
+
} else if (newMode === "interval") {
|
|
2528
|
+
createIntervalTick(clock, newDelta || 20);
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
|
|
2532
|
+
async function advanceUntilModeChanges() {
|
|
2533
|
+
async function newMacrotask() {
|
|
2534
|
+
// MessageChannel ensures that setTimeout is not throttled to 4ms.
|
|
2535
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified
|
|
2536
|
+
// https://stackblitz.com/edit/stackblitz-starters-qtlpcc
|
|
2537
|
+
const channel = new MessageChannel();
|
|
2538
|
+
await new Promise((resolve) => {
|
|
2539
|
+
channel.port1.onmessage = () => {
|
|
2540
|
+
resolve();
|
|
2541
|
+
channel.port1.close();
|
|
2542
|
+
};
|
|
2543
|
+
channel.port2.postMessage(undefined);
|
|
2544
|
+
});
|
|
2545
|
+
channel.port1.close();
|
|
2546
|
+
channel.port2.close();
|
|
2547
|
+
// setTimeout ensures microtask queue is emptied
|
|
2548
|
+
await new Promise((resolve) => {
|
|
2549
|
+
originalSetTimeout(resolve);
|
|
2550
|
+
});
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
const { counter } = clock.tickMode;
|
|
2554
|
+
while (clock.tickMode.counter === counter) {
|
|
2555
|
+
await newMacrotask();
|
|
2556
|
+
if (clock.tickMode.counter !== counter) {
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
clock.next();
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
function pauseAutoTickUntilFinished(promise) {
|
|
2564
|
+
if (clock.tickMode.mode !== "nextAsync") {
|
|
2565
|
+
return promise;
|
|
2566
|
+
}
|
|
2567
|
+
clock.setTickMode({ mode: "manual" });
|
|
2568
|
+
return promise.finally(() => {
|
|
2569
|
+
clock.setTickMode({ mode: "nextAsync" });
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2514
2573
|
clock.requestIdleCallback = function requestIdleCallback(
|
|
2515
2574
|
func,
|
|
2516
2575
|
timeout,
|
|
@@ -2809,15 +2868,17 @@ function requireFakeTimersSrc () {
|
|
|
2809
2868
|
* @returns {Promise}
|
|
2810
2869
|
*/
|
|
2811
2870
|
clock.tickAsync = function tickAsync(tickValue) {
|
|
2812
|
-
return
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2871
|
+
return pauseAutoTickUntilFinished(
|
|
2872
|
+
new _global.Promise(function (resolve, reject) {
|
|
2873
|
+
originalSetTimeout(function () {
|
|
2874
|
+
try {
|
|
2875
|
+
doTick(tickValue, true, resolve, reject);
|
|
2876
|
+
} catch (e) {
|
|
2877
|
+
reject(e);
|
|
2878
|
+
}
|
|
2879
|
+
});
|
|
2880
|
+
}),
|
|
2881
|
+
);
|
|
2821
2882
|
};
|
|
2822
2883
|
}
|
|
2823
2884
|
|
|
@@ -2841,37 +2902,39 @@ function requireFakeTimersSrc () {
|
|
|
2841
2902
|
|
|
2842
2903
|
if (typeof _global.Promise !== "undefined") {
|
|
2843
2904
|
clock.nextAsync = function nextAsync() {
|
|
2844
|
-
return
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
const timer = firstTimer(clock);
|
|
2848
|
-
if (!timer) {
|
|
2849
|
-
resolve(clock.now);
|
|
2850
|
-
return;
|
|
2851
|
-
}
|
|
2852
|
-
|
|
2853
|
-
let err;
|
|
2854
|
-
clock.duringTick = true;
|
|
2855
|
-
clock.now = timer.callAt;
|
|
2905
|
+
return pauseAutoTickUntilFinished(
|
|
2906
|
+
new _global.Promise(function (resolve, reject) {
|
|
2907
|
+
originalSetTimeout(function () {
|
|
2856
2908
|
try {
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
err = e;
|
|
2860
|
-
}
|
|
2861
|
-
clock.duringTick = false;
|
|
2862
|
-
|
|
2863
|
-
originalSetTimeout(function () {
|
|
2864
|
-
if (err) {
|
|
2865
|
-
reject(err);
|
|
2866
|
-
} else {
|
|
2909
|
+
const timer = firstTimer(clock);
|
|
2910
|
+
if (!timer) {
|
|
2867
2911
|
resolve(clock.now);
|
|
2912
|
+
return;
|
|
2868
2913
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2914
|
+
|
|
2915
|
+
let err;
|
|
2916
|
+
clock.duringTick = true;
|
|
2917
|
+
clock.now = timer.callAt;
|
|
2918
|
+
try {
|
|
2919
|
+
callTimer(clock, timer);
|
|
2920
|
+
} catch (e) {
|
|
2921
|
+
err = e;
|
|
2922
|
+
}
|
|
2923
|
+
clock.duringTick = false;
|
|
2924
|
+
|
|
2925
|
+
originalSetTimeout(function () {
|
|
2926
|
+
if (err) {
|
|
2927
|
+
reject(err);
|
|
2928
|
+
} else {
|
|
2929
|
+
resolve(clock.now);
|
|
2930
|
+
}
|
|
2931
|
+
});
|
|
2932
|
+
} catch (e) {
|
|
2933
|
+
reject(e);
|
|
2934
|
+
}
|
|
2935
|
+
});
|
|
2936
|
+
}),
|
|
2937
|
+
);
|
|
2875
2938
|
};
|
|
2876
2939
|
}
|
|
2877
2940
|
|
|
@@ -2904,51 +2967,55 @@ function requireFakeTimersSrc () {
|
|
|
2904
2967
|
|
|
2905
2968
|
if (typeof _global.Promise !== "undefined") {
|
|
2906
2969
|
clock.runAllAsync = function runAllAsync() {
|
|
2907
|
-
return
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
if (
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2970
|
+
return pauseAutoTickUntilFinished(
|
|
2971
|
+
new _global.Promise(function (resolve, reject) {
|
|
2972
|
+
let i = 0;
|
|
2973
|
+
/**
|
|
2974
|
+
*
|
|
2975
|
+
*/
|
|
2976
|
+
function doRun() {
|
|
2977
|
+
originalSetTimeout(function () {
|
|
2978
|
+
try {
|
|
2979
|
+
runJobs(clock);
|
|
2980
|
+
|
|
2981
|
+
let numTimers;
|
|
2982
|
+
if (i < clock.loopLimit) {
|
|
2983
|
+
if (!clock.timers) {
|
|
2984
|
+
resetIsNearInfiniteLimit();
|
|
2985
|
+
resolve(clock.now);
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
|
|
2989
|
+
numTimers = Object.keys(
|
|
2990
|
+
clock.timers,
|
|
2991
|
+
).length;
|
|
2992
|
+
if (numTimers === 0) {
|
|
2993
|
+
resetIsNearInfiniteLimit();
|
|
2994
|
+
resolve(clock.now);
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
clock.next();
|
|
2999
|
+
|
|
3000
|
+
i++;
|
|
3001
|
+
|
|
3002
|
+
doRun();
|
|
3003
|
+
checkIsNearInfiniteLimit(clock, i);
|
|
2931
3004
|
return;
|
|
2932
3005
|
}
|
|
2933
3006
|
|
|
2934
|
-
clock
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
return;
|
|
3007
|
+
const excessJob = firstTimer(clock);
|
|
3008
|
+
reject(
|
|
3009
|
+
getInfiniteLoopError(clock, excessJob),
|
|
3010
|
+
);
|
|
3011
|
+
} catch (e) {
|
|
3012
|
+
reject(e);
|
|
2941
3013
|
}
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
}
|
|
2948
|
-
});
|
|
2949
|
-
}
|
|
2950
|
-
doRun();
|
|
2951
|
-
});
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
doRun();
|
|
3017
|
+
}),
|
|
3018
|
+
);
|
|
2952
3019
|
};
|
|
2953
3020
|
}
|
|
2954
3021
|
|
|
@@ -2964,21 +3031,25 @@ function requireFakeTimersSrc () {
|
|
|
2964
3031
|
|
|
2965
3032
|
if (typeof _global.Promise !== "undefined") {
|
|
2966
3033
|
clock.runToLastAsync = function runToLastAsync() {
|
|
2967
|
-
return
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
3034
|
+
return pauseAutoTickUntilFinished(
|
|
3035
|
+
new _global.Promise(function (resolve, reject) {
|
|
3036
|
+
originalSetTimeout(function () {
|
|
3037
|
+
try {
|
|
3038
|
+
const timer = lastTimer(clock);
|
|
3039
|
+
if (!timer) {
|
|
3040
|
+
runJobs(clock);
|
|
3041
|
+
resolve(clock.now);
|
|
3042
|
+
}
|
|
2975
3043
|
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
3044
|
+
resolve(
|
|
3045
|
+
clock.tickAsync(timer.callAt - clock.now),
|
|
3046
|
+
);
|
|
3047
|
+
} catch (e) {
|
|
3048
|
+
reject(e);
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
}),
|
|
3052
|
+
);
|
|
2982
3053
|
};
|
|
2983
3054
|
}
|
|
2984
3055
|
|
|
@@ -3042,6 +3113,12 @@ function requireFakeTimersSrc () {
|
|
|
3042
3113
|
return clock;
|
|
3043
3114
|
}
|
|
3044
3115
|
|
|
3116
|
+
function createIntervalTick(clock, delta) {
|
|
3117
|
+
const intervalTick = doIntervalTick.bind(null, clock, delta);
|
|
3118
|
+
const intervalId = originalSetInterval(intervalTick, delta);
|
|
3119
|
+
clock.attachedInterval = intervalId;
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3045
3122
|
/* eslint-disable complexity */
|
|
3046
3123
|
|
|
3047
3124
|
/**
|
|
@@ -3102,7 +3179,7 @@ function requireFakeTimersSrc () {
|
|
|
3102
3179
|
clock.shouldClearNativeTimers = config.shouldClearNativeTimers;
|
|
3103
3180
|
|
|
3104
3181
|
clock.uninstall = function () {
|
|
3105
|
-
return uninstall(clock
|
|
3182
|
+
return uninstall(clock);
|
|
3106
3183
|
};
|
|
3107
3184
|
|
|
3108
3185
|
clock.abortListenerMap = new Map();
|
|
@@ -3114,16 +3191,10 @@ function requireFakeTimersSrc () {
|
|
|
3114
3191
|
}
|
|
3115
3192
|
|
|
3116
3193
|
if (config.shouldAdvanceTime === true) {
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
);
|
|
3122
|
-
const intervalId = _global.setInterval(
|
|
3123
|
-
intervalTick,
|
|
3124
|
-
config.advanceTimeDelta,
|
|
3125
|
-
);
|
|
3126
|
-
clock.attachedInterval = intervalId;
|
|
3194
|
+
clock.setTickMode({
|
|
3195
|
+
mode: "interval",
|
|
3196
|
+
delta: config.advanceTimeDelta,
|
|
3197
|
+
});
|
|
3127
3198
|
}
|
|
3128
3199
|
|
|
3129
3200
|
if (clock.methods.includes("performance")) {
|
|
@@ -3535,9 +3606,7 @@ class FakeTimers {
|
|
|
3535
3606
|
if (this._checkFakeTimers()) this._clock.runToFrame();
|
|
3536
3607
|
}
|
|
3537
3608
|
runAllTicks() {
|
|
3538
|
-
if (this._checkFakeTimers())
|
|
3539
|
-
// @ts-expect-error method not exposed
|
|
3540
|
-
this._clock.runMicrotasks();
|
|
3609
|
+
if (this._checkFakeTimers()) this._clock.runMicrotasks();
|
|
3541
3610
|
}
|
|
3542
3611
|
useRealTimers() {
|
|
3543
3612
|
if (this._fakingDate) {
|
|
@@ -3591,6 +3660,15 @@ class FakeTimers {
|
|
|
3591
3660
|
if (this._checkFakeTimers()) return this._clock.countTimers();
|
|
3592
3661
|
return 0;
|
|
3593
3662
|
}
|
|
3663
|
+
setTimerTickMode(mode, interval) {
|
|
3664
|
+
if (this._checkFakeTimers()) if (mode === "manual") this._clock.setTickMode({ mode: "manual" });
|
|
3665
|
+
else if (mode === "nextTimerAsync") this._clock.setTickMode({ mode: "nextAsync" });
|
|
3666
|
+
else if (mode === "interval") this._clock.setTickMode({
|
|
3667
|
+
mode: "interval",
|
|
3668
|
+
delta: interval
|
|
3669
|
+
});
|
|
3670
|
+
else throw new Error(`Invalid tick mode: ${mode}`);
|
|
3671
|
+
}
|
|
3594
3672
|
configure(config) {
|
|
3595
3673
|
this._userConfig = config;
|
|
3596
3674
|
}
|
|
@@ -3793,10 +3871,23 @@ function createVitest() {
|
|
|
3793
3871
|
timers().clearAllTimers();
|
|
3794
3872
|
return utils;
|
|
3795
3873
|
},
|
|
3874
|
+
setTimerTickMode(mode, interval) {
|
|
3875
|
+
timers().setTimerTickMode(mode, interval);
|
|
3876
|
+
return utils;
|
|
3877
|
+
},
|
|
3796
3878
|
spyOn,
|
|
3797
3879
|
fn,
|
|
3798
3880
|
waitFor,
|
|
3799
3881
|
waitUntil,
|
|
3882
|
+
defineHelper: (fn) => {
|
|
3883
|
+
return function __VITEST_HELPER__(...args) {
|
|
3884
|
+
const result = fn(...args);
|
|
3885
|
+
if (result && typeof result === "object" && typeof result.then === "function") return (async function __VITEST_HELPER__() {
|
|
3886
|
+
return await result;
|
|
3887
|
+
})();
|
|
3888
|
+
return result;
|
|
3889
|
+
};
|
|
3890
|
+
},
|
|
3800
3891
|
hoisted(factory) {
|
|
3801
3892
|
assertTypes(factory, "\"vi.hoisted\" factory", ["function"]);
|
|
3802
3893
|
return factory();
|
|
@@ -3814,6 +3905,11 @@ function createVitest() {
|
|
|
3814
3905
|
if (typeof path !== "string") throw new TypeError(`vi.doMock() expects a string path, but received a ${typeof path}`);
|
|
3815
3906
|
const importer = getImporter("doMock");
|
|
3816
3907
|
_mocker().queueMock(path, importer, typeof factory === "function" ? () => factory(() => _mocker().importActual(path, importer, _mocker().getMockContext().callstack)) : factory);
|
|
3908
|
+
const rv = {};
|
|
3909
|
+
if (Symbol.dispose) rv[Symbol.dispose] = () => {
|
|
3910
|
+
_mocker().queueUnmock(path, importer);
|
|
3911
|
+
};
|
|
3912
|
+
return rv;
|
|
3817
3913
|
},
|
|
3818
3914
|
doUnmock(path) {
|
|
3819
3915
|
if (typeof path !== "string") throw new TypeError(`vi.doUnmock() expects a string path, but received a ${typeof path}`);
|
|
@@ -3916,4 +4012,265 @@ function getImporter(name) {
|
|
|
3916
4012
|
}) + 1])?.file || "";
|
|
3917
4013
|
}
|
|
3918
4014
|
|
|
3919
|
-
|
|
4015
|
+
function createBenchmarkResult(name) {
|
|
4016
|
+
return {
|
|
4017
|
+
name,
|
|
4018
|
+
rank: 0,
|
|
4019
|
+
rme: 0,
|
|
4020
|
+
samples: []
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
const benchmarkTasks = /* @__PURE__ */ new WeakMap();
|
|
4024
|
+
async function runBenchmarkSuite(suite, runner) {
|
|
4025
|
+
const { Task, Bench } = await runner.importTinybench();
|
|
4026
|
+
const start = performance.now();
|
|
4027
|
+
const benchmarkGroup = [];
|
|
4028
|
+
const benchmarkSuiteGroup = [];
|
|
4029
|
+
for (const task of suite.tasks) {
|
|
4030
|
+
if (task.mode !== "run" && task.mode !== "queued") continue;
|
|
4031
|
+
if (task.meta?.benchmark) benchmarkGroup.push(task);
|
|
4032
|
+
else if (task.type === "suite") benchmarkSuiteGroup.push(task);
|
|
4033
|
+
}
|
|
4034
|
+
// run sub suites sequentially
|
|
4035
|
+
for (const subSuite of benchmarkSuiteGroup) await runBenchmarkSuite(subSuite, runner);
|
|
4036
|
+
if (benchmarkGroup.length) {
|
|
4037
|
+
const defer = createDefer();
|
|
4038
|
+
suite.result = {
|
|
4039
|
+
state: "run",
|
|
4040
|
+
startTime: start,
|
|
4041
|
+
benchmark: createBenchmarkResult(suite.name)
|
|
4042
|
+
};
|
|
4043
|
+
updateTask$1("suite-prepare", suite);
|
|
4044
|
+
const addBenchTaskListener = (task, benchmark) => {
|
|
4045
|
+
task.addEventListener("complete", (e) => {
|
|
4046
|
+
const taskRes = e.task.result;
|
|
4047
|
+
const result = benchmark.result.benchmark;
|
|
4048
|
+
benchmark.result.state = "pass";
|
|
4049
|
+
Object.assign(result, taskRes);
|
|
4050
|
+
// compute extra stats and free raw samples as early as possible
|
|
4051
|
+
const samples = result.samples;
|
|
4052
|
+
result.sampleCount = samples.length;
|
|
4053
|
+
result.median = samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2;
|
|
4054
|
+
if (!runner.config.benchmark?.includeSamples) result.samples.length = 0;
|
|
4055
|
+
updateTask$1("test-finished", benchmark);
|
|
4056
|
+
}, { once: true });
|
|
4057
|
+
task.addEventListener("error", (e) => {
|
|
4058
|
+
const task = e.task;
|
|
4059
|
+
defer.reject(benchmark ? task.result.error : e);
|
|
4060
|
+
}, { once: true });
|
|
4061
|
+
};
|
|
4062
|
+
benchmarkGroup.forEach((benchmark) => {
|
|
4063
|
+
const benchmarkInstance = new Bench(getBenchOptions(benchmark));
|
|
4064
|
+
const benchmarkFn = getBenchFn(benchmark);
|
|
4065
|
+
benchmark.result = {
|
|
4066
|
+
state: "run",
|
|
4067
|
+
startTime: start,
|
|
4068
|
+
benchmark: createBenchmarkResult(benchmark.name)
|
|
4069
|
+
};
|
|
4070
|
+
const task = new Task(benchmarkInstance, benchmark.name, benchmarkFn);
|
|
4071
|
+
benchmarkTasks.set(benchmark, task);
|
|
4072
|
+
addBenchTaskListener(task, benchmark);
|
|
4073
|
+
});
|
|
4074
|
+
const { setTimeout } = getSafeTimers();
|
|
4075
|
+
const tasks = [];
|
|
4076
|
+
for (const benchmark of benchmarkGroup) {
|
|
4077
|
+
const task = benchmarkTasks.get(benchmark);
|
|
4078
|
+
updateTask$1("test-prepare", benchmark);
|
|
4079
|
+
await task.warmup();
|
|
4080
|
+
tasks.push([await new Promise((resolve) => setTimeout(async () => {
|
|
4081
|
+
resolve(await task.run());
|
|
4082
|
+
})), benchmark]);
|
|
4083
|
+
}
|
|
4084
|
+
suite.result.duration = performance.now() - start;
|
|
4085
|
+
suite.result.state = "pass";
|
|
4086
|
+
updateTask$1("suite-finished", suite);
|
|
4087
|
+
defer.resolve(null);
|
|
4088
|
+
await defer;
|
|
4089
|
+
}
|
|
4090
|
+
function updateTask$1(event, task) {
|
|
4091
|
+
updateTask(event, task, runner);
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
class NodeBenchmarkRunner {
|
|
4095
|
+
moduleRunner;
|
|
4096
|
+
constructor(config) {
|
|
4097
|
+
this.config = config;
|
|
4098
|
+
}
|
|
4099
|
+
async importTinybench() {
|
|
4100
|
+
return await import('../vendor/tinybench.mjs');
|
|
4101
|
+
}
|
|
4102
|
+
importFile(filepath, source) {
|
|
4103
|
+
if (source === "setup") {
|
|
4104
|
+
const moduleNode = getWorkerState().evaluatedModules.getModuleById(filepath);
|
|
4105
|
+
if (moduleNode) getWorkerState().evaluatedModules.invalidateModule(moduleNode);
|
|
4106
|
+
}
|
|
4107
|
+
return this.moduleRunner.import(filepath);
|
|
4108
|
+
}
|
|
4109
|
+
async runSuite(suite) {
|
|
4110
|
+
await runBenchmarkSuite(suite, this);
|
|
4111
|
+
}
|
|
4112
|
+
async runTask() {
|
|
4113
|
+
throw new Error("`test()` and `it()` is only available in test mode.");
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
class TestRunner {
|
|
4118
|
+
snapshotClient = getSnapshotClient();
|
|
4119
|
+
workerState = getWorkerState();
|
|
4120
|
+
moduleRunner;
|
|
4121
|
+
cancelRun = false;
|
|
4122
|
+
assertionsErrors = /* @__PURE__ */ new WeakMap();
|
|
4123
|
+
pool = this.workerState.ctx.pool;
|
|
4124
|
+
_otel;
|
|
4125
|
+
viteEnvironment;
|
|
4126
|
+
viteModuleRunner;
|
|
4127
|
+
constructor(config) {
|
|
4128
|
+
this.config = config;
|
|
4129
|
+
const environment = this.workerState.environment;
|
|
4130
|
+
this.viteEnvironment = environment.viteEnvironment || environment.name;
|
|
4131
|
+
this.viteModuleRunner = config.experimental.viteModuleRunner;
|
|
4132
|
+
}
|
|
4133
|
+
importFile(filepath, source) {
|
|
4134
|
+
if (source === "setup") {
|
|
4135
|
+
const moduleNode = this.workerState.evaluatedModules.getModuleById(filepath);
|
|
4136
|
+
if (moduleNode) this.workerState.evaluatedModules.invalidateModule(moduleNode);
|
|
4137
|
+
}
|
|
4138
|
+
return this._otel.$(`vitest.module.import_${source === "setup" ? "setup" : "spec"}`, { attributes: { "code.file.path": filepath } }, () => {
|
|
4139
|
+
if (!this.viteModuleRunner) filepath = `${filepath}?vitest=${Date.now()}`;
|
|
4140
|
+
return this.moduleRunner.import(filepath);
|
|
4141
|
+
});
|
|
4142
|
+
}
|
|
4143
|
+
onCollectStart(file) {
|
|
4144
|
+
this.workerState.current = file;
|
|
4145
|
+
}
|
|
4146
|
+
onCleanupWorkerContext(listener) {
|
|
4147
|
+
this.workerState.onCleanup(listener);
|
|
4148
|
+
}
|
|
4149
|
+
onAfterRunFiles() {
|
|
4150
|
+
this.snapshotClient.clear();
|
|
4151
|
+
this.workerState.current = void 0;
|
|
4152
|
+
}
|
|
4153
|
+
async onAfterRunSuite(suite) {
|
|
4154
|
+
if (this.config.logHeapUsage && typeof process !== "undefined") suite.result.heap = process.memoryUsage().heapUsed;
|
|
4155
|
+
if (suite.mode !== "skip" && "filepath" in suite) {
|
|
4156
|
+
// mark snapshots in skipped tests as not obsolete
|
|
4157
|
+
for (const test of getTests(suite)) if (test.mode === "skip") {
|
|
4158
|
+
const name = getNames(test).slice(1).join(" > ");
|
|
4159
|
+
this.snapshotClient.skipTest(suite.file.filepath, name);
|
|
4160
|
+
}
|
|
4161
|
+
const result = await this.snapshotClient.finish(suite.file.filepath);
|
|
4162
|
+
if (this.workerState.config.snapshotOptions.updateSnapshot === "none" && result.unchecked) {
|
|
4163
|
+
let message = `Obsolete snapshots found when no snapshot update is expected.\n`;
|
|
4164
|
+
for (const key of result.uncheckedKeys) message += `· ${key}\n`;
|
|
4165
|
+
suite.result.errors ??= [];
|
|
4166
|
+
suite.result.errors.push(processError(new Error(message)));
|
|
4167
|
+
suite.result.state = "fail";
|
|
4168
|
+
}
|
|
4169
|
+
await rpc().snapshotSaved(result);
|
|
4170
|
+
}
|
|
4171
|
+
this.workerState.current = suite.suite || suite.file;
|
|
4172
|
+
}
|
|
4173
|
+
onAfterRunTask(test) {
|
|
4174
|
+
if (this.config.logHeapUsage && typeof process !== "undefined") test.result.heap = process.memoryUsage().heapUsed;
|
|
4175
|
+
this.workerState.current = test.suite || test.file;
|
|
4176
|
+
}
|
|
4177
|
+
cancel(_reason) {
|
|
4178
|
+
this.cancelRun = true;
|
|
4179
|
+
}
|
|
4180
|
+
injectValue(key) {
|
|
4181
|
+
// inject has a very limiting type controlled by ProvidedContext
|
|
4182
|
+
// some tests override it which causes the build to fail
|
|
4183
|
+
return inject(key);
|
|
4184
|
+
}
|
|
4185
|
+
async onBeforeRunTask(test) {
|
|
4186
|
+
if (this.cancelRun) test.mode = "skip";
|
|
4187
|
+
if (test.mode !== "run" && test.mode !== "queued") return;
|
|
4188
|
+
this.workerState.current = test;
|
|
4189
|
+
}
|
|
4190
|
+
async onBeforeRunSuite(suite) {
|
|
4191
|
+
if (this.cancelRun) suite.mode = "skip";
|
|
4192
|
+
// initialize snapshot state before running file suite
|
|
4193
|
+
if (suite.mode !== "skip" && "filepath" in suite) await this.snapshotClient.setup(suite.file.filepath, this.workerState.config.snapshotOptions);
|
|
4194
|
+
this.workerState.current = suite;
|
|
4195
|
+
}
|
|
4196
|
+
onBeforeTryTask(test) {
|
|
4197
|
+
clearModuleMocks(this.config);
|
|
4198
|
+
this.snapshotClient.clearTest(test.file.filepath, test.id);
|
|
4199
|
+
setState({
|
|
4200
|
+
assertionCalls: 0,
|
|
4201
|
+
isExpectingAssertions: false,
|
|
4202
|
+
isExpectingAssertionsError: null,
|
|
4203
|
+
expectedAssertionsNumber: null,
|
|
4204
|
+
expectedAssertionsNumberErrorGen: null,
|
|
4205
|
+
currentTestName: getTestName(test),
|
|
4206
|
+
snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath)
|
|
4207
|
+
}, globalThis[GLOBAL_EXPECT]);
|
|
4208
|
+
}
|
|
4209
|
+
onAfterTryTask(test) {
|
|
4210
|
+
const { assertionCalls, expectedAssertionsNumber, expectedAssertionsNumberErrorGen, isExpectingAssertions, isExpectingAssertionsError } = test.context._local ? test.context.expect.getState() : getState(globalThis[GLOBAL_EXPECT]);
|
|
4211
|
+
if (expectedAssertionsNumber !== null && assertionCalls !== expectedAssertionsNumber) throw expectedAssertionsNumberErrorGen();
|
|
4212
|
+
if (isExpectingAssertions === true && assertionCalls === 0) throw isExpectingAssertionsError;
|
|
4213
|
+
if (this.config.expect.requireAssertions && assertionCalls === 0) throw this.assertionsErrors.get(test);
|
|
4214
|
+
}
|
|
4215
|
+
extendTaskContext(context) {
|
|
4216
|
+
// create error during the test initialization so we have a nice stack trace
|
|
4217
|
+
if (this.config.expect.requireAssertions) this.assertionsErrors.set(context.task, /* @__PURE__ */ new Error("expected any number of assertion, but got none"));
|
|
4218
|
+
let _expect;
|
|
4219
|
+
Object.defineProperty(context, "expect", { get() {
|
|
4220
|
+
if (!_expect) _expect = createExpect(context.task);
|
|
4221
|
+
return _expect;
|
|
4222
|
+
} });
|
|
4223
|
+
Object.defineProperty(context, "_local", { get() {
|
|
4224
|
+
return _expect != null;
|
|
4225
|
+
} });
|
|
4226
|
+
return context;
|
|
4227
|
+
}
|
|
4228
|
+
getImportDurations() {
|
|
4229
|
+
const { limit } = this.config.experimental.importDurations;
|
|
4230
|
+
// skip sorting if limit is 0
|
|
4231
|
+
if (limit === 0) return {};
|
|
4232
|
+
// Sort by duration descending and keep top entries
|
|
4233
|
+
const sortedEntries = [...this.workerState.moduleExecutionInfo?.entries() || []].sort(([, a], [, b]) => b.duration - a.duration).slice(0, limit);
|
|
4234
|
+
const importDurations = {};
|
|
4235
|
+
for (const [filepath, { duration, selfTime, external, importer }] of sortedEntries) importDurations[normalize(filepath)] = {
|
|
4236
|
+
selfTime,
|
|
4237
|
+
totalTime: duration,
|
|
4238
|
+
external,
|
|
4239
|
+
importer
|
|
4240
|
+
};
|
|
4241
|
+
return importDurations;
|
|
4242
|
+
}
|
|
4243
|
+
trace = (name, attributes, cb) => {
|
|
4244
|
+
const options = typeof attributes === "object" ? { attributes } : {};
|
|
4245
|
+
return this._otel.$(`vitest.test.runner.${name}`, options, cb || attributes);
|
|
4246
|
+
};
|
|
4247
|
+
__setTraces(traces) {
|
|
4248
|
+
this._otel = traces;
|
|
4249
|
+
}
|
|
4250
|
+
static createTaskCollector = createTaskCollector;
|
|
4251
|
+
static getCurrentSuite = getCurrentSuite;
|
|
4252
|
+
static getCurrentTest = getCurrentTest;
|
|
4253
|
+
static createChainable = createChainable;
|
|
4254
|
+
static getSuiteHooks = getHooks;
|
|
4255
|
+
static getTestFn = getFn;
|
|
4256
|
+
static setSuiteHooks = getHooks;
|
|
4257
|
+
static setTestFn = getFn;
|
|
4258
|
+
/**
|
|
4259
|
+
* @deprecated
|
|
4260
|
+
*/
|
|
4261
|
+
static getBenchFn = getBenchFn;
|
|
4262
|
+
/**
|
|
4263
|
+
* @deprecated
|
|
4264
|
+
*/
|
|
4265
|
+
static getBenchOptions = getBenchOptions;
|
|
4266
|
+
}
|
|
4267
|
+
function clearModuleMocks(config) {
|
|
4268
|
+
const { clearMocks, mockReset, restoreMocks, unstubEnvs, unstubGlobals } = config;
|
|
4269
|
+
if (restoreMocks) vi.restoreAllMocks();
|
|
4270
|
+
if (mockReset) vi.resetAllMocks();
|
|
4271
|
+
if (clearMocks) vi.clearAllMocks();
|
|
4272
|
+
if (unstubEnvs) vi.unstubAllEnvs();
|
|
4273
|
+
if (unstubGlobals) vi.unstubAllGlobals();
|
|
4274
|
+
}
|
|
4275
|
+
|
|
4276
|
+
export { NodeBenchmarkRunner as N, TestRunner as T, assert as a, vitest as b, createExpect as c, globalExpect as g, inject as i, should as s, vi as v };
|