@depup/vitest__mocker 4.1.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/auto-register.d.ts +2 -0
- package/dist/auto-register.js +10 -0
- package/dist/automock.d.ts +13 -0
- package/dist/automock.js +8 -0
- package/dist/browser.d.ts +53 -0
- package/dist/browser.js +92 -0
- package/dist/chunk-automock.js +522 -0
- package/dist/chunk-helpers.js +44 -0
- package/dist/chunk-hoistMocks.js +659 -0
- package/dist/chunk-interceptor-native.js +15 -0
- package/dist/chunk-mocker.js +532 -0
- package/dist/chunk-pathe.M-eThtNZ.js +174 -0
- package/dist/chunk-registry.js +199 -0
- package/dist/chunk-utils.js +27 -0
- package/dist/hoistMocks.d-w2ILr1dG.d.ts +739 -0
- package/dist/index.d-B41z0AuW.d.ts +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +200 -0
- package/dist/mocker.d-QEntlm6J.d.ts +86 -0
- package/dist/node.d.ts +71 -0
- package/dist/node.js +409 -0
- package/dist/redirect.d.ts +3 -0
- package/dist/redirect.js +79 -0
- package/dist/register.d.ts +9 -0
- package/dist/register.js +42 -0
- package/dist/transforms.d.ts +8 -0
- package/dist/transforms.js +10 -0
- package/dist/types.d-BjI5eAwu.d.ts +123 -0
- package/package.json +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-Present VoidZero Inc. and Vitest contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @depup/vitest__mocker
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [@vitest/mocker](https://www.npmjs.com/package/@vitest/mocker)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/vitest__mocker
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [@vitest/mocker](https://www.npmjs.com/package/@vitest/mocker) @ 4.1.0 |
|
|
17
|
+
| Processed | 2026-03-17 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 0 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@vitest/mocker
|
|
24
|
+
|
|
25
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { M as ModuleMockerServerInterceptor } from './chunk-interceptor-native.js';
|
|
2
|
+
import { registerModuleMocker } from './register.js';
|
|
3
|
+
import './chunk-mocker.js';
|
|
4
|
+
import './chunk-helpers.js';
|
|
5
|
+
import './index.js';
|
|
6
|
+
import './chunk-registry.js';
|
|
7
|
+
import './chunk-pathe.M-eThtNZ.js';
|
|
8
|
+
import '@vitest/spy';
|
|
9
|
+
|
|
10
|
+
registerModuleMocker(() => new ModuleMockerServerInterceptor());
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import MagicString from 'magic-string';
|
|
2
|
+
|
|
3
|
+
interface AutomockOptions {
|
|
4
|
+
/**
|
|
5
|
+
* @default "__vitest_mocker__"
|
|
6
|
+
*/
|
|
7
|
+
globalThisAccessor?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
}
|
|
10
|
+
declare function automockModule(code: string, mockType: "automock" | "autospy", parse: (code: string) => any, options?: AutomockOptions): MagicString;
|
|
11
|
+
|
|
12
|
+
export { automockModule };
|
|
13
|
+
export type { AutomockOptions };
|
package/dist/automock.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { M as ModuleMockerInterceptor } from './mocker.d-QEntlm6J.js';
|
|
2
|
+
export { C as CompilerHintsOptions, b as ModuleMocker, a as ModuleMockerCompilerHints, c as ModuleMockerConfig, d as ModuleMockerRPC, R as ResolveIdResult, e as ResolveMockResult, f as createCompilerHints } from './mocker.d-QEntlm6J.js';
|
|
3
|
+
import { StartOptions, SetupWorker } from 'msw/browser';
|
|
4
|
+
import { M as MockerRegistry, a as MockedModule } from './types.d-BjI5eAwu.js';
|
|
5
|
+
import '@vitest/spy';
|
|
6
|
+
import './index.d-B41z0AuW.js';
|
|
7
|
+
|
|
8
|
+
interface ModuleMockerMSWInterceptorOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The identifier to access the globalThis object in the worker.
|
|
11
|
+
* This will be injected into the script as is, so make sure it's a valid JS expression.
|
|
12
|
+
* @example
|
|
13
|
+
* ```js
|
|
14
|
+
* // globalThisAccessor: '__my_variable__' produces:
|
|
15
|
+
* globalThis[__my_variable__]
|
|
16
|
+
* // globalThisAccessor: 'Symbol.for('secret:mocks')' produces:
|
|
17
|
+
* globalThis[Symbol.for('secret:mocks')]
|
|
18
|
+
* // globalThisAccessor: '"__vitest_mocker__"' (notice quotes) produces:
|
|
19
|
+
* globalThis["__vitest_mocker__"]
|
|
20
|
+
* ```
|
|
21
|
+
* @default `"__vitest_mocker__"`
|
|
22
|
+
*/
|
|
23
|
+
globalThisAccessor?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Options passed down to `msw.setupWorker().start(options)`
|
|
26
|
+
*/
|
|
27
|
+
mswOptions?: StartOptions;
|
|
28
|
+
/**
|
|
29
|
+
* A pre-configured `msw.setupWorker` instance.
|
|
30
|
+
*/
|
|
31
|
+
mswWorker?: SetupWorker;
|
|
32
|
+
}
|
|
33
|
+
declare class ModuleMockerMSWInterceptor implements ModuleMockerInterceptor {
|
|
34
|
+
private readonly options;
|
|
35
|
+
protected readonly mocks: MockerRegistry;
|
|
36
|
+
private startPromise;
|
|
37
|
+
private worker;
|
|
38
|
+
constructor(options?: ModuleMockerMSWInterceptorOptions);
|
|
39
|
+
register(module: MockedModule): Promise<void>;
|
|
40
|
+
delete(url: string): Promise<void>;
|
|
41
|
+
invalidate(): Promise<void>;
|
|
42
|
+
private resolveManualMock;
|
|
43
|
+
protected init(): Promise<SetupWorker>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare class ModuleMockerServerInterceptor implements ModuleMockerInterceptor {
|
|
47
|
+
register(module: MockedModule): Promise<void>;
|
|
48
|
+
delete(id: string): Promise<void>;
|
|
49
|
+
invalidate(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { ModuleMockerInterceptor, ModuleMockerMSWInterceptor, ModuleMockerServerInterceptor };
|
|
53
|
+
export type { ModuleMockerMSWInterceptorOptions };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export { M as ModuleMocker, c as createCompilerHints } from './chunk-mocker.js';
|
|
2
|
+
import { M as MockerRegistry } from './chunk-registry.js';
|
|
3
|
+
import { c as createManualModuleSource, a as cleanUrl } from './chunk-utils.js';
|
|
4
|
+
export { M as ModuleMockerServerInterceptor } from './chunk-interceptor-native.js';
|
|
5
|
+
import './chunk-helpers.js';
|
|
6
|
+
import './index.js';
|
|
7
|
+
import './chunk-pathe.M-eThtNZ.js';
|
|
8
|
+
|
|
9
|
+
class ModuleMockerMSWInterceptor {
|
|
10
|
+
mocks = new MockerRegistry();
|
|
11
|
+
startPromise;
|
|
12
|
+
worker;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
if (!options.globalThisAccessor) {
|
|
16
|
+
options.globalThisAccessor = "\"__vitest_mocker__\"";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async register(module) {
|
|
20
|
+
await this.init();
|
|
21
|
+
this.mocks.add(module);
|
|
22
|
+
}
|
|
23
|
+
async delete(url) {
|
|
24
|
+
await this.init();
|
|
25
|
+
this.mocks.delete(url);
|
|
26
|
+
}
|
|
27
|
+
async invalidate() {
|
|
28
|
+
this.mocks.clear();
|
|
29
|
+
}
|
|
30
|
+
async resolveManualMock(mock) {
|
|
31
|
+
const exports$1 = Object.keys(await mock.resolve());
|
|
32
|
+
const text = createManualModuleSource(mock.url, exports$1, this.options.globalThisAccessor);
|
|
33
|
+
return new Response(text, { headers: { "Content-Type": "application/javascript" } });
|
|
34
|
+
}
|
|
35
|
+
async init() {
|
|
36
|
+
if (this.worker) {
|
|
37
|
+
return this.worker;
|
|
38
|
+
}
|
|
39
|
+
if (this.startPromise) {
|
|
40
|
+
return this.startPromise;
|
|
41
|
+
}
|
|
42
|
+
const worker = this.options.mswWorker;
|
|
43
|
+
this.startPromise = Promise.all([worker ? { setupWorker(handler) {
|
|
44
|
+
worker.use(handler);
|
|
45
|
+
return worker;
|
|
46
|
+
} } : import('msw/browser'), import('msw/core/http')]).then(([{ setupWorker }, { http }]) => {
|
|
47
|
+
const worker = setupWorker(http.get(/.+/, async ({ request }) => {
|
|
48
|
+
const path = cleanQuery(request.url.slice(location.origin.length));
|
|
49
|
+
if (!this.mocks.has(path)) {
|
|
50
|
+
return passthrough();
|
|
51
|
+
}
|
|
52
|
+
const mock = this.mocks.get(path);
|
|
53
|
+
switch (mock.type) {
|
|
54
|
+
case "manual": return this.resolveManualMock(mock);
|
|
55
|
+
case "automock":
|
|
56
|
+
case "autospy": return Response.redirect(injectQuery(path, `mock=${mock.type}`));
|
|
57
|
+
case "redirect": return Response.redirect(mock.redirect);
|
|
58
|
+
default: throw new Error(`Unknown mock type: ${mock.type}`);
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
return worker.start(this.options.mswOptions).then(() => worker);
|
|
62
|
+
}).finally(() => {
|
|
63
|
+
this.worker = worker;
|
|
64
|
+
this.startPromise = undefined;
|
|
65
|
+
});
|
|
66
|
+
return await this.startPromise;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const trailingSeparatorRE = /[?&]$/;
|
|
70
|
+
const timestampRE = /\bt=\d{13}&?\b/;
|
|
71
|
+
const versionRE = /\bv=\w{8}&?\b/;
|
|
72
|
+
function cleanQuery(url) {
|
|
73
|
+
return url.replace(timestampRE, "").replace(versionRE, "").replace(trailingSeparatorRE, "");
|
|
74
|
+
}
|
|
75
|
+
function passthrough() {
|
|
76
|
+
return new Response(null, {
|
|
77
|
+
status: 302,
|
|
78
|
+
statusText: "Passthrough",
|
|
79
|
+
headers: { "x-msw-intention": "passthrough" }
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const replacePercentageRE = /%/g;
|
|
83
|
+
function injectQuery(url, queryToInject) {
|
|
84
|
+
// encode percents for consistent behavior with pathToFileURL
|
|
85
|
+
// see #2614 for details
|
|
86
|
+
const resolvedUrl = new URL(url.replace(replacePercentageRE, "%25"), location.href);
|
|
87
|
+
const { search, hash } = resolvedUrl;
|
|
88
|
+
const pathname = cleanUrl(url);
|
|
89
|
+
return `${pathname}?${queryToInject}${search ? `&${search.slice(1)}` : ""}${hash ?? ""}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { ModuleMockerMSWInterceptor };
|