@nuxt/test-utils 3.16.0 → 3.17.1
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/dist/runtime-utils/index.d.mts +1 -15
- package/dist/runtime-utils/index.mjs +30 -11
- package/package.json +25 -20
|
@@ -7,24 +7,10 @@ import { RenderOptions as RenderOptions$1 } from '@testing-library/vue';
|
|
|
7
7
|
|
|
8
8
|
type Awaitable<T> = T | Promise<T>;
|
|
9
9
|
type OptionalFunction<T> = T | (() => Awaitable<T>);
|
|
10
|
-
/**
|
|
11
|
-
* `registerEndpoint` allows you create Nitro endpoint that returns mocked data. It can come in handy if you want to test a component that makes requests to API to display some data.
|
|
12
|
-
* @param url - endpoint name (e.g. `/test/`).
|
|
13
|
-
* @param options - factory function that returns the mocked data or an object containing both the `handler` and the `method` properties.
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { registerEndpoint } from '@nuxt/test-utils/runtime'
|
|
17
|
-
*
|
|
18
|
-
* registerEndpoint("/test/", () => {
|
|
19
|
-
* test: "test-field"
|
|
20
|
-
* })
|
|
21
|
-
* ```
|
|
22
|
-
* @see https://nuxt.com/docs/getting-started/testing#registerendpoint
|
|
23
|
-
*/
|
|
24
10
|
declare function registerEndpoint(url: string, options: EventHandler | {
|
|
25
11
|
handler: EventHandler;
|
|
26
12
|
method: HTTPMethod;
|
|
27
|
-
}): void;
|
|
13
|
+
}): () => void;
|
|
28
14
|
/**
|
|
29
15
|
* `mockNuxtImport` allows you to mock Nuxt's auto import functionality.
|
|
30
16
|
* @param _name - name of an import to mock.
|
|
@@ -5,19 +5,34 @@ import { defu } from 'defu';
|
|
|
5
5
|
import { defineComponent, useRouter, h, tryUseNuxtApp } from '#imports';
|
|
6
6
|
import NuxtRoot from '#build/root-component.mjs';
|
|
7
7
|
|
|
8
|
+
const endpointRegistry = {};
|
|
8
9
|
function registerEndpoint(url, options) {
|
|
9
10
|
const app = window.__app;
|
|
10
|
-
if (!app)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
if (!app) {
|
|
12
|
+
throw new Error("registerEndpoint() can only be used in a `@nuxt/test-utils` runtime environment");
|
|
13
|
+
}
|
|
14
|
+
const config = typeof options === "function" ? { handler: options, method: void 0 } : options;
|
|
15
|
+
config.handler = defineEventHandler(config.handler);
|
|
16
|
+
const hasBeenRegistered = window.__registry.has(url);
|
|
17
|
+
endpointRegistry[url] ||= [];
|
|
18
|
+
endpointRegistry[url].push(config);
|
|
19
|
+
if (!hasBeenRegistered) {
|
|
20
|
+
window.__registry.add(url);
|
|
21
|
+
app.use("/_" + url, defineEventHandler((event) => {
|
|
22
|
+
const latestHandler = [...endpointRegistry[url]].reverse().find((config2) => config2.method ? event.method === config2.method : true);
|
|
23
|
+
return latestHandler?.handler(event);
|
|
24
|
+
}), {
|
|
25
|
+
match(_, event) {
|
|
26
|
+
return endpointRegistry[url]?.some((config2) => config2.method ? event?.method === config2.method : true);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return () => {
|
|
31
|
+
endpointRegistry[url].splice(endpointRegistry[url].indexOf(config), 1);
|
|
32
|
+
if (endpointRegistry[url].length === 0) {
|
|
33
|
+
window.__registry.delete(url);
|
|
18
34
|
}
|
|
19
|
-
}
|
|
20
|
-
window.__registry.add(url);
|
|
35
|
+
};
|
|
21
36
|
}
|
|
22
37
|
function mockNuxtImport(_name, _factory) {
|
|
23
38
|
throw new Error(
|
|
@@ -121,7 +136,11 @@ async function mountSuspended(component, options) {
|
|
|
121
136
|
render: render ? function(_ctx, ...args) {
|
|
122
137
|
const currentInstance = getCurrentInstance();
|
|
123
138
|
if (currentInstance) {
|
|
124
|
-
|
|
139
|
+
const oldEmit = currentInstance.emit;
|
|
140
|
+
currentInstance.emit = (event, ...args2) => {
|
|
141
|
+
oldEmit(event, ...args2);
|
|
142
|
+
setupContext.emit(event, ...args2);
|
|
143
|
+
};
|
|
125
144
|
}
|
|
126
145
|
if (data && typeof data === "function") {
|
|
127
146
|
const dataObject = data();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/test-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/test-utils.git"
|
|
@@ -65,15 +65,15 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@nuxt/kit": "^3.15.4",
|
|
67
67
|
"@nuxt/schema": "^3.15.4",
|
|
68
|
-
"c12": "^
|
|
68
|
+
"c12": "^3.0.2",
|
|
69
69
|
"consola": "^3.4.0",
|
|
70
70
|
"defu": "^6.1.4",
|
|
71
71
|
"destr": "^2.0.3",
|
|
72
72
|
"estree-walker": "^3.0.3",
|
|
73
73
|
"fake-indexeddb": "^6.0.0",
|
|
74
74
|
"get-port-please": "^3.1.2",
|
|
75
|
-
"h3": "^1.15.
|
|
76
|
-
"local-pkg": "^1.
|
|
75
|
+
"h3": "^1.15.1",
|
|
76
|
+
"local-pkg": "^1.1.0",
|
|
77
77
|
"magic-string": "^0.30.17",
|
|
78
78
|
"node-fetch-native": "^1.6.5",
|
|
79
79
|
"ofetch": "^1.4.1",
|
|
@@ -86,39 +86,39 @@
|
|
|
86
86
|
"ufo": "^1.5.4",
|
|
87
87
|
"unenv": "^1.10.0",
|
|
88
88
|
"unplugin": "^2.2.0",
|
|
89
|
-
"vite": "^6.
|
|
89
|
+
"vite": "^6.2.0",
|
|
90
90
|
"vitest-environment-nuxt": "^1.0.1",
|
|
91
91
|
"vue": "^3.5.13"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@cucumber/cucumber": "11.2.0",
|
|
95
95
|
"@jest/globals": "29.7.0",
|
|
96
|
-
"@nuxt/devtools-kit": "2.1.
|
|
96
|
+
"@nuxt/devtools-kit": "2.1.1",
|
|
97
97
|
"@nuxt/eslint-config": "1.1.0",
|
|
98
98
|
"@playwright/test": "1.50.1",
|
|
99
99
|
"@testing-library/vue": "8.1.0",
|
|
100
100
|
"@types/estree": "1.0.6",
|
|
101
101
|
"@types/jsdom": "21.1.7",
|
|
102
|
-
"@types/node": "22.13.
|
|
102
|
+
"@types/node": "22.13.8",
|
|
103
103
|
"@types/semver": "7.5.8",
|
|
104
104
|
"@vue/test-utils": "2.4.6",
|
|
105
|
-
"changelogen": "0.
|
|
105
|
+
"changelogen": "0.6.0",
|
|
106
106
|
"compatx": "0.1.8",
|
|
107
|
-
"eslint": "9.
|
|
107
|
+
"eslint": "9.21.0",
|
|
108
108
|
"installed-check": "9.3.0",
|
|
109
|
-
"knip": "5.
|
|
109
|
+
"knip": "5.45.0",
|
|
110
110
|
"nitropack": "2.10.4",
|
|
111
111
|
"nuxt": "3.15.4",
|
|
112
|
-
"pkg-pr-new": "0.0.
|
|
112
|
+
"pkg-pr-new": "0.0.40",
|
|
113
113
|
"playwright-core": "1.50.1",
|
|
114
|
-
"rollup": "4.34.
|
|
114
|
+
"rollup": "4.34.9",
|
|
115
115
|
"semver": "7.7.1",
|
|
116
|
-
"typescript": "5.
|
|
116
|
+
"typescript": "5.8.2",
|
|
117
117
|
"unbuild": "latest",
|
|
118
118
|
"unimport": "4.1.2",
|
|
119
|
-
"vitest": "3.0.
|
|
119
|
+
"vitest": "3.0.7",
|
|
120
120
|
"vue-router": "4.5.0",
|
|
121
|
-
"vue-tsc": "2.2.
|
|
121
|
+
"vue-tsc": "2.2.8"
|
|
122
122
|
},
|
|
123
123
|
"peerDependencies": {
|
|
124
124
|
"@cucumber/cucumber": "^10.3.1 || ^11.0.0",
|
|
@@ -169,14 +169,19 @@
|
|
|
169
169
|
"@nuxt/kit": "^3.15.4",
|
|
170
170
|
"@nuxt/schema": "^3.15.4",
|
|
171
171
|
"@nuxt/test-utils": "workspace:*",
|
|
172
|
-
"rollup": "4.34.
|
|
173
|
-
"vite": "^6.
|
|
174
|
-
"vite-node": "3.0.
|
|
175
|
-
"vitest": "3.0.
|
|
172
|
+
"rollup": "4.34.9",
|
|
173
|
+
"vite": "^6.2.0",
|
|
174
|
+
"vite-node": "3.0.7",
|
|
175
|
+
"vitest": "3.0.7",
|
|
176
176
|
"vue": "^3.5.13"
|
|
177
177
|
},
|
|
178
178
|
"engines": {
|
|
179
179
|
"node": "^18.20.5 || ^20.9.0 || ^22.0.0 || >=23.0.0"
|
|
180
180
|
},
|
|
181
|
-
"packageManager": "pnpm@10.
|
|
181
|
+
"packageManager": "pnpm@10.5.2",
|
|
182
|
+
"pnpm": {
|
|
183
|
+
"onlyBuiltDependencies": [
|
|
184
|
+
"better-sqlite3"
|
|
185
|
+
]
|
|
186
|
+
}
|
|
182
187
|
}
|