@nuxt/test-utils 3.13.1 → 3.14.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/dist/e2e.d.mts +4 -13
- package/dist/e2e.d.ts +4 -13
- package/dist/e2e.mjs +5 -4
- package/dist/experimental.mjs +1 -1
- package/dist/playwright.d.mts +2 -1
- package/dist/playwright.d.ts +2 -1
- package/dist/playwright.mjs +3 -2
- package/dist/runtime-utils/index.d.mts +6 -3
- package/dist/runtime-utils/index.d.ts +6 -3
- package/dist/runtime-utils/index.mjs +41 -8
- package/dist/shared/{test-utils.TBc-WRBw.d.mts → test-utils.Bfk23aTC.d.mts} +15 -3
- package/dist/shared/{test-utils.TBc-WRBw.d.ts → test-utils.Bfk23aTC.d.ts} +15 -3
- package/dist/shared/{test-utils.C7cWLW4C.mjs → test-utils.CSumGjP7.mjs} +18 -16
- package/dist/shared/{test-utils.D8NWZeqn.mjs → test-utils.iUoJhWDR.mjs} +13 -5
- package/package.json +36 -36
package/dist/e2e.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.
|
|
2
|
-
export { G as GotoOptions,
|
|
1
|
+
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.Bfk23aTC.mjs';
|
|
2
|
+
export { $ as $fetch, G as GotoOptions, S as StartServerOptions, h as TestRunner, c as createBrowser, d as createPage, f as fetch, g as getBrowser, s as startServer, e as stopServer, u as url, w as waitForHydration } from './shared/test-utils.Bfk23aTC.mjs';
|
|
3
3
|
import { LogType } from 'consola';
|
|
4
|
-
import * as nitropack from 'nitropack';
|
|
5
4
|
import 'playwright-core';
|
|
6
5
|
import '@nuxt/schema';
|
|
7
6
|
import 'execa';
|
|
7
|
+
import 'nitropack';
|
|
8
8
|
|
|
9
9
|
declare function createTestContext(options: Partial<TestOptions>): TestContext;
|
|
10
10
|
declare function useTestContext(): TestContext;
|
|
@@ -20,15 +20,6 @@ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
|
|
|
20
20
|
declare function loadFixture(): Promise<void>;
|
|
21
21
|
declare function buildFixture(): Promise<void>;
|
|
22
22
|
|
|
23
|
-
interface StartServerOptions {
|
|
24
|
-
env?: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
27
|
-
declare function stopServer(): Promise<void>;
|
|
28
|
-
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
29
|
-
declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
|
|
30
|
-
declare function url(path: string): string;
|
|
31
|
-
|
|
32
23
|
declare function setupCucumber(hooks: TestHooks): Promise<void>;
|
|
33
24
|
|
|
34
25
|
declare function setupJest(hooks: TestHooks): Promise<void>;
|
|
@@ -52,4 +43,4 @@ interface RunTestOptions {
|
|
|
52
43
|
}
|
|
53
44
|
declare function runTests(opts: RunTestOptions): Promise<void>;
|
|
54
45
|
|
|
55
|
-
export {
|
|
46
|
+
export { type RunTestOptions, TestContext, TestHooks, TestOptions, buildFixture, createTest, createTestContext, exposeContextToEnv, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, useTestContext };
|
package/dist/e2e.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.
|
|
2
|
-
export { G as GotoOptions,
|
|
1
|
+
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.Bfk23aTC.js';
|
|
2
|
+
export { $ as $fetch, G as GotoOptions, S as StartServerOptions, h as TestRunner, c as createBrowser, d as createPage, f as fetch, g as getBrowser, s as startServer, e as stopServer, u as url, w as waitForHydration } from './shared/test-utils.Bfk23aTC.js';
|
|
3
3
|
import { LogType } from 'consola';
|
|
4
|
-
import * as nitropack from 'nitropack';
|
|
5
4
|
import 'playwright-core';
|
|
6
5
|
import '@nuxt/schema';
|
|
7
6
|
import 'execa';
|
|
7
|
+
import 'nitropack';
|
|
8
8
|
|
|
9
9
|
declare function createTestContext(options: Partial<TestOptions>): TestContext;
|
|
10
10
|
declare function useTestContext(): TestContext;
|
|
@@ -20,15 +20,6 @@ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
|
|
|
20
20
|
declare function loadFixture(): Promise<void>;
|
|
21
21
|
declare function buildFixture(): Promise<void>;
|
|
22
22
|
|
|
23
|
-
interface StartServerOptions {
|
|
24
|
-
env?: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
27
|
-
declare function stopServer(): Promise<void>;
|
|
28
|
-
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
29
|
-
declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
|
|
30
|
-
declare function url(path: string): string;
|
|
31
|
-
|
|
32
23
|
declare function setupCucumber(hooks: TestHooks): Promise<void>;
|
|
33
24
|
|
|
34
25
|
declare function setupJest(hooks: TestHooks): Promise<void>;
|
|
@@ -52,4 +43,4 @@ interface RunTestOptions {
|
|
|
52
43
|
}
|
|
53
44
|
declare function runTests(opts: RunTestOptions): Promise<void>;
|
|
54
45
|
|
|
55
|
-
export {
|
|
46
|
+
export { type RunTestOptions, TestContext, TestHooks, TestOptions, buildFixture, createTest, createTestContext, exposeContextToEnv, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, useTestContext };
|
package/dist/e2e.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { d as distDir } from './shared/test-utils.
|
|
2
|
-
export { b as buildFixture, c as createBrowser, a as createPage, e as createTest, g as getBrowser, l as loadFixture, f as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.
|
|
3
|
-
import { u as useTestContext } from './shared/test-utils.
|
|
4
|
-
export { $ as $fetch, c as createTestContext, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv, s as setTestContext, a as startServer, b as stopServer, d as url } from './shared/test-utils.
|
|
1
|
+
import { d as distDir } from './shared/test-utils.CSumGjP7.mjs';
|
|
2
|
+
export { b as buildFixture, c as createBrowser, a as createPage, e as createTest, g as getBrowser, l as loadFixture, f as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.CSumGjP7.mjs';
|
|
3
|
+
import { u as useTestContext } from './shared/test-utils.iUoJhWDR.mjs';
|
|
4
|
+
export { $ as $fetch, c as createTestContext, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv, s as setTestContext, a as startServer, b as stopServer, d as url } from './shared/test-utils.iUoJhWDR.mjs';
|
|
5
5
|
import { consola } from 'consola';
|
|
6
6
|
import { resolve } from 'pathe';
|
|
7
7
|
import 'node:fs';
|
|
@@ -12,6 +12,7 @@ import 'node:url';
|
|
|
12
12
|
import 'execa';
|
|
13
13
|
import 'get-port-please';
|
|
14
14
|
import 'ofetch';
|
|
15
|
+
import 'ufo';
|
|
15
16
|
|
|
16
17
|
function mockFn() {
|
|
17
18
|
const ctx = useTestContext();
|
package/dist/experimental.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'pathe';
|
|
2
2
|
import { stringifyQuery } from 'ufo';
|
|
3
|
-
import { $ as $fetch, u as useTestContext } from './shared/test-utils.
|
|
3
|
+
import { $ as $fetch, u as useTestContext } from './shared/test-utils.iUoJhWDR.mjs';
|
|
4
4
|
import 'execa';
|
|
5
5
|
import 'get-port-please';
|
|
6
6
|
import 'ofetch';
|
package/dist/playwright.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as _playwright_test from '@playwright/test';
|
|
2
2
|
export { expect } from '@playwright/test';
|
|
3
3
|
import { Response } from 'playwright-core';
|
|
4
|
-
import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.
|
|
4
|
+
import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.Bfk23aTC.mjs';
|
|
5
5
|
import '@nuxt/schema';
|
|
6
6
|
import 'execa';
|
|
7
|
+
import 'nitropack';
|
|
7
8
|
|
|
8
9
|
type ConfigOptions = {
|
|
9
10
|
nuxt: Partial<TestOptions$1> | undefined;
|
package/dist/playwright.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as _playwright_test from '@playwright/test';
|
|
2
2
|
export { expect } from '@playwright/test';
|
|
3
3
|
import { Response } from 'playwright-core';
|
|
4
|
-
import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.
|
|
4
|
+
import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.Bfk23aTC.js';
|
|
5
5
|
import '@nuxt/schema';
|
|
6
6
|
import 'execa';
|
|
7
|
+
import 'nitropack';
|
|
7
8
|
|
|
8
9
|
type ConfigOptions = {
|
|
9
10
|
nuxt: Partial<TestOptions$1> | undefined;
|
package/dist/playwright.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { test as test$1 } from '@playwright/test';
|
|
2
2
|
export { expect } from '@playwright/test';
|
|
3
|
-
import { e as createTest, w as waitForHydration } from './shared/test-utils.
|
|
3
|
+
import { e as createTest, w as waitForHydration } from './shared/test-utils.CSumGjP7.mjs';
|
|
4
4
|
import 'node:path';
|
|
5
5
|
import 'defu';
|
|
6
|
+
import 'ufo';
|
|
6
7
|
import 'consola';
|
|
7
8
|
import 'node:fs';
|
|
8
9
|
import '@nuxt/kit';
|
|
9
|
-
import { d as url } from './shared/test-utils.
|
|
10
|
+
import { d as url } from './shared/test-utils.iUoJhWDR.mjs';
|
|
10
11
|
import 'pathe';
|
|
11
12
|
import 'node:url';
|
|
12
13
|
import 'execa';
|
|
@@ -82,7 +82,7 @@ declare function mockComponent<PropsOptions extends Readonly<ComponentPropsOptio
|
|
|
82
82
|
type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
|
|
83
83
|
route?: RouteLocationRaw;
|
|
84
84
|
};
|
|
85
|
-
type SetupState = Record<string, any>;
|
|
85
|
+
type SetupState$1 = Record<string, any>;
|
|
86
86
|
/**
|
|
87
87
|
* `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:
|
|
88
88
|
*
|
|
@@ -110,12 +110,13 @@ type SetupState = Record<string, any>;
|
|
|
110
110
|
* @param options optional options to set up your component
|
|
111
111
|
*/
|
|
112
112
|
declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<ReturnType<typeof mount<T>> & {
|
|
113
|
-
setupState: SetupState;
|
|
113
|
+
setupState: SetupState$1;
|
|
114
114
|
}>;
|
|
115
115
|
|
|
116
116
|
type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
117
117
|
route?: RouteLocationRaw;
|
|
118
118
|
};
|
|
119
|
+
type SetupState = Record<string, any>;
|
|
119
120
|
/**
|
|
120
121
|
* `renderSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins.
|
|
121
122
|
*
|
|
@@ -146,7 +147,9 @@ type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
|
146
147
|
* @param component the component to be tested
|
|
147
148
|
* @param options optional options to set up your component
|
|
148
149
|
*/
|
|
149
|
-
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult
|
|
150
|
+
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult & {
|
|
151
|
+
setupState: SetupState;
|
|
152
|
+
}>;
|
|
150
153
|
declare global {
|
|
151
154
|
interface Window {
|
|
152
155
|
__cleanup?: Array<() => void>;
|
|
@@ -82,7 +82,7 @@ declare function mockComponent<PropsOptions extends Readonly<ComponentPropsOptio
|
|
|
82
82
|
type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
|
|
83
83
|
route?: RouteLocationRaw;
|
|
84
84
|
};
|
|
85
|
-
type SetupState = Record<string, any>;
|
|
85
|
+
type SetupState$1 = Record<string, any>;
|
|
86
86
|
/**
|
|
87
87
|
* `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:
|
|
88
88
|
*
|
|
@@ -110,12 +110,13 @@ type SetupState = Record<string, any>;
|
|
|
110
110
|
* @param options optional options to set up your component
|
|
111
111
|
*/
|
|
112
112
|
declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<ReturnType<typeof mount<T>> & {
|
|
113
|
-
setupState: SetupState;
|
|
113
|
+
setupState: SetupState$1;
|
|
114
114
|
}>;
|
|
115
115
|
|
|
116
116
|
type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
117
117
|
route?: RouteLocationRaw;
|
|
118
118
|
};
|
|
119
|
+
type SetupState = Record<string, any>;
|
|
119
120
|
/**
|
|
120
121
|
* `renderSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins.
|
|
121
122
|
*
|
|
@@ -146,7 +147,9 @@ type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
|
146
147
|
* @param component the component to be tested
|
|
147
148
|
* @param options optional options to set up your component
|
|
148
149
|
*/
|
|
149
|
-
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult
|
|
150
|
+
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult & {
|
|
151
|
+
setupState: SetupState;
|
|
152
|
+
}>;
|
|
150
153
|
declare global {
|
|
151
154
|
interface Window {
|
|
152
155
|
__cleanup?: Array<() => void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
2
|
import { mount } from '@vue/test-utils';
|
|
3
3
|
import { reactive, h as h$1, Suspense, nextTick, isReadonly, unref, effectScope } from 'vue';
|
|
4
|
-
import { defu } from 'defu';
|
|
4
|
+
import { createDefu, defu } from 'defu';
|
|
5
5
|
import { defineComponent, useRouter, h, tryUseNuxtApp } from '#imports';
|
|
6
6
|
import NuxtRoot from '#build/root-component.mjs';
|
|
7
7
|
|
|
@@ -133,7 +133,7 @@ async function mountSuspended(component, options) {
|
|
|
133
133
|
} : void 0,
|
|
134
134
|
setup: setup ? (props2) => wrappedSetup(props2, setupContext) : void 0
|
|
135
135
|
};
|
|
136
|
-
return () => h$1(clonedComponent, { ...
|
|
136
|
+
return () => h$1(clonedComponent, { ...defuReplaceArray(setProps, props), ...attrs }, slots);
|
|
137
137
|
}
|
|
138
138
|
})
|
|
139
139
|
}
|
|
@@ -161,6 +161,12 @@ async function mountSuspended(component, options) {
|
|
|
161
161
|
}
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
|
+
const defuReplaceArray = createDefu((obj, key, value) => {
|
|
165
|
+
if (Array.isArray(obj[key])) {
|
|
166
|
+
obj[key] = value;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
164
170
|
|
|
165
171
|
const WRAPPER_EL_ID = "test-wrapper";
|
|
166
172
|
async function renderSuspended(component, options) {
|
|
@@ -174,11 +180,21 @@ async function renderSuspended(component, options) {
|
|
|
174
180
|
const { render: renderFromTestingLibrary } = await import('@testing-library/vue');
|
|
175
181
|
const vueApp = tryUseNuxtApp()?.vueApp || globalThis.__unctx__.get("nuxt-app").tryUse().vueApp;
|
|
176
182
|
const { render, setup } = component;
|
|
183
|
+
let setupContext;
|
|
184
|
+
let setupState;
|
|
177
185
|
for (const fn of window.__cleanup || []) {
|
|
178
186
|
fn();
|
|
179
187
|
}
|
|
180
188
|
document.querySelector(`#${WRAPPER_EL_ID}`)?.remove();
|
|
181
|
-
let
|
|
189
|
+
let passedProps;
|
|
190
|
+
const wrappedSetup = async (props2, setupContext2) => {
|
|
191
|
+
passedProps = props2;
|
|
192
|
+
if (setup) {
|
|
193
|
+
const result = await setup(props2, setupContext2);
|
|
194
|
+
setupState = result && typeof result === "object" ? result : {};
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
182
198
|
return new Promise((resolve) => {
|
|
183
199
|
const utils = renderFromTestingLibrary(
|
|
184
200
|
{
|
|
@@ -191,8 +207,7 @@ async function renderSuspended(component, options) {
|
|
|
191
207
|
});
|
|
192
208
|
return scope.run(() => NuxtRoot.setup(props2, {
|
|
193
209
|
...ctx,
|
|
194
|
-
expose: () => {
|
|
195
|
-
}
|
|
210
|
+
expose: () => ({})
|
|
196
211
|
}));
|
|
197
212
|
},
|
|
198
213
|
render: (renderContext) => (
|
|
@@ -204,16 +219,34 @@ async function renderSuspended(component, options) {
|
|
|
204
219
|
{ id: WRAPPER_EL_ID },
|
|
205
220
|
h$1(
|
|
206
221
|
Suspense,
|
|
207
|
-
{
|
|
222
|
+
{
|
|
223
|
+
onResolve: () => nextTick().then(() => {
|
|
224
|
+
utils.setupState = setupState;
|
|
225
|
+
resolve(utils);
|
|
226
|
+
})
|
|
227
|
+
},
|
|
208
228
|
{
|
|
209
229
|
default: () => h$1({
|
|
230
|
+
name: "RenderHelper",
|
|
210
231
|
async setup() {
|
|
211
232
|
const router = useRouter();
|
|
212
233
|
await router.replace(route);
|
|
213
234
|
const clonedComponent = {
|
|
235
|
+
name: "RenderSuspendedComponent",
|
|
214
236
|
...component,
|
|
215
|
-
render: render ? (_ctx, ...args)
|
|
216
|
-
|
|
237
|
+
render: render ? function(_ctx, ...args) {
|
|
238
|
+
for (const key in setupState || {}) {
|
|
239
|
+
renderContext[key] = isReadonly(setupState[key]) ? unref(setupState[key]) : setupState[key];
|
|
240
|
+
}
|
|
241
|
+
for (const key in props || {}) {
|
|
242
|
+
renderContext[key] = _ctx[key];
|
|
243
|
+
}
|
|
244
|
+
for (const key in passedProps || {}) {
|
|
245
|
+
renderContext[key] = passedProps[key];
|
|
246
|
+
}
|
|
247
|
+
return render.call(this, renderContext, ...args);
|
|
248
|
+
} : void 0,
|
|
249
|
+
setup: setup ? (props2) => wrappedSetup(props2, setupContext) : void 0
|
|
217
250
|
};
|
|
218
251
|
return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...attrs }, slots);
|
|
219
252
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Browser, BrowserContextOptions, Page, Response, LaunchOptions } from 'playwright-core';
|
|
1
|
+
import { Browser, BrowserContextOptions, Page, Response as Response$1, LaunchOptions } from 'playwright-core';
|
|
2
2
|
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
3
3
|
import { ExecaChildProcess } from 'execa';
|
|
4
|
+
import * as nitropack from 'nitropack';
|
|
4
5
|
|
|
5
6
|
declare function createBrowser(): Promise<void>;
|
|
6
7
|
declare function getBrowser(): Promise<Browser>;
|
|
@@ -9,11 +10,20 @@ interface GotoOptions extends Omit<_GotoOptions, 'waitUntil'> {
|
|
|
9
10
|
waitUntil?: 'hydration' | 'route' | _GotoOptions['waitUntil'];
|
|
10
11
|
}
|
|
11
12
|
interface NuxtPage extends Omit<Page, 'goto'> {
|
|
12
|
-
goto: (url: string, options?: GotoOptions) => Promise<Response | null>;
|
|
13
|
+
goto: (url: string, options?: GotoOptions) => Promise<Response$1 | null>;
|
|
13
14
|
}
|
|
14
15
|
declare function createPage(path?: string, options?: BrowserContextOptions): Promise<NuxtPage>;
|
|
15
16
|
declare function waitForHydration(page: Page, url: string, waitUntil?: GotoOptions['waitUntil']): Promise<void>;
|
|
16
17
|
|
|
18
|
+
interface StartServerOptions {
|
|
19
|
+
env?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
22
|
+
declare function stopServer(): Promise<void>;
|
|
23
|
+
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
24
|
+
declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
|
|
25
|
+
declare function url(path: string): string;
|
|
26
|
+
|
|
17
27
|
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
18
28
|
interface TestOptions {
|
|
19
29
|
testDir: string;
|
|
@@ -34,7 +44,9 @@ interface TestOptions {
|
|
|
34
44
|
launch?: LaunchOptions;
|
|
35
45
|
};
|
|
36
46
|
server: boolean;
|
|
47
|
+
host?: string;
|
|
37
48
|
port?: number;
|
|
49
|
+
env?: StartServerOptions['env'];
|
|
38
50
|
}
|
|
39
51
|
interface TestContext {
|
|
40
52
|
options: TestOptions;
|
|
@@ -57,4 +69,4 @@ interface TestHooks {
|
|
|
57
69
|
ctx: TestContext;
|
|
58
70
|
}
|
|
59
71
|
|
|
60
|
-
export { type GotoOptions as G, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d,
|
|
72
|
+
export { $fetch as $, type GotoOptions as G, type StartServerOptions as S, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d, stopServer as e, fetch as f, getBrowser as g, type TestRunner as h, startServer as s, url as u, waitForHydration as w };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Browser, BrowserContextOptions, Page, Response, LaunchOptions } from 'playwright-core';
|
|
1
|
+
import { Browser, BrowserContextOptions, Page, Response as Response$1, LaunchOptions } from 'playwright-core';
|
|
2
2
|
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
3
3
|
import { ExecaChildProcess } from 'execa';
|
|
4
|
+
import * as nitropack from 'nitropack';
|
|
4
5
|
|
|
5
6
|
declare function createBrowser(): Promise<void>;
|
|
6
7
|
declare function getBrowser(): Promise<Browser>;
|
|
@@ -9,11 +10,20 @@ interface GotoOptions extends Omit<_GotoOptions, 'waitUntil'> {
|
|
|
9
10
|
waitUntil?: 'hydration' | 'route' | _GotoOptions['waitUntil'];
|
|
10
11
|
}
|
|
11
12
|
interface NuxtPage extends Omit<Page, 'goto'> {
|
|
12
|
-
goto: (url: string, options?: GotoOptions) => Promise<Response | null>;
|
|
13
|
+
goto: (url: string, options?: GotoOptions) => Promise<Response$1 | null>;
|
|
13
14
|
}
|
|
14
15
|
declare function createPage(path?: string, options?: BrowserContextOptions): Promise<NuxtPage>;
|
|
15
16
|
declare function waitForHydration(page: Page, url: string, waitUntil?: GotoOptions['waitUntil']): Promise<void>;
|
|
16
17
|
|
|
18
|
+
interface StartServerOptions {
|
|
19
|
+
env?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
22
|
+
declare function stopServer(): Promise<void>;
|
|
23
|
+
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
24
|
+
declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
|
|
25
|
+
declare function url(path: string): string;
|
|
26
|
+
|
|
17
27
|
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
18
28
|
interface TestOptions {
|
|
19
29
|
testDir: string;
|
|
@@ -34,7 +44,9 @@ interface TestOptions {
|
|
|
34
44
|
launch?: LaunchOptions;
|
|
35
45
|
};
|
|
36
46
|
server: boolean;
|
|
47
|
+
host?: string;
|
|
37
48
|
port?: number;
|
|
49
|
+
env?: StartServerOptions['env'];
|
|
38
50
|
}
|
|
39
51
|
interface TestContext {
|
|
40
52
|
options: TestOptions;
|
|
@@ -57,4 +69,4 @@ interface TestHooks {
|
|
|
57
69
|
ctx: TestContext;
|
|
58
70
|
}
|
|
59
71
|
|
|
60
|
-
export { type GotoOptions as G, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d,
|
|
72
|
+
export { $fetch as $, type GotoOptions as G, type StartServerOptions as S, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d, stopServer as e, fetch as f, getBrowser as g, type TestRunner as h, startServer as s, url as u, waitForHydration as w };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { u as useTestContext, d as url, c as createTestContext, s as setTestContext, b as stopServer, a as startServer } from './test-utils.
|
|
1
|
+
import { u as useTestContext, d as url, c as createTestContext, s as setTestContext, b as stopServer, a as startServer } from './test-utils.iUoJhWDR.mjs';
|
|
2
2
|
import { existsSync, promises } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { defu } from 'defu';
|
|
@@ -82,27 +82,29 @@ async function loadFixture() {
|
|
|
82
82
|
ctx.options.rootDir = resolveRootDir();
|
|
83
83
|
if (!ctx.options.dev) {
|
|
84
84
|
const randomId = Math.random().toString(36).slice(2, 8);
|
|
85
|
-
const
|
|
85
|
+
const buildDir = ctx.options.buildDir || resolve(ctx.options.rootDir, ".nuxt", "test", randomId);
|
|
86
86
|
ctx.options.nuxtConfig = defu(ctx.options.nuxtConfig, {
|
|
87
|
-
buildDir
|
|
87
|
+
buildDir,
|
|
88
88
|
nitro: {
|
|
89
89
|
output: {
|
|
90
|
-
dir: resolve(
|
|
90
|
+
dir: resolve(buildDir, "output")
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
ctx.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
if (ctx.options.build) {
|
|
96
|
+
ctx.nuxt = await kit.loadNuxt({
|
|
97
|
+
cwd: ctx.options.rootDir,
|
|
98
|
+
dev: ctx.options.dev,
|
|
99
|
+
overrides: ctx.options.nuxtConfig,
|
|
100
|
+
configFile: ctx.options.configFile
|
|
101
|
+
});
|
|
102
|
+
const buildDir = ctx.nuxt.options.buildDir;
|
|
103
|
+
if (!existsSync(buildDir)) {
|
|
104
|
+
await promises.mkdir(buildDir, { recursive: true });
|
|
105
|
+
ctx.teardown = ctx.teardown || [];
|
|
106
|
+
ctx.teardown.push(() => promises.rm(buildDir, { recursive: true, force: true }));
|
|
107
|
+
}
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
async function buildFixture() {
|
|
@@ -174,7 +176,7 @@ function createTest(options) {
|
|
|
174
176
|
await buildFixture();
|
|
175
177
|
}
|
|
176
178
|
if (ctx.options.server) {
|
|
177
|
-
await startServer();
|
|
179
|
+
await startServer(ctx.options.env);
|
|
178
180
|
}
|
|
179
181
|
if (ctx.options.waitFor) {
|
|
180
182
|
await new Promise((resolve) => setTimeout(resolve, ctx.options.waitFor));
|
|
@@ -3,6 +3,7 @@ import { getRandomPort, waitForPort } from 'get-port-please';
|
|
|
3
3
|
import { fetch as fetch$1, $fetch as $fetch$1 } from 'ofetch';
|
|
4
4
|
import * as _kit from '@nuxt/kit';
|
|
5
5
|
import { resolve as resolve$1 } from 'pathe';
|
|
6
|
+
import { withTrailingSlash, joinURL } from 'ufo';
|
|
6
7
|
import { resolve } from 'node:path';
|
|
7
8
|
import { defu } from 'defu';
|
|
8
9
|
|
|
@@ -22,13 +23,18 @@ function createTestContext(options) {
|
|
|
22
23
|
type: "chromium"
|
|
23
24
|
}
|
|
24
25
|
});
|
|
26
|
+
if (_options.host) {
|
|
27
|
+
_options.build = false;
|
|
28
|
+
_options.server = false;
|
|
29
|
+
}
|
|
25
30
|
if (process.env.VITEST === "true") {
|
|
26
31
|
_options.runner || (_options.runner = "vitest");
|
|
27
32
|
} else if (process.env.JEST_WORKER_ID) {
|
|
28
33
|
_options.runner || (_options.runner = "jest");
|
|
29
34
|
}
|
|
30
35
|
return setTestContext({
|
|
31
|
-
options: _options
|
|
36
|
+
options: _options,
|
|
37
|
+
url: withTrailingSlash(_options.host)
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
function useTestContext() {
|
|
@@ -62,7 +68,7 @@ async function startServer(options = {}) {
|
|
|
62
68
|
await stopServer();
|
|
63
69
|
const host = "127.0.0.1";
|
|
64
70
|
const port = ctx.options.port || await getRandomPort(host);
|
|
65
|
-
ctx.url = `http://${host}:${port}
|
|
71
|
+
ctx.url = `http://${host}:${port}/`;
|
|
66
72
|
if (ctx.options.dev) {
|
|
67
73
|
const nuxiCLI = await kit.resolvePath("nuxi/cli");
|
|
68
74
|
ctx.serverProcess = execa(nuxiCLI, ["_dev"], {
|
|
@@ -75,7 +81,8 @@ async function startServer(options = {}) {
|
|
|
75
81
|
PORT: String(port),
|
|
76
82
|
HOST: host,
|
|
77
83
|
NODE_ENV: "development",
|
|
78
|
-
...options.env
|
|
84
|
+
...options.env,
|
|
85
|
+
...ctx.options.env
|
|
79
86
|
}
|
|
80
87
|
});
|
|
81
88
|
await waitForPort(port, { retries: 32, host }).catch(() => {
|
|
@@ -104,7 +111,8 @@ async function startServer(options = {}) {
|
|
|
104
111
|
PORT: String(port),
|
|
105
112
|
HOST: host,
|
|
106
113
|
NODE_ENV: "test",
|
|
107
|
-
...options.env
|
|
114
|
+
...options.env,
|
|
115
|
+
...ctx.options.env
|
|
108
116
|
}
|
|
109
117
|
});
|
|
110
118
|
await waitForPort(port, { retries: 20, host });
|
|
@@ -130,7 +138,7 @@ function url(path) {
|
|
|
130
138
|
if (path.startsWith(ctx.url)) {
|
|
131
139
|
return path;
|
|
132
140
|
}
|
|
133
|
-
return ctx.url
|
|
141
|
+
return joinURL(ctx.url, path);
|
|
134
142
|
}
|
|
135
143
|
|
|
136
144
|
export { $fetch as $, startServer as a, stopServer as b, createTestContext as c, url as d, exposeContextToEnv as e, fetch as f, isDev as i, recoverContextFromEnv as r, setTestContext as s, useTestContext as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/test-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/test-utils.git"
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"release": "pnpm prepack && pnpm test:examples && changelogen --release --push"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@nuxt/kit": "^3.
|
|
44
|
-
"@nuxt/schema": "^3.
|
|
45
|
-
"c12": "^1.
|
|
43
|
+
"@nuxt/kit": "^3.12.4",
|
|
44
|
+
"@nuxt/schema": "^3.12.4",
|
|
45
|
+
"c12": "^1.11.1",
|
|
46
46
|
"consola": "^3.2.3",
|
|
47
47
|
"defu": "^6.1.4",
|
|
48
48
|
"destr": "^2.0.3",
|
|
49
49
|
"estree-walker": "^3.0.3",
|
|
50
50
|
"execa": "^8.0.1",
|
|
51
|
-
"fake-indexeddb": "^
|
|
51
|
+
"fake-indexeddb": "^6.0.0",
|
|
52
52
|
"get-port-please": "^3.1.2",
|
|
53
53
|
"local-pkg": "^0.5.0",
|
|
54
54
|
"magic-string": "^0.30.10",
|
|
@@ -59,46 +59,46 @@
|
|
|
59
59
|
"radix3": "^1.1.2",
|
|
60
60
|
"scule": "^1.3.0",
|
|
61
61
|
"std-env": "^3.7.0",
|
|
62
|
-
"ufo": "^1.5.
|
|
63
|
-
"unenv": "^1.
|
|
64
|
-
"unplugin": "^1.
|
|
62
|
+
"ufo": "^1.5.4",
|
|
63
|
+
"unenv": "^1.10.0",
|
|
64
|
+
"unplugin": "^1.12.0",
|
|
65
65
|
"vitest-environment-nuxt": "^1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@cucumber/cucumber": "10.
|
|
68
|
+
"@cucumber/cucumber": "10.8.0",
|
|
69
69
|
"@jest/globals": "29.7.0",
|
|
70
70
|
"@nuxt/devtools": "1.0.8",
|
|
71
71
|
"@nuxt/eslint-config": "0.3.13",
|
|
72
|
-
"@nuxt/module-builder": "0.
|
|
73
|
-
"@playwright/test": "1.
|
|
72
|
+
"@nuxt/module-builder": "0.8.1",
|
|
73
|
+
"@playwright/test": "1.45.3",
|
|
74
74
|
"@testing-library/vue": "8.1.0",
|
|
75
75
|
"@types/estree": "1.0.5",
|
|
76
|
-
"@types/jsdom": "21.1.
|
|
76
|
+
"@types/jsdom": "21.1.7",
|
|
77
77
|
"@types/semver": "7.5.8",
|
|
78
|
-
"@vitest/ui": "
|
|
78
|
+
"@vitest/ui": "2.0.4",
|
|
79
79
|
"@vue/test-utils": "2.4.6",
|
|
80
80
|
"changelogen": "0.5.5",
|
|
81
|
-
"eslint": "9.
|
|
82
|
-
"h3": "1.
|
|
83
|
-
"jiti": "1.21.
|
|
84
|
-
"nitropack": "2.9.
|
|
85
|
-
"nuxt": "3.
|
|
86
|
-
"playwright-core": "1.
|
|
87
|
-
"rollup": "4.
|
|
88
|
-
"semver": "7.6.
|
|
81
|
+
"eslint": "9.7.0",
|
|
82
|
+
"h3": "1.12.0",
|
|
83
|
+
"jiti": "1.21.6",
|
|
84
|
+
"nitropack": "2.9.7",
|
|
85
|
+
"nuxt": "3.12.4",
|
|
86
|
+
"playwright-core": "1.45.3",
|
|
87
|
+
"rollup": "4.19.0",
|
|
88
|
+
"semver": "7.6.3",
|
|
89
89
|
"unbuild": "latest",
|
|
90
|
-
"unimport": "3.
|
|
91
|
-
"vite": "5.
|
|
92
|
-
"vitest": "
|
|
93
|
-
"vue-router": "4.
|
|
94
|
-
"vue-tsc": "2.0.
|
|
90
|
+
"unimport": "3.9.0",
|
|
91
|
+
"vite": "5.3.5",
|
|
92
|
+
"vitest": "2.0.4",
|
|
93
|
+
"vue-router": "4.4.0",
|
|
94
|
+
"vue-tsc": "2.0.29"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
97
|
"@cucumber/cucumber": "^10.3.1",
|
|
98
98
|
"@jest/globals": "^29.5.0",
|
|
99
99
|
"@playwright/test": "^1.43.1",
|
|
100
100
|
"@testing-library/vue": "^7.0.0 || ^8.0.1",
|
|
101
|
-
"@vitest/ui": "^0.34.6 || ^1.0.0",
|
|
101
|
+
"@vitest/ui": "^0.34.6 || ^1.0.0 || ^2.0.0",
|
|
102
102
|
"@vue/test-utils": "^2.4.2",
|
|
103
103
|
"h3": "*",
|
|
104
104
|
"happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"nitropack": "*",
|
|
107
107
|
"playwright-core": "^1.43.1",
|
|
108
108
|
"vite": "*",
|
|
109
|
-
"vitest": "^0.34.6 || ^1.0.0",
|
|
109
|
+
"vitest": "^0.34.6 || ^1.0.0 || ^2.0.0",
|
|
110
110
|
"vue": "^3.3.4",
|
|
111
111
|
"vue-router": "^4.0.0"
|
|
112
112
|
},
|
|
@@ -143,18 +143,18 @@
|
|
|
143
143
|
}
|
|
144
144
|
},
|
|
145
145
|
"resolutions": {
|
|
146
|
-
"@cucumber/cucumber": "10.
|
|
147
|
-
"@nuxt/kit": "^3.
|
|
148
|
-
"@nuxt/schema": "^3.
|
|
146
|
+
"@cucumber/cucumber": "10.8.0",
|
|
147
|
+
"@nuxt/kit": "^3.12.4",
|
|
148
|
+
"@nuxt/schema": "^3.12.4",
|
|
149
149
|
"@nuxt/test-utils": "workspace:*",
|
|
150
|
-
"rollup": "4.
|
|
151
|
-
"vite": "5.
|
|
152
|
-
"vue": "^3.4.
|
|
150
|
+
"rollup": "4.19.0",
|
|
151
|
+
"vite": "5.3.5",
|
|
152
|
+
"vue": "^3.4.34"
|
|
153
153
|
},
|
|
154
154
|
"engines": {
|
|
155
|
-
"node": ">=18.20.
|
|
155
|
+
"node": ">=18.20.4"
|
|
156
156
|
},
|
|
157
|
-
"packageManager": "pnpm@9.
|
|
157
|
+
"packageManager": "pnpm@9.6.0",
|
|
158
158
|
"pnpm": {
|
|
159
159
|
"patchedDependencies": {
|
|
160
160
|
"nuxt@3.11.2": "patches/nuxt@3.11.2.patch"
|