@nuxt/test-utils-nightly 3.21.1-20251220-095456-4c8a3b7 → 3.21.1-20251231-210330-86b4998
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 +23 -23
- package/dist/runtime-utils/index.mjs +154 -281
- package/package.json +12 -12
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventHandler, HTTPMethod } from 'h3';
|
|
2
2
|
import { SetupContext, RenderFunction, ComputedOptions, MethodOptions, ComponentOptionsMixin, EmitsOptions, ComponentInjectOptions, ComponentOptionsWithoutProps, ComponentOptionsWithArrayProps, ComponentPropsOptions, ComponentOptionsWithObjectProps } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { mount } from '@vue/test-utils';
|
|
4
4
|
import { RouteLocationRaw } from 'vue-router';
|
|
5
|
-
import {
|
|
5
|
+
import { render } from '@testing-library/vue';
|
|
6
6
|
|
|
7
7
|
type Awaitable<T> = T | Promise<T>;
|
|
8
8
|
type OptionalFunction<T> = T | (() => Awaitable<T>);
|
|
@@ -95,14 +95,26 @@ declare function mockComponent<Props = {}, RawBindings = {}, D = {}, C extends C
|
|
|
95
95
|
declare function mockComponent<PropNames extends string, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string>(path: string, options: OptionalFunction<ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II>>): void;
|
|
96
96
|
declare function mockComponent<PropsOptions extends Readonly<ComponentPropsOptions>, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string>(path: string, options: OptionalFunction<ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II>>): void;
|
|
97
97
|
|
|
98
|
-
type
|
|
98
|
+
type SetupState = Record<string, any>;
|
|
99
|
+
type WrapperFnComponent<Fn> = Fn extends (c: infer C, o: infer _) => infer _ ? C : never;
|
|
100
|
+
type WrapperFnOption<Fn> = Fn extends (c: WrapperFnComponent<Fn>, o: infer O) => infer _ ? O : never;
|
|
101
|
+
type WrapperFnResult<Fn> = Fn extends (c: WrapperFnComponent<Fn>, o: WrapperFnOption<Fn>) => infer R ? R : never;
|
|
102
|
+
type WrapperSuspendedOptions<Fn> = WrapperFnOption<Fn> & {
|
|
99
103
|
route?: RouteLocationRaw;
|
|
100
104
|
scoped?: boolean;
|
|
101
105
|
};
|
|
102
|
-
type
|
|
103
|
-
setupState: SetupState
|
|
106
|
+
type WrapperSuspendedResult<Fn> = WrapperFnResult<Fn> & {
|
|
107
|
+
setupState: SetupState;
|
|
104
108
|
};
|
|
105
|
-
|
|
109
|
+
declare global {
|
|
110
|
+
interface Window {
|
|
111
|
+
__cleanup?: Array<() => void>;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type WrapperFn$1<C> = typeof mount<C>;
|
|
116
|
+
type WrapperOptions$1<C> = WrapperSuspendedOptions<WrapperFn$1<C>>;
|
|
117
|
+
type WrapperResult$1<C> = WrapperSuspendedResult<WrapperFn$1<C>>;
|
|
106
118
|
/**
|
|
107
119
|
* `mountSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins. For example:
|
|
108
120
|
*
|
|
@@ -129,18 +141,11 @@ type SetupState$1 = Record<string, any>;
|
|
|
129
141
|
* @param component the component to be tested
|
|
130
142
|
* @param options optional options to set up your component
|
|
131
143
|
*/
|
|
132
|
-
declare function mountSuspended<T>(component: T, options?:
|
|
133
|
-
declare global {
|
|
134
|
-
var __cleanup: Array<() => void> | undefined;
|
|
135
|
-
}
|
|
144
|
+
declare function mountSuspended<T>(component: T, options?: WrapperOptions$1<T>): Promise<WrapperResult$1<T>>;
|
|
136
145
|
|
|
137
|
-
type
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
type RenderSuspendeResult = RenderResult & {
|
|
141
|
-
setupState: SetupState;
|
|
142
|
-
};
|
|
143
|
-
type SetupState = Record<string, any>;
|
|
146
|
+
type WrapperFn<C> = typeof render<C>;
|
|
147
|
+
type WrapperOptions<C> = WrapperSuspendedOptions<WrapperFn<C>>;
|
|
148
|
+
type WrapperResult<C> = WrapperSuspendedResult<WrapperFn<C>>;
|
|
144
149
|
/**
|
|
145
150
|
* `renderSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins.
|
|
146
151
|
*
|
|
@@ -171,11 +176,6 @@ type SetupState = Record<string, any>;
|
|
|
171
176
|
* @param component the component to be tested
|
|
172
177
|
* @param options optional options to set up your component
|
|
173
178
|
*/
|
|
174
|
-
declare function renderSuspended<T>(component: T, options?:
|
|
175
|
-
declare global {
|
|
176
|
-
interface Window {
|
|
177
|
-
__cleanup?: Array<() => void>;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
179
|
+
declare function renderSuspended<T>(component: T, options?: WrapperOptions<T>): Promise<WrapperResult<T>>;
|
|
180
180
|
|
|
181
181
|
export { mockComponent, mockNuxtImport, mountSuspended, registerEndpoint, renderSuspended };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
2
|
import { mount } from '@vue/test-utils';
|
|
3
|
-
import { reactive, h as h$1, Suspense, nextTick, getCurrentInstance,
|
|
3
|
+
import { reactive, h as h$1, Suspense, nextTick as nextTick$1, getCurrentInstance, onErrorCaptured, effectScope } from 'vue';
|
|
4
4
|
import { defu } from 'defu';
|
|
5
|
-
import { defineComponent, useRouter, h, tryUseNuxtApp
|
|
5
|
+
import { defineComponent, useRouter, h, tryUseNuxtApp } from '#imports';
|
|
6
6
|
import NuxtRoot from '#build/root-component.mjs';
|
|
7
7
|
|
|
8
8
|
const endpointRegistry = {};
|
|
@@ -88,19 +88,34 @@ const RouterLink = defineComponent({
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
const {
|
|
93
|
-
|
|
94
|
-
attrs = {},
|
|
95
|
-
slots = {},
|
|
96
|
-
route = "/",
|
|
97
|
-
..._options
|
|
98
|
-
} = options || {};
|
|
99
|
-
for (const cleanupFunction of globalThis.__cleanup || []) {
|
|
100
|
-
cleanupFunction();
|
|
91
|
+
function cleanupAll() {
|
|
92
|
+
for (const fn of (window.__cleanup || []).splice(0)) {
|
|
93
|
+
fn();
|
|
101
94
|
}
|
|
95
|
+
}
|
|
96
|
+
function addCleanup(fn) {
|
|
97
|
+
window.__cleanup ||= [];
|
|
98
|
+
window.__cleanup.push(fn);
|
|
99
|
+
}
|
|
100
|
+
function runEffectScope(fn) {
|
|
101
|
+
const scope = effectScope();
|
|
102
|
+
addCleanup(() => scope.stop());
|
|
103
|
+
return scope.run(fn);
|
|
104
|
+
}
|
|
105
|
+
function wrapperSuspended(component, options, {
|
|
106
|
+
wrapperFn,
|
|
107
|
+
wrappedRender = (fn) => fn,
|
|
108
|
+
suspendedHelperName,
|
|
109
|
+
clonedComponentName
|
|
110
|
+
}) {
|
|
111
|
+
const { props = {}, attrs = {} } = options;
|
|
112
|
+
const { route = "/", scoped = false, ...wrapperFnOptions } = options;
|
|
102
113
|
const vueApp = tryUseNuxtApp()?.vueApp || globalThis.__unctx__.get("nuxt-app").tryUse().vueApp;
|
|
103
|
-
const {
|
|
114
|
+
const {
|
|
115
|
+
render: componentRender,
|
|
116
|
+
setup: componentSetup,
|
|
117
|
+
...componentRest
|
|
118
|
+
} = component;
|
|
104
119
|
let wrappedInstance = null;
|
|
105
120
|
let setupContext;
|
|
106
121
|
let setupState;
|
|
@@ -113,28 +128,19 @@ async function mountSuspended(component, options) {
|
|
|
113
128
|
app[key] = value;
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (options?.scoped) {
|
|
127
|
-
componentScope = effectScope();
|
|
128
|
-
globalThis.__cleanup ||= [];
|
|
129
|
-
globalThis.__cleanup.push(() => {
|
|
130
|
-
componentScope?.stop();
|
|
131
|
-
});
|
|
132
|
-
result = await componentScope?.run(async () => {
|
|
133
|
-
return await setup(props2, setupContext2);
|
|
134
|
-
});
|
|
135
|
-
} else {
|
|
136
|
-
result = await setup(props2, setupContext2);
|
|
131
|
+
const ClonedComponent = {
|
|
132
|
+
components: {},
|
|
133
|
+
...component,
|
|
134
|
+
name: clonedComponentName,
|
|
135
|
+
async setup(props2, instanceContext) {
|
|
136
|
+
const currentInstance = getCurrentInstance();
|
|
137
|
+
if (currentInstance) {
|
|
138
|
+
currentInstance.emit = (event, ...args) => {
|
|
139
|
+
setupContext.emit(event, ...args);
|
|
140
|
+
};
|
|
137
141
|
}
|
|
142
|
+
if (!componentSetup) return;
|
|
143
|
+
const result = scoped ? await runEffectScope(() => componentSetup(props2, setupContext)) : await componentSetup(props2, setupContext);
|
|
138
144
|
if (wrappedInstance?.exposed) {
|
|
139
145
|
instanceContext.expose(wrappedInstance.exposed);
|
|
140
146
|
}
|
|
@@ -142,114 +148,108 @@ async function mountSuspended(component, options) {
|
|
|
142
148
|
return result;
|
|
143
149
|
}
|
|
144
150
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
151
|
+
const SuspendedHelper = {
|
|
152
|
+
name: suspendedHelperName,
|
|
153
|
+
render: () => "",
|
|
154
|
+
async setup() {
|
|
155
|
+
const router = useRouter();
|
|
156
|
+
await router.replace(route);
|
|
157
|
+
return () => h$1(ClonedComponent, { ...props, ...setProps, ...attrs }, setupContext.slots);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
let isMountSettled = false;
|
|
162
|
+
const wrapper = wrapperFn(
|
|
163
|
+
{
|
|
164
|
+
inheritAttrs: false,
|
|
165
|
+
__cssModules: componentRest.__cssModules,
|
|
166
|
+
setup: (props2, ctx) => {
|
|
167
|
+
patchInstanceAppContext();
|
|
168
|
+
wrappedInstance = getCurrentInstance();
|
|
169
|
+
setupContext = ctx;
|
|
170
|
+
const nuxtRootSetupResult = runEffectScope(
|
|
171
|
+
() => NuxtRoot.setup(props2, {
|
|
172
|
+
...ctx,
|
|
173
|
+
expose: () => {
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
onErrorCaptured((error, ...args) => {
|
|
178
|
+
if (isMountSettled) return;
|
|
179
|
+
isMountSettled = true;
|
|
180
|
+
try {
|
|
181
|
+
wrappedInstance?.appContext.config.errorHandler?.(error, ...args);
|
|
182
|
+
reject(error);
|
|
183
|
+
} catch (error2) {
|
|
184
|
+
reject(error2);
|
|
174
185
|
}
|
|
175
|
-
|
|
186
|
+
return false;
|
|
187
|
+
});
|
|
188
|
+
return nuxtRootSetupResult;
|
|
189
|
+
},
|
|
190
|
+
render: wrappedRender(() => h$1(
|
|
191
|
+
Suspense,
|
|
192
|
+
{
|
|
193
|
+
onResolve: () => nextTick$1().then(() => {
|
|
176
194
|
if (isMountSettled) return;
|
|
177
195
|
isMountSettled = true;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
reject(error2);
|
|
183
|
-
}
|
|
184
|
-
return false;
|
|
185
|
-
});
|
|
186
|
-
return nuxtRootSetupResult;
|
|
187
|
-
},
|
|
188
|
-
render: () => h$1(
|
|
189
|
-
Suspense,
|
|
190
|
-
{
|
|
191
|
-
onResolve: () => nextTick().then(() => {
|
|
192
|
-
if (isMountSettled) return;
|
|
193
|
-
isMountSettled = true;
|
|
194
|
-
vm.setupState = setupState;
|
|
195
|
-
vm.__setProps = (props2) => {
|
|
196
|
+
wrapper.setupState = setupState;
|
|
197
|
+
resolve({
|
|
198
|
+
wrapper,
|
|
199
|
+
setProps: (props2) => {
|
|
196
200
|
Object.assign(setProps, props2);
|
|
197
|
-
};
|
|
198
|
-
resolve(wrappedMountedWrapper(vm));
|
|
199
|
-
})
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
default: () => h$1({
|
|
203
|
-
name: "MountSuspendedHelper",
|
|
204
|
-
render: () => "",
|
|
205
|
-
async setup() {
|
|
206
|
-
const router = useRouter();
|
|
207
|
-
await router.replace(route);
|
|
208
|
-
const clonedComponent = {
|
|
209
|
-
components: {},
|
|
210
|
-
...component,
|
|
211
|
-
name: "MountSuspendedComponent",
|
|
212
|
-
setup: (props2, ctx) => wrappedSetup(props2, setupContext, ctx)
|
|
213
|
-
};
|
|
214
|
-
return () => h$1(clonedComponent, { ...props, ...setProps, ...attrs }, setupContext.slots);
|
|
215
201
|
}
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
},
|
|
220
|
-
defu(
|
|
221
|
-
_options,
|
|
202
|
+
});
|
|
203
|
+
})
|
|
204
|
+
},
|
|
222
205
|
{
|
|
223
|
-
|
|
224
|
-
slots,
|
|
225
|
-
attrs,
|
|
226
|
-
global: {
|
|
227
|
-
config: {
|
|
228
|
-
globalProperties: {
|
|
229
|
-
...vueApp.config.globalProperties,
|
|
230
|
-
// make all properties/keys enumerable.
|
|
231
|
-
...Object.fromEntries(
|
|
232
|
-
Object.getOwnPropertyNames(vueApp.config.globalProperties).map((key) => [key, vueApp.config.globalProperties[key]])
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
directives: vueApp._context.directives,
|
|
237
|
-
provide: vueApp._context.provides,
|
|
238
|
-
stubs: {
|
|
239
|
-
Suspense: false,
|
|
240
|
-
MountSuspendedHelper: false,
|
|
241
|
-
[component && typeof component === "object" && "name" in component && typeof component.name === "string" ? component.name : "MountSuspendedComponent"]: false
|
|
242
|
-
},
|
|
243
|
-
components: { ...vueApp._context.components, RouterLink }
|
|
244
|
-
}
|
|
206
|
+
default: () => h$1(SuspendedHelper)
|
|
245
207
|
}
|
|
246
|
-
)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
208
|
+
))
|
|
209
|
+
},
|
|
210
|
+
defu(wrapperFnOptions, {
|
|
211
|
+
global: {
|
|
212
|
+
config: {
|
|
213
|
+
globalProperties: makeAllPropertiesEnumerable(
|
|
214
|
+
vueApp.config.globalProperties
|
|
215
|
+
)
|
|
216
|
+
},
|
|
217
|
+
directives: vueApp._context.directives,
|
|
218
|
+
provide: vueApp._context.provides,
|
|
219
|
+
stubs: {
|
|
220
|
+
Suspense: false,
|
|
221
|
+
[SuspendedHelper.name]: false,
|
|
222
|
+
[ClonedComponent.name]: false
|
|
223
|
+
},
|
|
224
|
+
components: { ...vueApp._context.components, RouterLink }
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function makeAllPropertiesEnumerable(target) {
|
|
231
|
+
return {
|
|
232
|
+
...target,
|
|
233
|
+
...Object.fromEntries(
|
|
234
|
+
Object.getOwnPropertyNames(target).map((key) => [key, target[key]])
|
|
235
|
+
)
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function mountSuspended(component, options = {}) {
|
|
240
|
+
const suspendedHelperName = "MountSuspendedHelper";
|
|
241
|
+
const clonedComponentName = "MountSuspendedComponent";
|
|
242
|
+
cleanupAll();
|
|
243
|
+
const { wrapper, setProps } = await wrapperSuspended(component, options, {
|
|
244
|
+
wrapperFn: mount,
|
|
245
|
+
suspendedHelperName,
|
|
246
|
+
clonedComponentName
|
|
247
|
+
});
|
|
248
|
+
Object.assign(wrapper, { __setProps: setProps });
|
|
249
|
+
const clonedComponent = wrapper.findComponent({ name: clonedComponentName });
|
|
250
|
+
return wrappedMountedWrapper(wrapper, clonedComponent);
|
|
250
251
|
}
|
|
251
|
-
function wrappedMountedWrapper(wrapper) {
|
|
252
|
-
const component = wrapper.findComponent({ name: "MountSuspendedComponent" });
|
|
252
|
+
function wrappedMountedWrapper(wrapper, component) {
|
|
253
253
|
const wrapperProps = [
|
|
254
254
|
"setProps",
|
|
255
255
|
"emitted",
|
|
@@ -290,154 +290,27 @@ function wrappedMountedWrapper(wrapper) {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const setProps = reactive({});
|
|
309
|
-
function patchInstanceAppContext() {
|
|
310
|
-
const app = getCurrentInstance()?.appContext.app;
|
|
311
|
-
if (!app) return;
|
|
312
|
-
for (const [key, value] of Object.entries(vueApp)) {
|
|
313
|
-
if (key in app) continue;
|
|
314
|
-
app[key] = value;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
for (const fn of window.__cleanup || []) {
|
|
318
|
-
fn();
|
|
319
|
-
}
|
|
320
|
-
document.querySelector(`#${WRAPPER_EL_ID}`)?.remove();
|
|
321
|
-
const wrappedSetup = async (props2, setupContext2, instanceContext) => {
|
|
322
|
-
const currentInstance = getCurrentInstance();
|
|
323
|
-
if (currentInstance) {
|
|
324
|
-
currentInstance.emit = (event, ...args) => {
|
|
325
|
-
setupContext2.emit(event, ...args);
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
if (setup) {
|
|
329
|
-
const result = await setup(props2, setupContext2);
|
|
330
|
-
setupState = result && typeof result === "object" ? result : {};
|
|
331
|
-
if (wrappedInstance?.exposed) {
|
|
332
|
-
instanceContext.expose(wrappedInstance.exposed);
|
|
333
|
-
}
|
|
334
|
-
return result;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
const WrapperComponent = defineComponent$1({
|
|
338
|
-
inheritAttrs: false,
|
|
339
|
-
render() {
|
|
340
|
-
return h$1("div", { id: WRAPPER_EL_ID }, this.$slots.default?.());
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
return new Promise((resolve, reject) => {
|
|
344
|
-
let isMountSettled = false;
|
|
345
|
-
const utils = renderFromTestingLibrary(
|
|
346
|
-
{
|
|
347
|
-
__cssModules: componentRest.__cssModules,
|
|
348
|
-
inheritAttrs: false,
|
|
349
|
-
setup: (props2, ctx) => {
|
|
350
|
-
patchInstanceAppContext();
|
|
351
|
-
wrappedInstance = getCurrentInstance();
|
|
352
|
-
setupContext = ctx;
|
|
353
|
-
const scope = effectScope();
|
|
354
|
-
window.__cleanup ||= [];
|
|
355
|
-
window.__cleanup.push(() => {
|
|
356
|
-
scope.stop();
|
|
357
|
-
});
|
|
358
|
-
const nuxtRootSetupResult = scope.run(() => NuxtRoot.setup(props2, {
|
|
359
|
-
...ctx,
|
|
360
|
-
expose: () => ({})
|
|
361
|
-
}));
|
|
362
|
-
onErrorCaptured((error, ...args) => {
|
|
363
|
-
if (isMountSettled) return;
|
|
364
|
-
isMountSettled = true;
|
|
365
|
-
try {
|
|
366
|
-
wrappedInstance?.appContext.config.errorHandler?.(error, ...args);
|
|
367
|
-
reject(error);
|
|
368
|
-
} catch (error2) {
|
|
369
|
-
reject(error2);
|
|
370
|
-
}
|
|
371
|
-
return false;
|
|
372
|
-
});
|
|
373
|
-
return nuxtRootSetupResult;
|
|
374
|
-
},
|
|
375
|
-
render: () => (
|
|
376
|
-
// See discussions in https://github.com/testing-library/vue-testing-library/issues/230
|
|
377
|
-
// we add this additional root element because otherwise testing-library breaks
|
|
378
|
-
// because there's no root element while Suspense is resolving
|
|
379
|
-
h$1(
|
|
380
|
-
WrapperComponent,
|
|
381
|
-
{},
|
|
382
|
-
{
|
|
383
|
-
default: () => h$1(
|
|
384
|
-
Suspense,
|
|
385
|
-
{
|
|
386
|
-
onResolve: () => nextTick().then(() => {
|
|
387
|
-
if (isMountSettled) return;
|
|
388
|
-
isMountSettled = true;
|
|
389
|
-
utils.setupState = setupState;
|
|
390
|
-
utils.rerender = async (props2) => {
|
|
391
|
-
Object.assign(setProps, props2);
|
|
392
|
-
await nextTick();
|
|
393
|
-
};
|
|
394
|
-
resolve(utils);
|
|
395
|
-
})
|
|
396
|
-
},
|
|
397
|
-
{
|
|
398
|
-
default: () => h$1({
|
|
399
|
-
name: "RenderHelper",
|
|
400
|
-
render: () => "",
|
|
401
|
-
async setup() {
|
|
402
|
-
const router = useRouter();
|
|
403
|
-
await router.replace(route);
|
|
404
|
-
const clonedComponent = {
|
|
405
|
-
components: {},
|
|
406
|
-
...component,
|
|
407
|
-
name: "RenderSuspendedComponent",
|
|
408
|
-
render,
|
|
409
|
-
setup: (props2, ctx) => wrappedSetup(props2, setupContext, ctx)
|
|
410
|
-
};
|
|
411
|
-
return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...setProps, ...attrs }, setupContext.slots);
|
|
412
|
-
}
|
|
413
|
-
})
|
|
414
|
-
}
|
|
415
|
-
)
|
|
416
|
-
}
|
|
417
|
-
)
|
|
418
|
-
)
|
|
419
|
-
},
|
|
420
|
-
defu(_options, {
|
|
421
|
-
props,
|
|
422
|
-
slots,
|
|
423
|
-
attrs,
|
|
424
|
-
global: {
|
|
425
|
-
config: {
|
|
426
|
-
globalProperties: {
|
|
427
|
-
...vueApp.config.globalProperties,
|
|
428
|
-
// make all properties/keys enumerable.
|
|
429
|
-
...Object.fromEntries(
|
|
430
|
-
Object.getOwnPropertyNames(vueApp.config.globalProperties).map((key) => [key, vueApp.config.globalProperties[key]])
|
|
431
|
-
)
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
directives: vueApp._context.directives,
|
|
435
|
-
provide: vueApp._context.provides,
|
|
436
|
-
components: { RouterLink }
|
|
437
|
-
}
|
|
438
|
-
})
|
|
439
|
-
);
|
|
293
|
+
async function renderSuspended(component, options = {}) {
|
|
294
|
+
const wrapperId = "test-wrapper";
|
|
295
|
+
const suspendedHelperName = "RenderHelper";
|
|
296
|
+
const clonedComponentName = "RenderSuspendedComponent";
|
|
297
|
+
const { render: wrapperFn } = await import('@testing-library/vue');
|
|
298
|
+
cleanupAll();
|
|
299
|
+
document.getElementById(wrapperId)?.remove();
|
|
300
|
+
const { wrapper, setProps } = await wrapperSuspended(component, options, {
|
|
301
|
+
wrapperFn,
|
|
302
|
+
wrappedRender: (render) => () => h$1({
|
|
303
|
+
inheritAttrs: false,
|
|
304
|
+
render: () => h$1("div", { id: wrapperId }, render())
|
|
305
|
+
}),
|
|
306
|
+
suspendedHelperName,
|
|
307
|
+
clonedComponentName
|
|
440
308
|
});
|
|
309
|
+
wrapper.rerender = async (props) => {
|
|
310
|
+
setProps(props);
|
|
311
|
+
await nextTick();
|
|
312
|
+
};
|
|
313
|
+
return wrapper;
|
|
441
314
|
}
|
|
442
315
|
|
|
443
316
|
export { mockComponent, mockNuxtImport, mountSuspended, registerEndpoint, renderSuspended };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/test-utils-nightly",
|
|
3
|
-
"version": "3.21.1-
|
|
3
|
+
"version": "3.21.1-20251231-210330-86b4998",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/test-utils.git"
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@nuxt/kit": "^3.20.1",
|
|
71
|
-
"c12": "^3.3.
|
|
71
|
+
"c12": "^3.3.3",
|
|
72
72
|
"consola": "^3.4.2",
|
|
73
73
|
"defu": "^6.1.4",
|
|
74
74
|
"destr": "^2.0.5",
|
|
@@ -91,17 +91,17 @@
|
|
|
91
91
|
"ufo": "^1.6.1",
|
|
92
92
|
"unplugin": "^2.3.11",
|
|
93
93
|
"vitest-environment-nuxt": "^1.0.1",
|
|
94
|
-
"vue": "^3.5.
|
|
94
|
+
"vue": "^3.5.26"
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@cucumber/cucumber": "12.
|
|
97
|
+
"@cucumber/cucumber": "12.5.0",
|
|
98
98
|
"@jest/globals": "30.2.0",
|
|
99
99
|
"@nuxt/devtools-kit": "2.7.0",
|
|
100
100
|
"@nuxt/eslint-config": "1.12.1",
|
|
101
101
|
"@nuxt/schema": "4.2.1",
|
|
102
102
|
"@playwright/test": "1.57.0",
|
|
103
103
|
"@testing-library/vue": "8.1.0",
|
|
104
|
-
"@types/bun": "1.3.
|
|
104
|
+
"@types/bun": "1.3.5",
|
|
105
105
|
"@types/estree": "1.0.8",
|
|
106
106
|
"@types/jsdom": "27.0.0",
|
|
107
107
|
"@types/node": "latest",
|
|
@@ -111,12 +111,12 @@
|
|
|
111
111
|
"compatx": "0.2.0",
|
|
112
112
|
"eslint": "9.39.2",
|
|
113
113
|
"installed-check": "9.3.0",
|
|
114
|
-
"knip": "5.
|
|
114
|
+
"knip": "5.78.0",
|
|
115
115
|
"nitropack": "2.12.9",
|
|
116
116
|
"nuxt": "4.2.1",
|
|
117
117
|
"pkg-pr-new": "0.0.62",
|
|
118
118
|
"playwright-core": "1.57.0",
|
|
119
|
-
"rollup": "4.
|
|
119
|
+
"rollup": "4.54.0",
|
|
120
120
|
"semver": "7.7.3",
|
|
121
121
|
"typescript": "5.9.3",
|
|
122
122
|
"unbuild": "latest",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"vite": "7.3.0",
|
|
125
125
|
"vitest": "3.2.4",
|
|
126
126
|
"vue-router": "4.6.4",
|
|
127
|
-
"vue-tsc": "3.1
|
|
127
|
+
"vue-tsc": "3.2.1"
|
|
128
128
|
},
|
|
129
129
|
"peerDependencies": {
|
|
130
130
|
"@cucumber/cucumber": "^10.3.1 || >=11.0.0",
|
|
@@ -170,18 +170,18 @@
|
|
|
170
170
|
}
|
|
171
171
|
},
|
|
172
172
|
"resolutions": {
|
|
173
|
-
"@cucumber/cucumber": "12.
|
|
173
|
+
"@cucumber/cucumber": "12.5.0",
|
|
174
174
|
"@nuxt/schema": "4.2.1",
|
|
175
175
|
"@nuxt/test-utils": "workspace:*",
|
|
176
176
|
"@types/node": "24.10.4",
|
|
177
|
-
"rollup": "4.
|
|
177
|
+
"rollup": "4.54.0",
|
|
178
178
|
"vite": "7.3.0",
|
|
179
179
|
"vite-node": "5.2.0",
|
|
180
180
|
"vitest": "3.2.4",
|
|
181
|
-
"vue": "^3.5.
|
|
181
|
+
"vue": "^3.5.26"
|
|
182
182
|
},
|
|
183
183
|
"engines": {
|
|
184
184
|
"node": "^20.0.0 || ^22.0.0 || >=24.0.0"
|
|
185
185
|
},
|
|
186
|
-
"packageManager": "pnpm@10.26.
|
|
186
|
+
"packageManager": "pnpm@10.26.2"
|
|
187
187
|
}
|