@voidzero-dev/vite-plus-test 0.0.0-0bfcc90f.20260209-0731
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 +691 -0
- package/browser/context.d.ts +4 -0
- package/browser/context.js +20 -0
- package/config.d.ts +3 -0
- package/coverage.d.ts +1 -0
- package/dist/@vitest/browser/client/.vite/manifest.json +24 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/@vitest/browser/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/@vitest/browser/client/__vitest__/bg.png +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.ico +0 -0
- package/dist/@vitest/browser/client/__vitest__/favicon.svg +5 -0
- package/dist/@vitest/browser/client/__vitest__/index.html +32 -0
- package/dist/@vitest/browser/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/@vitest/browser/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/@vitest/browser/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/@vitest/browser/client/error-catcher.js +82 -0
- package/dist/@vitest/browser/client/esm-client-injector.js +67 -0
- package/dist/@vitest/browser/client/favicon.svg +5 -0
- package/dist/@vitest/browser/client/orchestrator.html +35 -0
- package/dist/@vitest/browser/client/tester/tester.html +13 -0
- package/dist/@vitest/browser/client.js +456 -0
- package/dist/@vitest/browser/context.d.ts +792 -0
- package/dist/@vitest/browser/context.js +541 -0
- package/dist/@vitest/browser/expect-element.js +32 -0
- package/dist/@vitest/browser/index-D6m36C6U.js +11 -0
- package/dist/@vitest/browser/index.d.ts +73 -0
- package/dist/@vitest/browser/index.js +3513 -0
- package/dist/@vitest/browser/jest-dom.d.ts +724 -0
- package/dist/@vitest/browser/locators.d.ts +354 -0
- package/dist/@vitest/browser/locators.js +1 -0
- package/dist/@vitest/browser/matchers.d.ts +29 -0
- package/dist/@vitest/browser/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/@vitest/browser/state.js +280 -0
- package/dist/@vitest/browser/types.d.ts +69 -0
- package/dist/@vitest/browser-playwright/context.d.ts +1 -0
- package/dist/@vitest/browser-playwright/index.d.ts +106 -0
- package/dist/@vitest/browser-playwright/index.js +1111 -0
- package/dist/@vitest/browser-playwright/locators.js +114 -0
- package/dist/@vitest/browser-preview/context.d.ts +1 -0
- package/dist/@vitest/browser-preview/index.d.ts +19 -0
- package/dist/@vitest/browser-preview/index.js +148 -0
- package/dist/@vitest/browser-preview/locators.js +79 -0
- package/dist/@vitest/browser-webdriverio/context.d.ts +1 -0
- package/dist/@vitest/browser-webdriverio/index.d.ts +63 -0
- package/dist/@vitest/browser-webdriverio/index.js +600 -0
- package/dist/@vitest/browser-webdriverio/locators.js +163 -0
- package/dist/@vitest/expect/index.d.ts +807 -0
- package/dist/@vitest/expect/index.js +1875 -0
- package/dist/@vitest/mocker/auto-register.d.ts +2 -0
- package/dist/@vitest/mocker/auto-register.js +9 -0
- package/dist/@vitest/mocker/automock.d.ts +12 -0
- package/dist/@vitest/mocker/automock.js +1 -0
- package/dist/@vitest/mocker/browser.d.ts +53 -0
- package/dist/@vitest/mocker/browser.js +91 -0
- package/dist/@vitest/mocker/chunk-automock.js +354 -0
- package/dist/@vitest/mocker/chunk-interceptor-native.js +15 -0
- package/dist/@vitest/mocker/chunk-mocker.js +521 -0
- package/dist/@vitest/mocker/chunk-pathe.M-eThtNZ.js +174 -0
- package/dist/@vitest/mocker/chunk-registry.js +185 -0
- package/dist/@vitest/mocker/chunk-utils.js +16 -0
- package/dist/@vitest/mocker/index.d-C-sLYZi-.d.ts +25 -0
- package/dist/@vitest/mocker/index.d.ts +2 -0
- package/dist/@vitest/mocker/index.js +185 -0
- package/dist/@vitest/mocker/mocker.d-TnKRhz7N.d.ts +81 -0
- package/dist/@vitest/mocker/node.d.ts +800 -0
- package/dist/@vitest/mocker/node.js +966 -0
- package/dist/@vitest/mocker/redirect.d.ts +3 -0
- package/dist/@vitest/mocker/redirect.js +79 -0
- package/dist/@vitest/mocker/register.d.ts +9 -0
- package/dist/@vitest/mocker/register.js +41 -0
- package/dist/@vitest/mocker/types.d-B8CCKmHt.d.ts +107 -0
- package/dist/@vitest/pretty-format/index.d.ts +124 -0
- package/dist/@vitest/pretty-format/index.js +1022 -0
- package/dist/@vitest/runner/chunk-tasks.js +340 -0
- package/dist/@vitest/runner/index.d.ts +180 -0
- package/dist/@vitest/runner/index.js +2114 -0
- package/dist/@vitest/runner/tasks.d-C7UxawJ9.d.ts +834 -0
- package/dist/@vitest/runner/types.d.ts +183 -0
- package/dist/@vitest/runner/types.js +1 -0
- package/dist/@vitest/runner/utils.d.ts +45 -0
- package/dist/@vitest/runner/utils.js +5 -0
- package/dist/@vitest/snapshot/environment.d-DHdQ1Csl.d.ts +22 -0
- package/dist/@vitest/snapshot/environment.d.ts +16 -0
- package/dist/@vitest/snapshot/environment.js +40 -0
- package/dist/@vitest/snapshot/index.d.ts +130 -0
- package/dist/@vitest/snapshot/index.js +1437 -0
- package/dist/@vitest/snapshot/manager.d.ts +18 -0
- package/dist/@vitest/snapshot/manager.js +73 -0
- package/dist/@vitest/snapshot/rawSnapshot.d-lFsMJFUd.d.ts +61 -0
- package/dist/@vitest/spy/index.d.ts +384 -0
- package/dist/@vitest/spy/index.js +433 -0
- package/dist/@vitest/utils/chunk-_commonjsHelpers.js +5 -0
- package/dist/@vitest/utils/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/@vitest/utils/constants.d.ts +21 -0
- package/dist/@vitest/utils/constants.js +49 -0
- package/dist/@vitest/utils/diff.d.ts +93 -0
- package/dist/@vitest/utils/diff.js +2199 -0
- package/dist/@vitest/utils/display.d.ts +29 -0
- package/dist/@vitest/utils/display.js +742 -0
- package/dist/@vitest/utils/error.d.ts +7 -0
- package/dist/@vitest/utils/error.js +42 -0
- package/dist/@vitest/utils/helpers.d.ts +73 -0
- package/dist/@vitest/utils/helpers.js +295 -0
- package/dist/@vitest/utils/highlight.d.ts +9 -0
- package/dist/@vitest/utils/highlight.js +538 -0
- package/dist/@vitest/utils/index.d.ts +5 -0
- package/dist/@vitest/utils/index.js +1 -0
- package/dist/@vitest/utils/offset.d.ts +5 -0
- package/dist/@vitest/utils/offset.js +32 -0
- package/dist/@vitest/utils/resolver.d.ts +7 -0
- package/dist/@vitest/utils/resolver.js +71 -0
- package/dist/@vitest/utils/serialize.d.ts +3 -0
- package/dist/@vitest/utils/serialize.js +118 -0
- package/dist/@vitest/utils/source-map.d.ts +55 -0
- package/dist/@vitest/utils/source-map.js +478 -0
- package/dist/@vitest/utils/timers.d.ts +33 -0
- package/dist/@vitest/utils/timers.js +49 -0
- package/dist/@vitest/utils/types.d-BCElaP-c.d.ts +53 -0
- package/dist/@vitest/utils/types.d.ts +34 -0
- package/dist/@vitest/utils/types.js +1 -0
- package/dist/browser-compat.js +3 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +20 -0
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
- package/dist/chunks/base.CJ0Y4ePK.js +165 -0
- package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
- package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
- package/dist/chunks/cac.DVeoLl0M.js +1409 -0
- package/dist/chunks/cli-api.B7PN_QUv.js +13672 -0
- package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/constants.D_Q9UYh-.js +36 -0
- package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
- package/dist/chunks/coverage.D_JHT54q.js +25 -0
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
- package/dist/chunks/creator.DAmOKTvJ.js +673 -0
- package/dist/chunks/date.Bq6ZW5rf.js +73 -0
- package/dist/chunks/defaults.BOqNVLsY.js +74 -0
- package/dist/chunks/env.D4Lgay0q.js +8 -0
- package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
- package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
- package/dist/chunks/git.Bm2pzPAa.js +71 -0
- package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
- package/dist/chunks/globals.DOayXfHP.js +30 -0
- package/dist/chunks/index.6Qv1eEA6.js +109 -0
- package/dist/chunks/index.C5r1PdPD.js +231 -0
- package/dist/chunks/index.Chj8NDwU.js +206 -0
- package/dist/chunks/index.CyBMJtT7.js +727 -0
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/index.D4KonVSU.js +6343 -0
- package/dist/chunks/index.M8mOzt4Y.js +3839 -0
- package/dist/chunks/index.Z5E_ObnR.js +37 -0
- package/dist/chunks/init-forks._y3TW739.js +41 -0
- package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
- package/dist/chunks/init.B6MLFIaN.js +334 -0
- package/dist/chunks/inspector.CvyFGlXm.js +53 -0
- package/dist/chunks/modules.BJuCwlRJ.js +36 -0
- package/dist/chunks/node.Ce0vMQM7.js +14 -0
- package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
- package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
- package/dist/chunks/rpc.BoxB0q7B.js +76 -0
- package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
- package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
- package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
- package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
- package/dist/chunks/test.B8ej_ZHS.js +254 -0
- package/dist/chunks/traces.CCmnQaNT.js +217 -0
- package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
- package/dist/chunks/utils.DvEY5TfP.js +52 -0
- package/dist/chunks/vi.2VT5v0um.js +3919 -0
- package/dist/chunks/vm.D3epNOPZ.js +744 -0
- package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
- package/dist/cli.js +28 -0
- package/dist/client/.vite/manifest.json +24 -0
- package/dist/client/__vitest__/assets/index-BUCFJtth.js +57 -0
- package/dist/client/__vitest__/assets/index-DlhE0rqZ.css +1 -0
- package/dist/client/__vitest__/bg.png +0 -0
- package/dist/client/__vitest__/favicon.ico +0 -0
- package/dist/client/__vitest__/favicon.svg +5 -0
- package/dist/client/__vitest__/index.html +32 -0
- package/dist/client/__vitest_browser__/orchestrator-S_3e_uzt.js +345 -0
- package/dist/client/__vitest_browser__/tester-k74mgIRa.js +2171 -0
- package/dist/client/__vitest_browser__/utils-uxqdqUz8.js +223 -0
- package/dist/client/error-catcher.js +82 -0
- package/dist/client/esm-client-injector.js +67 -0
- package/dist/client/favicon.svg +5 -0
- package/dist/client/orchestrator.html +35 -0
- package/dist/client/tester/tester.html +13 -0
- package/dist/client.js +456 -0
- package/dist/config.cjs +94 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.js +15 -0
- package/dist/context.js +541 -0
- package/dist/coverage.d.ts +118 -0
- package/dist/coverage.js +23 -0
- package/dist/dummy.js +2 -0
- package/dist/environments.d.ts +22 -0
- package/dist/environments.js +3 -0
- package/dist/expect-element.js +27 -0
- package/dist/index-D6m36C6U.js +6 -0
- package/dist/index-node.js +7 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +19 -0
- package/dist/locators.d.ts +354 -0
- package/dist/locators.js +1 -0
- package/dist/mocker.d.ts +1 -0
- package/dist/mocker.js +1 -0
- package/dist/module-evaluator.d.ts +124 -0
- package/dist/module-evaluator.js +343 -0
- package/dist/module-runner-stub.js +44 -0
- package/dist/module-runner.js +17 -0
- package/dist/node.d.ts +251 -0
- package/dist/node.js +98 -0
- package/dist/path.js +7 -0
- package/dist/plugins/browser-client.mjs +2 -0
- package/dist/plugins/browser-context.mjs +2 -0
- package/dist/plugins/browser-locators.mjs +2 -0
- package/dist/plugins/browser-playwright.mjs +2 -0
- package/dist/plugins/browser-preview.mjs +2 -0
- package/dist/plugins/browser-webdriverio.mjs +2 -0
- package/dist/plugins/browser.mjs +2 -0
- package/dist/plugins/expect.mjs +2 -0
- package/dist/plugins/mocker-automock.mjs +2 -0
- package/dist/plugins/mocker-browser.mjs +2 -0
- package/dist/plugins/mocker-node.mjs +2 -0
- package/dist/plugins/mocker-redirect.mjs +2 -0
- package/dist/plugins/mocker-register.mjs +2 -0
- package/dist/plugins/mocker.mjs +2 -0
- package/dist/plugins/pretty-format.mjs +2 -0
- package/dist/plugins/runner-types.mjs +2 -0
- package/dist/plugins/runner-utils.mjs +2 -0
- package/dist/plugins/runner.mjs +2 -0
- package/dist/plugins/snapshot-environment.mjs +2 -0
- package/dist/plugins/snapshot-manager.mjs +2 -0
- package/dist/plugins/snapshot.mjs +2 -0
- package/dist/plugins/spy.mjs +2 -0
- package/dist/plugins/utils-constants.mjs +2 -0
- package/dist/plugins/utils-diff.mjs +2 -0
- package/dist/plugins/utils-display.mjs +2 -0
- package/dist/plugins/utils-error.mjs +2 -0
- package/dist/plugins/utils-helpers.mjs +2 -0
- package/dist/plugins/utils-highlight.mjs +2 -0
- package/dist/plugins/utils-offset.mjs +2 -0
- package/dist/plugins/utils-resolver.mjs +2 -0
- package/dist/plugins/utils-serialize.mjs +2 -0
- package/dist/plugins/utils-source-map.mjs +2 -0
- package/dist/plugins/utils-timers.mjs +2 -0
- package/dist/plugins/utils.mjs +2 -0
- package/dist/reporters.d.ts +27 -0
- package/dist/reporters.js +24 -0
- package/dist/runners.d.ts +50 -0
- package/dist/runners.js +19 -0
- package/dist/shared/screenshotMatcher/types.d.ts +22 -0
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +4 -0
- package/dist/spy.js +1 -0
- package/dist/state.js +280 -0
- package/dist/suite.d.ts +5 -0
- package/dist/suite.js +6 -0
- package/dist/types.d.ts +69 -0
- package/dist/vendor/chai.d.mts +1 -0
- package/dist/vendor/chai.mjs +3577 -0
- package/dist/vendor/es-module-lexer.d.mts +193 -0
- package/dist/vendor/es-module-lexer.mjs +79 -0
- package/dist/vendor/estree-walker.d.mts +583 -0
- package/dist/vendor/estree-walker.mjs +339 -0
- package/dist/vendor/expect-type.d.mts +1574 -0
- package/dist/vendor/expect-type.mjs +214 -0
- package/dist/vendor/magic-string.d.mts +261 -0
- package/dist/vendor/magic-string.mjs +1700 -0
- package/dist/vendor/obug.d.mts +56 -0
- package/dist/vendor/obug.mjs +276 -0
- package/dist/vendor/pathe.d.mts +46 -0
- package/dist/vendor/pathe.mjs +496 -0
- package/dist/vendor/picomatch.d.mts +1 -0
- package/dist/vendor/picomatch.mjs +1855 -0
- package/dist/vendor/shared-3g9mwCWP.mjs +31 -0
- package/dist/vendor/std-env.d.mts +88 -0
- package/dist/vendor/std-env.mjs +159 -0
- package/dist/vendor/tinybench.d.mts +317 -0
- package/dist/vendor/tinybench.mjs +504 -0
- package/dist/vendor/tinyexec.d.mts +72 -0
- package/dist/vendor/tinyexec.mjs +637 -0
- package/dist/vendor/tinyglobby.d.mts +157 -0
- package/dist/vendor/tinyglobby.mjs +832 -0
- package/dist/vendor/tinyrainbow.d.mts +60 -0
- package/dist/vendor/tinyrainbow.mjs +93 -0
- package/dist/vendor/vitest_browser.mjs +2 -0
- package/dist/vendor/vitest_internal_browser.mjs +2 -0
- package/dist/vendor/vitest_runner.mjs +2 -0
- package/dist/vendor/vitest_runners.mjs +2 -0
- package/dist/worker.d.ts +32 -0
- package/dist/worker.js +48 -0
- package/dist/workers/forks.js +54 -0
- package/dist/workers/runVmTests.js +95 -0
- package/dist/workers/threads.js +55 -0
- package/dist/workers/vmForks.js +36 -0
- package/dist/workers/vmThreads.js +37 -0
- package/environments.d.ts +1 -0
- package/globals.d.ts +20 -0
- package/import-meta.d.ts +5 -0
- package/importMeta.d.ts +4 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/jsdom.d.ts +6 -0
- package/mocker.d.ts +1 -0
- package/node.d.ts +1 -0
- package/optional-types.d.ts +7 -0
- package/package.json +335 -0
- package/reporters.d.ts +1 -0
- package/runners.d.ts +1 -0
- package/snapshot.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/suppress-warnings.cjs +21 -0
- package/vitest.mjs +2 -0
- package/worker.d.ts +1 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
function isMockFunction(fn) {
|
|
2
|
+
return typeof fn === "function" && "_isMockFunction" in fn && fn._isMockFunction === true;
|
|
3
|
+
}
|
|
4
|
+
const MOCK_RESTORE = new Set();
|
|
5
|
+
// Jest keeps the state in a separate WeakMap which is good for memory,
|
|
6
|
+
// but it makes the state slower to access and return different values
|
|
7
|
+
// if you stored it before calling `mockClear` where it will be recreated
|
|
8
|
+
const REGISTERED_MOCKS = new Set();
|
|
9
|
+
const MOCK_CONFIGS = new WeakMap();
|
|
10
|
+
function createMockInstance(options = {}) {
|
|
11
|
+
var _ref;
|
|
12
|
+
const { originalImplementation, restore, mockImplementation, resetToMockImplementation, resetToMockName } = options;
|
|
13
|
+
if (restore) {
|
|
14
|
+
MOCK_RESTORE.add(restore);
|
|
15
|
+
}
|
|
16
|
+
const config = getDefaultConfig(originalImplementation);
|
|
17
|
+
const state = getDefaultState();
|
|
18
|
+
const mock = createMock({
|
|
19
|
+
config,
|
|
20
|
+
state,
|
|
21
|
+
...options
|
|
22
|
+
});
|
|
23
|
+
const mockLength = ((_ref = mockImplementation || originalImplementation) === null || _ref === void 0 ? void 0 : _ref.length) ?? 0;
|
|
24
|
+
Object.defineProperty(mock, "length", {
|
|
25
|
+
writable: true,
|
|
26
|
+
enumerable: false,
|
|
27
|
+
value: mockLength,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
// inherit the default name so it appears in snapshots and logs
|
|
31
|
+
// this is used by `vi.spyOn()` for better debugging.
|
|
32
|
+
// when `vi.fn()` is called, we just use the default string
|
|
33
|
+
if (resetToMockName) {
|
|
34
|
+
config.mockName = mock.name || "vi.fn()";
|
|
35
|
+
}
|
|
36
|
+
MOCK_CONFIGS.set(mock, config);
|
|
37
|
+
REGISTERED_MOCKS.add(mock);
|
|
38
|
+
mock._isMockFunction = true;
|
|
39
|
+
mock.getMockImplementation = () => {
|
|
40
|
+
// Jest only returns `config.mockImplementation` here,
|
|
41
|
+
// but we think it makes sense to return what the next function will be called
|
|
42
|
+
return config.onceMockImplementations[0] || config.mockImplementation;
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(mock, "mock", {
|
|
45
|
+
configurable: false,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
writable: false,
|
|
48
|
+
value: state
|
|
49
|
+
});
|
|
50
|
+
mock.mockImplementation = function mockImplementation(implementation) {
|
|
51
|
+
config.mockImplementation = implementation;
|
|
52
|
+
return mock;
|
|
53
|
+
};
|
|
54
|
+
mock.mockImplementationOnce = function mockImplementationOnce(implementation) {
|
|
55
|
+
config.onceMockImplementations.push(implementation);
|
|
56
|
+
return mock;
|
|
57
|
+
};
|
|
58
|
+
mock.withImplementation = function withImplementation(implementation, callback) {
|
|
59
|
+
const previousImplementation = config.mockImplementation;
|
|
60
|
+
const previousOnceImplementations = config.onceMockImplementations;
|
|
61
|
+
const reset = () => {
|
|
62
|
+
config.mockImplementation = previousImplementation;
|
|
63
|
+
config.onceMockImplementations = previousOnceImplementations;
|
|
64
|
+
};
|
|
65
|
+
config.mockImplementation = implementation;
|
|
66
|
+
config.onceMockImplementations = [];
|
|
67
|
+
const returnValue = callback();
|
|
68
|
+
if (typeof returnValue === "object" && typeof (returnValue === null || returnValue === void 0 ? void 0 : returnValue.then) === "function") {
|
|
69
|
+
return returnValue.then(() => {
|
|
70
|
+
reset();
|
|
71
|
+
return mock;
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
reset();
|
|
75
|
+
}
|
|
76
|
+
return mock;
|
|
77
|
+
};
|
|
78
|
+
mock.mockReturnThis = function mockReturnThis() {
|
|
79
|
+
return mock.mockImplementation(function() {
|
|
80
|
+
return this;
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
mock.mockReturnValue = function mockReturnValue(value) {
|
|
84
|
+
return mock.mockImplementation(() => value);
|
|
85
|
+
};
|
|
86
|
+
mock.mockReturnValueOnce = function mockReturnValueOnce(value) {
|
|
87
|
+
return mock.mockImplementationOnce(() => value);
|
|
88
|
+
};
|
|
89
|
+
mock.mockResolvedValue = function mockResolvedValue(value) {
|
|
90
|
+
return mock.mockImplementation(() => Promise.resolve(value));
|
|
91
|
+
};
|
|
92
|
+
mock.mockResolvedValueOnce = function mockResolvedValueOnce(value) {
|
|
93
|
+
return mock.mockImplementationOnce(() => Promise.resolve(value));
|
|
94
|
+
};
|
|
95
|
+
mock.mockRejectedValue = function mockRejectedValue(value) {
|
|
96
|
+
return mock.mockImplementation(() => Promise.reject(value));
|
|
97
|
+
};
|
|
98
|
+
mock.mockRejectedValueOnce = function mockRejectedValueOnce(value) {
|
|
99
|
+
return mock.mockImplementationOnce(() => Promise.reject(value));
|
|
100
|
+
};
|
|
101
|
+
mock.mockClear = function mockClear() {
|
|
102
|
+
state.calls = [];
|
|
103
|
+
state.contexts = [];
|
|
104
|
+
state.instances = [];
|
|
105
|
+
state.invocationCallOrder = [];
|
|
106
|
+
state.results = [];
|
|
107
|
+
state.settledResults = [];
|
|
108
|
+
return mock;
|
|
109
|
+
};
|
|
110
|
+
mock.mockReset = function mockReset() {
|
|
111
|
+
mock.mockClear();
|
|
112
|
+
config.mockImplementation = resetToMockImplementation ? mockImplementation : undefined;
|
|
113
|
+
config.mockName = resetToMockName ? mock.name || "vi.fn()" : "vi.fn()";
|
|
114
|
+
config.onceMockImplementations = [];
|
|
115
|
+
return mock;
|
|
116
|
+
};
|
|
117
|
+
mock.mockRestore = function mockRestore() {
|
|
118
|
+
mock.mockReset();
|
|
119
|
+
return restore === null || restore === void 0 ? void 0 : restore();
|
|
120
|
+
};
|
|
121
|
+
mock.mockName = function mockName(name) {
|
|
122
|
+
if (typeof name === "string") {
|
|
123
|
+
config.mockName = name;
|
|
124
|
+
}
|
|
125
|
+
return mock;
|
|
126
|
+
};
|
|
127
|
+
mock.getMockName = function getMockName() {
|
|
128
|
+
return config.mockName || "vi.fn()";
|
|
129
|
+
};
|
|
130
|
+
if (Symbol.dispose) {
|
|
131
|
+
mock[Symbol.dispose] = () => mock.mockRestore();
|
|
132
|
+
}
|
|
133
|
+
if (mockImplementation) {
|
|
134
|
+
mock.mockImplementation(mockImplementation);
|
|
135
|
+
}
|
|
136
|
+
return mock;
|
|
137
|
+
}
|
|
138
|
+
function fn(originalImplementation) {
|
|
139
|
+
// if the function is already a mock, just return the same function,
|
|
140
|
+
// simillarly to how vi.spyOn() works
|
|
141
|
+
if (originalImplementation != null && isMockFunction(originalImplementation)) {
|
|
142
|
+
return originalImplementation;
|
|
143
|
+
}
|
|
144
|
+
return createMockInstance({
|
|
145
|
+
mockImplementation: originalImplementation,
|
|
146
|
+
resetToMockImplementation: true
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function spyOn(object, key, accessor) {
|
|
150
|
+
assert(object != null, "The vi.spyOn() function could not find an object to spy upon. The first argument must be defined.");
|
|
151
|
+
assert(typeof object === "object" || typeof object === "function", "Vitest cannot spy on a primitive value.");
|
|
152
|
+
const [originalDescriptorObject, originalDescriptor] = getDescriptor(object, key) || [];
|
|
153
|
+
assert(originalDescriptor || key in object, `The property "${String(key)}" is not defined on the ${typeof object}.`);
|
|
154
|
+
let accessType = accessor || "value";
|
|
155
|
+
let ssr = false;
|
|
156
|
+
// vite ssr support - actual function is stored inside a getter
|
|
157
|
+
if (accessType === "value" && originalDescriptor && originalDescriptor.value == null && originalDescriptor.get) {
|
|
158
|
+
accessType = "get";
|
|
159
|
+
ssr = true;
|
|
160
|
+
}
|
|
161
|
+
let original;
|
|
162
|
+
if (originalDescriptor) {
|
|
163
|
+
original = originalDescriptor[accessType];
|
|
164
|
+
} else if (accessType !== "value") {
|
|
165
|
+
original = () => object[key];
|
|
166
|
+
} else {
|
|
167
|
+
original = object[key];
|
|
168
|
+
}
|
|
169
|
+
const originalImplementation = ssr && original ? original() : original;
|
|
170
|
+
const originalType = typeof originalImplementation;
|
|
171
|
+
assert(
|
|
172
|
+
// allow only functions
|
|
173
|
+
originalType === "function" || accessType !== "value" && original == null,
|
|
174
|
+
`vi.spyOn() can only spy on a function. Received ${originalType}.`
|
|
175
|
+
);
|
|
176
|
+
if (isMockFunction(originalImplementation)) {
|
|
177
|
+
return originalImplementation;
|
|
178
|
+
}
|
|
179
|
+
const reassign = (cb) => {
|
|
180
|
+
const { value, ...desc } = originalDescriptor || {
|
|
181
|
+
configurable: true,
|
|
182
|
+
writable: true
|
|
183
|
+
};
|
|
184
|
+
if (accessType !== "value") {
|
|
185
|
+
delete desc.writable;
|
|
186
|
+
}
|
|
187
|
+
desc[accessType] = cb;
|
|
188
|
+
Object.defineProperty(object, key, desc);
|
|
189
|
+
};
|
|
190
|
+
const restore = () => {
|
|
191
|
+
// if method is defined on the prototype, we can just remove it from
|
|
192
|
+
// the current object instead of redefining a copy of it
|
|
193
|
+
if (originalDescriptorObject !== object) {
|
|
194
|
+
Reflect.deleteProperty(object, key);
|
|
195
|
+
} else if (originalDescriptor && !original) {
|
|
196
|
+
Object.defineProperty(object, key, originalDescriptor);
|
|
197
|
+
} else {
|
|
198
|
+
reassign(original);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const mock = createMockInstance({
|
|
202
|
+
restore,
|
|
203
|
+
originalImplementation,
|
|
204
|
+
resetToMockName: true
|
|
205
|
+
});
|
|
206
|
+
try {
|
|
207
|
+
reassign(ssr ? () => mock : mock);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
if (error instanceof TypeError && Symbol.toStringTag && object[Symbol.toStringTag] === "Module" && (error.message.includes("Cannot redefine property") || error.message.includes("Cannot replace module namespace") || error.message.includes("can't redefine non-configurable property"))) {
|
|
210
|
+
throw new TypeError(`Cannot spy on export "${String(key)}". Module namespace is not configurable in ESM. See: https://vitest.dev/guide/browser/#limitations`, { cause: error });
|
|
211
|
+
}
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
return mock;
|
|
215
|
+
}
|
|
216
|
+
function getDescriptor(obj, method) {
|
|
217
|
+
const objDescriptor = Object.getOwnPropertyDescriptor(obj, method);
|
|
218
|
+
if (objDescriptor) {
|
|
219
|
+
return [obj, objDescriptor];
|
|
220
|
+
}
|
|
221
|
+
let currentProto = Object.getPrototypeOf(obj);
|
|
222
|
+
while (currentProto !== null) {
|
|
223
|
+
const descriptor = Object.getOwnPropertyDescriptor(currentProto, method);
|
|
224
|
+
if (descriptor) {
|
|
225
|
+
return [currentProto, descriptor];
|
|
226
|
+
}
|
|
227
|
+
currentProto = Object.getPrototypeOf(currentProto);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function assert(condition, message) {
|
|
231
|
+
if (!condition) {
|
|
232
|
+
throw new Error(message);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
let invocationCallCounter = 1;
|
|
236
|
+
function createMock({ state, config, name: mockName, prototypeState, prototypeConfig, keepMembersImplementation, mockImplementation, prototypeMembers = [] }) {
|
|
237
|
+
const original = config.mockOriginal;
|
|
238
|
+
const pseudoOriginal = mockImplementation;
|
|
239
|
+
const name = mockName || (original === null || original === void 0 ? void 0 : original.name) || "Mock";
|
|
240
|
+
const namedObject = { [name]: (function(...args) {
|
|
241
|
+
registerCalls(args, state, prototypeState);
|
|
242
|
+
registerInvocationOrder(invocationCallCounter++, state, prototypeState);
|
|
243
|
+
const result = {
|
|
244
|
+
type: "incomplete",
|
|
245
|
+
value: undefined
|
|
246
|
+
};
|
|
247
|
+
const settledResult = {
|
|
248
|
+
type: "incomplete",
|
|
249
|
+
value: undefined
|
|
250
|
+
};
|
|
251
|
+
registerResult(result, state, prototypeState);
|
|
252
|
+
registerSettledResult(settledResult, state, prototypeState);
|
|
253
|
+
const context = new.target ? undefined : this;
|
|
254
|
+
const [instanceIndex, instancePrototypeIndex] = registerInstance(context, state, prototypeState);
|
|
255
|
+
const [contextIndex, contextPrototypeIndex] = registerContext(context, state, prototypeState);
|
|
256
|
+
const implementation = config.onceMockImplementations.shift() || config.mockImplementation || (prototypeConfig === null || prototypeConfig === void 0 ? void 0 : prototypeConfig.onceMockImplementations.shift()) || (prototypeConfig === null || prototypeConfig === void 0 ? void 0 : prototypeConfig.mockImplementation) || original || function() {};
|
|
257
|
+
let returnValue;
|
|
258
|
+
let thrownValue;
|
|
259
|
+
let didThrow = false;
|
|
260
|
+
try {
|
|
261
|
+
if (new.target) {
|
|
262
|
+
returnValue = Reflect.construct(implementation, args, new.target);
|
|
263
|
+
// jest calls this before the implementation, but we have to resolve this _after_
|
|
264
|
+
// because we cannot do it before the `Reflect.construct` called the custom implementation.
|
|
265
|
+
// fortunetly, the constructor is always an empty functon because `prototypeMethods`
|
|
266
|
+
// are only used by the automocker, so this doesn't matter
|
|
267
|
+
for (const prop of prototypeMembers) {
|
|
268
|
+
const prototypeMock = returnValue[prop];
|
|
269
|
+
// the method was overidden because of inheritence, ignore it
|
|
270
|
+
// eslint-disable-next-line ts/no-use-before-define
|
|
271
|
+
if (prototypeMock !== mock.prototype[prop]) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const isMock = isMockFunction(prototypeMock);
|
|
275
|
+
const prototypeState = isMock ? prototypeMock.mock : undefined;
|
|
276
|
+
const prototypeConfig = isMock ? MOCK_CONFIGS.get(prototypeMock) : undefined;
|
|
277
|
+
returnValue[prop] = createMockInstance({
|
|
278
|
+
originalImplementation: keepMembersImplementation ? prototypeConfig === null || prototypeConfig === void 0 ? void 0 : prototypeConfig.mockOriginal : undefined,
|
|
279
|
+
prototypeState,
|
|
280
|
+
prototypeConfig,
|
|
281
|
+
keepMembersImplementation
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
returnValue = implementation.apply(this, args);
|
|
286
|
+
}
|
|
287
|
+
} catch (error) {
|
|
288
|
+
thrownValue = error;
|
|
289
|
+
didThrow = true;
|
|
290
|
+
if (error instanceof TypeError && error.message.includes("is not a constructor")) {
|
|
291
|
+
console.warn(`[vitest] The ${namedObject[name].getMockName()} mock did not use 'function' or 'class' in its implementation, see https://vitest.dev/api/vi#vi-spyon for examples.`);
|
|
292
|
+
}
|
|
293
|
+
throw error;
|
|
294
|
+
} finally {
|
|
295
|
+
if (didThrow) {
|
|
296
|
+
result.type = "throw";
|
|
297
|
+
result.value = thrownValue;
|
|
298
|
+
settledResult.type = "rejected";
|
|
299
|
+
settledResult.value = thrownValue;
|
|
300
|
+
} else {
|
|
301
|
+
result.type = "return";
|
|
302
|
+
result.value = returnValue;
|
|
303
|
+
if (new.target) {
|
|
304
|
+
state.contexts[contextIndex - 1] = returnValue;
|
|
305
|
+
state.instances[instanceIndex - 1] = returnValue;
|
|
306
|
+
if (contextPrototypeIndex != null && prototypeState) {
|
|
307
|
+
prototypeState.contexts[contextPrototypeIndex - 1] = returnValue;
|
|
308
|
+
}
|
|
309
|
+
if (instancePrototypeIndex != null && prototypeState) {
|
|
310
|
+
prototypeState.instances[instancePrototypeIndex - 1] = returnValue;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (returnValue instanceof Promise) {
|
|
314
|
+
returnValue.then((settledValue) => {
|
|
315
|
+
settledResult.type = "fulfilled";
|
|
316
|
+
settledResult.value = settledValue;
|
|
317
|
+
}, (rejectedValue) => {
|
|
318
|
+
settledResult.type = "rejected";
|
|
319
|
+
settledResult.value = rejectedValue;
|
|
320
|
+
});
|
|
321
|
+
} else {
|
|
322
|
+
settledResult.type = "fulfilled";
|
|
323
|
+
settledResult.value = returnValue;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return returnValue;
|
|
328
|
+
}) };
|
|
329
|
+
const mock = namedObject[name];
|
|
330
|
+
const copyPropertiesFrom = original || pseudoOriginal;
|
|
331
|
+
if (copyPropertiesFrom) {
|
|
332
|
+
copyOriginalStaticProperties(mock, copyPropertiesFrom);
|
|
333
|
+
}
|
|
334
|
+
return mock;
|
|
335
|
+
}
|
|
336
|
+
function registerCalls(args, state, prototypeState) {
|
|
337
|
+
state.calls.push(args);
|
|
338
|
+
prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.calls.push(args);
|
|
339
|
+
}
|
|
340
|
+
function registerInvocationOrder(order, state, prototypeState) {
|
|
341
|
+
state.invocationCallOrder.push(order);
|
|
342
|
+
prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.invocationCallOrder.push(order);
|
|
343
|
+
}
|
|
344
|
+
function registerResult(result, state, prototypeState) {
|
|
345
|
+
state.results.push(result);
|
|
346
|
+
prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.results.push(result);
|
|
347
|
+
}
|
|
348
|
+
function registerSettledResult(result, state, prototypeState) {
|
|
349
|
+
state.settledResults.push(result);
|
|
350
|
+
prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.settledResults.push(result);
|
|
351
|
+
}
|
|
352
|
+
function registerInstance(instance, state, prototypeState) {
|
|
353
|
+
const instanceIndex = state.instances.push(instance);
|
|
354
|
+
const instancePrototypeIndex = prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.instances.push(instance);
|
|
355
|
+
return [instanceIndex, instancePrototypeIndex];
|
|
356
|
+
}
|
|
357
|
+
function registerContext(context, state, prototypeState) {
|
|
358
|
+
const contextIndex = state.contexts.push(context);
|
|
359
|
+
const contextPrototypeIndex = prototypeState === null || prototypeState === void 0 ? void 0 : prototypeState.contexts.push(context);
|
|
360
|
+
return [contextIndex, contextPrototypeIndex];
|
|
361
|
+
}
|
|
362
|
+
function copyOriginalStaticProperties(mock, original) {
|
|
363
|
+
const { properties, descriptors } = getAllProperties(original);
|
|
364
|
+
for (const key of properties) {
|
|
365
|
+
const descriptor = descriptors[key];
|
|
366
|
+
const mockDescriptor = getDescriptor(mock, key);
|
|
367
|
+
if (mockDescriptor) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
Object.defineProperty(mock, key, descriptor);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const ignoreProperties = new Set([
|
|
374
|
+
"length",
|
|
375
|
+
"name",
|
|
376
|
+
"prototype",
|
|
377
|
+
Symbol.for("nodejs.util.promisify.custom")
|
|
378
|
+
]);
|
|
379
|
+
function getAllProperties(original) {
|
|
380
|
+
const properties = new Set();
|
|
381
|
+
const descriptors = {};
|
|
382
|
+
while (original && original !== Object.prototype && original !== Function.prototype) {
|
|
383
|
+
const ownProperties = [...Object.getOwnPropertyNames(original), ...Object.getOwnPropertySymbols(original)];
|
|
384
|
+
for (const prop of ownProperties) {
|
|
385
|
+
if (descriptors[prop] || ignoreProperties.has(prop)) {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
properties.add(prop);
|
|
389
|
+
descriptors[prop] = Object.getOwnPropertyDescriptor(original, prop);
|
|
390
|
+
}
|
|
391
|
+
original = Object.getPrototypeOf(original);
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
properties,
|
|
395
|
+
descriptors
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function getDefaultConfig(original) {
|
|
399
|
+
return {
|
|
400
|
+
mockImplementation: undefined,
|
|
401
|
+
mockOriginal: original,
|
|
402
|
+
mockName: "vi.fn()",
|
|
403
|
+
onceMockImplementations: []
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function getDefaultState() {
|
|
407
|
+
const state = {
|
|
408
|
+
calls: [],
|
|
409
|
+
contexts: [],
|
|
410
|
+
instances: [],
|
|
411
|
+
invocationCallOrder: [],
|
|
412
|
+
settledResults: [],
|
|
413
|
+
results: [],
|
|
414
|
+
get lastCall() {
|
|
415
|
+
return state.calls.at(-1);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
return state;
|
|
419
|
+
}
|
|
420
|
+
function restoreAllMocks() {
|
|
421
|
+
for (const restore of MOCK_RESTORE) {
|
|
422
|
+
restore();
|
|
423
|
+
}
|
|
424
|
+
MOCK_RESTORE.clear();
|
|
425
|
+
}
|
|
426
|
+
function clearAllMocks() {
|
|
427
|
+
REGISTERED_MOCKS.forEach((mock) => mock.mockClear());
|
|
428
|
+
}
|
|
429
|
+
function resetAllMocks() {
|
|
430
|
+
REGISTERED_MOCKS.forEach((mock) => mock.mockReset());
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export { clearAllMocks, createMockInstance, fn, isMockFunction, resetAllMocks, restoreAllMocks, spyOn };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
2
|
+
function normalizeWindowsPath(input = "") {
|
|
3
|
+
if (!input) {
|
|
4
|
+
return input;
|
|
5
|
+
}
|
|
6
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const _UNC_REGEX = /^[/\\]{2}/;
|
|
10
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
11
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
12
|
+
const normalize = function(path) {
|
|
13
|
+
if (path.length === 0) {
|
|
14
|
+
return ".";
|
|
15
|
+
}
|
|
16
|
+
path = normalizeWindowsPath(path);
|
|
17
|
+
const isUNCPath = path.match(_UNC_REGEX);
|
|
18
|
+
const isPathAbsolute = isAbsolute(path);
|
|
19
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
20
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
21
|
+
if (path.length === 0) {
|
|
22
|
+
if (isPathAbsolute) {
|
|
23
|
+
return "/";
|
|
24
|
+
}
|
|
25
|
+
return trailingSeparator ? "./" : ".";
|
|
26
|
+
}
|
|
27
|
+
if (trailingSeparator) {
|
|
28
|
+
path += "/";
|
|
29
|
+
}
|
|
30
|
+
if (_DRIVE_LETTER_RE.test(path)) {
|
|
31
|
+
path += "/";
|
|
32
|
+
}
|
|
33
|
+
if (isUNCPath) {
|
|
34
|
+
if (!isPathAbsolute) {
|
|
35
|
+
return `//./${path}`;
|
|
36
|
+
}
|
|
37
|
+
return `//${path}`;
|
|
38
|
+
}
|
|
39
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
40
|
+
};
|
|
41
|
+
const join = function(...segments) {
|
|
42
|
+
let path = "";
|
|
43
|
+
for (const seg of segments) {
|
|
44
|
+
if (!seg) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (path.length > 0) {
|
|
48
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
49
|
+
const segLeading = seg[0] === "/";
|
|
50
|
+
const both = pathTrailing && segLeading;
|
|
51
|
+
if (both) {
|
|
52
|
+
path += seg.slice(1);
|
|
53
|
+
} else {
|
|
54
|
+
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
path += seg;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return normalize(path);
|
|
61
|
+
};
|
|
62
|
+
function cwd() {
|
|
63
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
|
64
|
+
return process.cwd().replace(/\\/g, "/");
|
|
65
|
+
}
|
|
66
|
+
return "/";
|
|
67
|
+
}
|
|
68
|
+
const resolve = function(...arguments_) {
|
|
69
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
70
|
+
let resolvedPath = "";
|
|
71
|
+
let resolvedAbsolute = false;
|
|
72
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
73
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
74
|
+
if (!path || path.length === 0) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
78
|
+
resolvedAbsolute = isAbsolute(path);
|
|
79
|
+
}
|
|
80
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
81
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
82
|
+
return `/${resolvedPath}`;
|
|
83
|
+
}
|
|
84
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
85
|
+
};
|
|
86
|
+
function normalizeString(path, allowAboveRoot) {
|
|
87
|
+
let res = "";
|
|
88
|
+
let lastSegmentLength = 0;
|
|
89
|
+
let lastSlash = -1;
|
|
90
|
+
let dots = 0;
|
|
91
|
+
let char = null;
|
|
92
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
93
|
+
if (index < path.length) {
|
|
94
|
+
char = path[index];
|
|
95
|
+
} else if (char === "/") {
|
|
96
|
+
break;
|
|
97
|
+
} else {
|
|
98
|
+
char = "/";
|
|
99
|
+
}
|
|
100
|
+
if (char === "/") {
|
|
101
|
+
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
|
102
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
103
|
+
if (res.length > 2) {
|
|
104
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
105
|
+
if (lastSlashIndex === -1) {
|
|
106
|
+
res = "";
|
|
107
|
+
lastSegmentLength = 0;
|
|
108
|
+
} else {
|
|
109
|
+
res = res.slice(0, lastSlashIndex);
|
|
110
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
111
|
+
}
|
|
112
|
+
lastSlash = index;
|
|
113
|
+
dots = 0;
|
|
114
|
+
continue;
|
|
115
|
+
} else if (res.length > 0) {
|
|
116
|
+
res = "";
|
|
117
|
+
lastSegmentLength = 0;
|
|
118
|
+
lastSlash = index;
|
|
119
|
+
dots = 0;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (allowAboveRoot) {
|
|
124
|
+
res += res.length > 0 ? "/.." : "..";
|
|
125
|
+
lastSegmentLength = 2;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
if (res.length > 0) {
|
|
129
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
130
|
+
} else {
|
|
131
|
+
res = path.slice(lastSlash + 1, index);
|
|
132
|
+
}
|
|
133
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
134
|
+
}
|
|
135
|
+
lastSlash = index;
|
|
136
|
+
dots = 0;
|
|
137
|
+
} else if (char === "." && dots !== -1) {
|
|
138
|
+
++dots;
|
|
139
|
+
} else {
|
|
140
|
+
dots = -1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
const isAbsolute = function(p) {
|
|
146
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
147
|
+
};
|
|
148
|
+
const dirname = function(p) {
|
|
149
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
150
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
|
|
151
|
+
segments[0] += "/";
|
|
152
|
+
}
|
|
153
|
+
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export { dirname as d, join as j, resolve as r };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const KNOWN_ASSET_TYPES: string[];
|
|
2
|
+
declare const KNOWN_ASSET_RE: RegExp;
|
|
3
|
+
declare const CSS_LANGS_RE: RegExp;
|
|
4
|
+
/**
|
|
5
|
+
* Prefix for resolved Ids that are not valid browser import specifiers
|
|
6
|
+
*/
|
|
7
|
+
declare const VALID_ID_PREFIX = "/@id/";
|
|
8
|
+
/**
|
|
9
|
+
* Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
|
|
10
|
+
* module ID with `\0`, a convention from the rollup ecosystem.
|
|
11
|
+
* This prevents other plugins from trying to process the id (like node resolution),
|
|
12
|
+
* and core features like sourcemaps can use this info to differentiate between
|
|
13
|
+
* virtual modules and regular files.
|
|
14
|
+
* `\0` is not a permitted char in import URLs so we have to replace them during
|
|
15
|
+
* import analysis. The id will be decoded back before entering the plugins pipeline.
|
|
16
|
+
* These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
|
|
17
|
+
* modules in the browser end up encoded as `/@id/__x00__{id}`
|
|
18
|
+
*/
|
|
19
|
+
declare const NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
20
|
+
|
|
21
|
+
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// TODO: this is all copy pasted from Vite - can they expose a module that exports only constants?
|
|
2
|
+
const KNOWN_ASSET_TYPES = [
|
|
3
|
+
"apng",
|
|
4
|
+
"bmp",
|
|
5
|
+
"png",
|
|
6
|
+
"jpe?g",
|
|
7
|
+
"jfif",
|
|
8
|
+
"pjpeg",
|
|
9
|
+
"pjp",
|
|
10
|
+
"gif",
|
|
11
|
+
"svg",
|
|
12
|
+
"ico",
|
|
13
|
+
"webp",
|
|
14
|
+
"avif",
|
|
15
|
+
"mp4",
|
|
16
|
+
"webm",
|
|
17
|
+
"ogg",
|
|
18
|
+
"mp3",
|
|
19
|
+
"wav",
|
|
20
|
+
"flac",
|
|
21
|
+
"aac",
|
|
22
|
+
"woff2?",
|
|
23
|
+
"eot",
|
|
24
|
+
"ttf",
|
|
25
|
+
"otf",
|
|
26
|
+
"webmanifest",
|
|
27
|
+
"pdf",
|
|
28
|
+
"txt"
|
|
29
|
+
];
|
|
30
|
+
const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
|
|
31
|
+
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
32
|
+
/**
|
|
33
|
+
* Prefix for resolved Ids that are not valid browser import specifiers
|
|
34
|
+
*/
|
|
35
|
+
const VALID_ID_PREFIX = `/@id/`;
|
|
36
|
+
/**
|
|
37
|
+
* Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
|
|
38
|
+
* module ID with `\0`, a convention from the rollup ecosystem.
|
|
39
|
+
* This prevents other plugins from trying to process the id (like node resolution),
|
|
40
|
+
* and core features like sourcemaps can use this info to differentiate between
|
|
41
|
+
* virtual modules and regular files.
|
|
42
|
+
* `\0` is not a permitted char in import URLs so we have to replace them during
|
|
43
|
+
* import analysis. The id will be decoded back before entering the plugins pipeline.
|
|
44
|
+
* These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
|
|
45
|
+
* modules in the browser end up encoded as `/@id/__x00__{id}`
|
|
46
|
+
*/
|
|
47
|
+
const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
|
48
|
+
|
|
49
|
+
export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX };
|