@nuxt/test-utils 3.12.1 → 3.13.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/config.d.mts CHANGED
@@ -17,7 +17,7 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
17
17
  }>;
18
18
  declare function defineVitestConfig(config?: InlineConfig & {
19
19
  test?: InlineConfig$1;
20
- }): vite.UserConfig & Promise<vite.UserConfig> & vite.UserConfigFnObject & vite.UserConfigExport;
20
+ }): vite.UserConfig & Promise<vite.UserConfig> & (vite.UserConfigFnObject & vite.UserConfigExport);
21
21
  declare module 'vitest' {
22
22
  interface EnvironmentOptions {
23
23
  nuxt?: {
package/dist/config.d.ts CHANGED
@@ -17,7 +17,7 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
17
17
  }>;
18
18
  declare function defineVitestConfig(config?: InlineConfig & {
19
19
  test?: InlineConfig$1;
20
- }): vite.UserConfig & Promise<vite.UserConfig> & vite.UserConfigFnObject & vite.UserConfigExport;
20
+ }): vite.UserConfig & Promise<vite.UserConfig> & (vite.UserConfigFnObject & vite.UserConfigExport);
21
21
  declare module 'vitest' {
22
22
  interface EnvironmentOptions {
23
23
  nuxt?: {
package/dist/config.mjs CHANGED
@@ -46,6 +46,8 @@ async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {})
46
46
  }),
47
47
  overrides: defu(
48
48
  {
49
+ appId: "nuxt-app",
50
+ buildId: "test",
49
51
  ssr: false,
50
52
  test: true,
51
53
  modules: ["@nuxt/test-utils/module"]
@@ -88,7 +90,7 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
88
90
  }
89
91
  });
90
92
  }
91
- options.viteConfig.plugins = (options.viteConfig.plugins || []).filter((p) => !excludedPlugins.includes(p?.name));
93
+ options.viteConfig.plugins = (options.viteConfig.plugins || []).filter((p) => !p || !("name" in p) || !excludedPlugins.includes(p.name));
92
94
  const resolvedConfig = defu(
93
95
  // overrides
94
96
  {
package/dist/e2e.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.9059LSjm.mjs';
2
- export { G as GotoOptions, e as TestRunner, c as createBrowser, d as createPage, g as getBrowser, w as waitForHydration } from './shared/test-utils.9059LSjm.mjs';
3
- import { FetchOptions } from 'ofetch';
1
+ import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.TBc-WRBw.mjs';
2
+ export { G as GotoOptions, e as TestRunner, c as createBrowser, d as createPage, g as getBrowser, w as waitForHydration } from './shared/test-utils.TBc-WRBw.mjs';
3
+ import { LogType } from 'consola';
4
+ import * as nitropack from 'nitropack';
4
5
  import 'playwright-core';
5
6
  import '@nuxt/schema';
6
7
  import 'execa';
@@ -13,8 +14,8 @@ declare function isDev(): boolean;
13
14
  declare function recoverContextFromEnv(): void;
14
15
  declare function exposeContextToEnv(): void;
15
16
 
16
- declare function mockFn(): Function | undefined;
17
- declare function mockLogger(): Record<string, Function>;
17
+ declare function mockFn(): ((...args: unknown[]) => unknown) | undefined;
18
+ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
18
19
 
19
20
  declare function loadFixture(): Promise<void>;
20
21
  declare function buildFixture(): Promise<void>;
@@ -24,8 +25,8 @@ interface StartServerOptions {
24
25
  }
25
26
  declare function startServer(options?: StartServerOptions): Promise<void>;
26
27
  declare function stopServer(): Promise<void>;
27
- declare function fetch(path: string, options?: any): Promise<Response>;
28
- declare function $fetch(path: string, options?: FetchOptions): Promise<any>;
28
+ declare function fetch(path: string, options?: RequestInit): Promise<Response>;
29
+ declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
29
30
  declare function url(path: string): string;
30
31
 
31
32
  declare function setupCucumber(hooks: TestHooks): Promise<void>;
package/dist/e2e.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.9059LSjm.js';
2
- export { G as GotoOptions, e as TestRunner, c as createBrowser, d as createPage, g as getBrowser, w as waitForHydration } from './shared/test-utils.9059LSjm.js';
3
- import { FetchOptions } from 'ofetch';
1
+ import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.TBc-WRBw.js';
2
+ export { G as GotoOptions, e as TestRunner, c as createBrowser, d as createPage, g as getBrowser, w as waitForHydration } from './shared/test-utils.TBc-WRBw.js';
3
+ import { LogType } from 'consola';
4
+ import * as nitropack from 'nitropack';
4
5
  import 'playwright-core';
5
6
  import '@nuxt/schema';
6
7
  import 'execa';
@@ -13,8 +14,8 @@ declare function isDev(): boolean;
13
14
  declare function recoverContextFromEnv(): void;
14
15
  declare function exposeContextToEnv(): void;
15
16
 
16
- declare function mockFn(): Function | undefined;
17
- declare function mockLogger(): Record<string, Function>;
17
+ declare function mockFn(): ((...args: unknown[]) => unknown) | undefined;
18
+ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
18
19
 
19
20
  declare function loadFixture(): Promise<void>;
20
21
  declare function buildFixture(): Promise<void>;
@@ -24,8 +25,8 @@ interface StartServerOptions {
24
25
  }
25
26
  declare function startServer(options?: StartServerOptions): Promise<void>;
26
27
  declare function stopServer(): Promise<void>;
27
- declare function fetch(path: string, options?: any): Promise<Response>;
28
- declare function $fetch(path: string, options?: FetchOptions): Promise<any>;
28
+ declare function fetch(path: string, options?: RequestInit): Promise<Response>;
29
+ declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
29
30
  declare function url(path: string): string;
30
31
 
31
32
  declare function setupCucumber(hooks: TestHooks): Promise<void>;
package/dist/e2e.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { d as distDir } from './shared/test-utils.B57u8E0c.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.B57u8E0c.mjs';
3
- import { u as useTestContext } from './shared/test-utils.BegIhSnH.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.BegIhSnH.mjs';
1
+ import { d as distDir } from './shared/test-utils.C7cWLW4C.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.C7cWLW4C.mjs';
3
+ import { u as useTestContext } from './shared/test-utils.D8NWZeqn.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.D8NWZeqn.mjs';
5
5
  import { consola } from 'consola';
6
6
  import { resolve } from 'pathe';
7
7
  import 'node:fs';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This is a function to render a component directly with the Nuxt server.
3
3
  */
4
- declare function $fetchComponent(filepath: string, props?: Record<string, any>): Promise<any>;
5
- declare function componentTestUrl(filepath: string, props?: Record<string, any>): string;
4
+ declare function $fetchComponent(filepath: string, props?: Record<string, unknown>): Promise<unknown>;
5
+ declare function componentTestUrl(filepath: string, props?: Record<string, unknown>): string;
6
6
 
7
7
  export { $fetchComponent, componentTestUrl };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This is a function to render a component directly with the Nuxt server.
3
3
  */
4
- declare function $fetchComponent(filepath: string, props?: Record<string, any>): Promise<any>;
5
- declare function componentTestUrl(filepath: string, props?: Record<string, any>): string;
4
+ declare function $fetchComponent(filepath: string, props?: Record<string, unknown>): Promise<unknown>;
5
+ declare function componentTestUrl(filepath: string, props?: Record<string, unknown>): string;
6
6
 
7
7
  export { $fetchComponent, componentTestUrl };
@@ -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.BegIhSnH.mjs';
3
+ import { $ as $fetch, u as useTestContext } from './shared/test-utils.D8NWZeqn.mjs';
4
4
  import 'execa';
5
5
  import 'get-port-please';
6
6
  import 'ofetch';
package/dist/module.mjs CHANGED
@@ -218,7 +218,7 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
218
218
  // Place Vitest's mock plugin after all Nuxt plugins
219
219
  async configResolved(config) {
220
220
  const plugins = config.plugins || [];
221
- const vitestPlugins = plugins.filter((p) => (p.name === "vite:mocks" || p.name.startsWith("vitest:")) && (p.enforce || p.order) === "post");
221
+ const vitestPlugins = plugins.filter((p) => (p.name === "vite:mocks" || p.name.startsWith("vitest:")) && (p.enforce || "order" in p && p.order) === "post");
222
222
  const lastNuxt = findLastIndex(
223
223
  plugins,
224
224
  (i) => i.name?.startsWith("nuxt:")
@@ -262,10 +262,10 @@ function isExpressionStatement(node) {
262
262
  return node?.type === "ExpressionStatement";
263
263
  }
264
264
  function startOf(node) {
265
- return "range" in node && node.range ? node.range[0] : node.start;
265
+ return "range" in node && node.range ? node.range[0] : "start" in node ? node.start : void 0;
266
266
  }
267
267
  function endOf(node) {
268
- return "range" in node && node.range ? node.range[1] : node.end;
268
+ return "range" in node && node.range ? node.range[1] : "end" in node ? node.end : void 0;
269
269
  }
270
270
 
271
271
  function setupImportMocking() {
@@ -367,7 +367,7 @@ const module = defineNuxtModule({
367
367
  const rawViteConfig = mergeConfig({}, await rawViteConfigPromise);
368
368
  const viteConfig = await getVitestConfigFromNuxt({ nuxt, viteConfig: defu({ test: options.vitestConfig }, rawViteConfig) });
369
369
  viteConfig.plugins = (viteConfig.plugins || []).filter((p) => {
370
- return !vitePluginBlocklist.includes(p?.name);
370
+ return !p || !("name" in p) || !vitePluginBlocklist.includes(p.name);
371
371
  });
372
372
  process.env.__NUXT_VITEST_RESOLVED__ = "true";
373
373
  const { startVitest } = await import(pathToFileURL(await resolvePath("vitest/node")).href);
@@ -1,7 +1,7 @@
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.9059LSjm.mjs';
4
+ import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.TBc-WRBw.mjs';
5
5
  import '@nuxt/schema';
6
6
  import 'execa';
7
7
 
@@ -1,7 +1,7 @@
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.9059LSjm.js';
4
+ import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.TBc-WRBw.js';
5
5
  import '@nuxt/schema';
6
6
  import 'execa';
7
7
 
@@ -1,39 +1,18 @@
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.B57u8E0c.mjs';
3
+ import { e as createTest, w as waitForHydration } from './shared/test-utils.C7cWLW4C.mjs';
4
4
  import 'node:path';
5
5
  import 'defu';
6
6
  import 'consola';
7
7
  import 'node:fs';
8
8
  import '@nuxt/kit';
9
- import { d as url } from './shared/test-utils.BegIhSnH.mjs';
9
+ import { d as url } from './shared/test-utils.D8NWZeqn.mjs';
10
10
  import 'pathe';
11
11
  import 'node:url';
12
12
  import 'execa';
13
13
  import 'get-port-please';
14
14
  import 'ofetch';
15
15
 
16
- {
17
- if (process.env.TEST_WORKER_INDEX) {
18
- for (const stream of [process.stdout, process.stderr]) {
19
- if (!stream.clearLine) {
20
- stream.clearLine = (dir, callback) => {
21
- callback?.();
22
- return true;
23
- };
24
- }
25
- if (!stream.cursorTo) {
26
- stream.cursorTo = (x, y, callback) => {
27
- if (callback)
28
- callback();
29
- else if (y instanceof Function)
30
- y();
31
- return true;
32
- };
33
- }
34
- }
35
- }
36
- }
37
16
  const test = test$1.extend({
38
17
  nuxt: [void 0, { option: true, scope: "worker" }],
39
18
  _nuxtHooks: [
@@ -1,6 +1,5 @@
1
1
  import { vi } from "vitest";
2
- if (typeof window !== "undefined" && // @ts-expect-error undefined property
3
- window.__NUXT_VITEST_ENVIRONMENT__) {
2
+ if (typeof window !== "undefined" && window.__NUXT_VITEST_ENVIRONMENT__) {
4
3
  const { useRouter } = await import("#app/composables/router");
5
4
  await import("#app/nuxt-vitest-app-entry").then((r) => r.default());
6
5
  const nuxtApp = useNuxtApp();
@@ -41,7 +41,7 @@ declare function registerEndpoint(url: string, options: EventHandler | {
41
41
  * ```
42
42
  * @see https://nuxt.com/docs/getting-started/testing#mocknuxtimport
43
43
  */
44
- declare function mockNuxtImport<T = any>(_name: string, _factory: () => T | Promise<T>): void;
44
+ declare function mockNuxtImport<T = unknown>(_name: string, _factory: () => T | Promise<T>): void;
45
45
  /**
46
46
  * `mockComponent` allows you to mock Nuxt's component.
47
47
  * @param path - component name in PascalCase, or the relative path of the component.
@@ -82,6 +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
86
  /**
86
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:
87
88
  *
@@ -109,10 +110,10 @@ type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
109
110
  * @param options optional options to set up your component
110
111
  */
111
112
  declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<ReturnType<typeof mount<T>> & {
112
- setupState: any;
113
+ setupState: SetupState;
113
114
  }>;
114
115
 
115
- type RenderOptions = RenderOptions$1 & {
116
+ type RenderOptions<C = unknown> = RenderOptions$1<C> & {
116
117
  route?: RouteLocationRaw;
117
118
  };
118
119
  /**
@@ -145,6 +146,11 @@ type RenderOptions = RenderOptions$1 & {
145
146
  * @param component the component to be tested
146
147
  * @param options optional options to set up your component
147
148
  */
148
- declare function renderSuspended<T>(component: T, options?: RenderOptions): Promise<_testing_library_vue.RenderResult>;
149
+ declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult>;
150
+ declare global {
151
+ interface Window {
152
+ __cleanup?: Array<() => void>;
153
+ }
154
+ }
149
155
 
150
156
  export { mockComponent, mockNuxtImport, mountSuspended, registerEndpoint, renderSuspended };
@@ -41,7 +41,7 @@ declare function registerEndpoint(url: string, options: EventHandler | {
41
41
  * ```
42
42
  * @see https://nuxt.com/docs/getting-started/testing#mocknuxtimport
43
43
  */
44
- declare function mockNuxtImport<T = any>(_name: string, _factory: () => T | Promise<T>): void;
44
+ declare function mockNuxtImport<T = unknown>(_name: string, _factory: () => T | Promise<T>): void;
45
45
  /**
46
46
  * `mockComponent` allows you to mock Nuxt's component.
47
47
  * @param path - component name in PascalCase, or the relative path of the component.
@@ -82,6 +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
86
  /**
86
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:
87
88
  *
@@ -109,10 +110,10 @@ type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
109
110
  * @param options optional options to set up your component
110
111
  */
111
112
  declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<ReturnType<typeof mount<T>> & {
112
- setupState: any;
113
+ setupState: SetupState;
113
114
  }>;
114
115
 
115
- type RenderOptions = RenderOptions$1 & {
116
+ type RenderOptions<C = unknown> = RenderOptions$1<C> & {
116
117
  route?: RouteLocationRaw;
117
118
  };
118
119
  /**
@@ -145,6 +146,11 @@ type RenderOptions = RenderOptions$1 & {
145
146
  * @param component the component to be tested
146
147
  * @param options optional options to set up your component
147
148
  */
148
- declare function renderSuspended<T>(component: T, options?: RenderOptions): Promise<_testing_library_vue.RenderResult>;
149
+ declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult>;
150
+ declare global {
151
+ interface Window {
152
+ __cleanup?: Array<() => void>;
153
+ }
154
+ }
149
155
 
150
156
  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, isReadonly, unref } from 'vue';
3
+ import { reactive, h as h$1, Suspense, nextTick, isReadonly, unref, effectScope } from 'vue';
4
4
  import { defu } from 'defu';
5
- import { defineComponent, useRouter, h } from '#imports';
5
+ import { defineComponent, useRouter, h, tryUseNuxtApp } from '#imports';
6
6
  import NuxtRoot from '#build/root-component.mjs';
7
7
 
8
8
  function registerEndpoint(url, options) {
@@ -73,7 +73,7 @@ async function mountSuspended(component, options) {
73
73
  route = "/",
74
74
  ..._options
75
75
  } = options || {};
76
- const vueApp = globalThis.__unctx__.get("nuxt-app").tryUse().vueApp;
76
+ const vueApp = tryUseNuxtApp()?.vueApp || globalThis.__unctx__.get("nuxt-app").tryUse().vueApp;
77
77
  const { render, setup } = component;
78
78
  let setupContext;
79
79
  let setupState;
@@ -82,8 +82,9 @@ async function mountSuspended(component, options) {
82
82
  const wrappedSetup = async (props2, setupContext2) => {
83
83
  passedProps = props2;
84
84
  if (setup) {
85
- setupState = await setup(props2, setupContext2);
86
- return setupState;
85
+ const result = await setup(props2, setupContext2);
86
+ setupState = result && typeof result === "object" ? result : {};
87
+ return result;
87
88
  }
88
89
  };
89
90
  return new Promise(
@@ -150,7 +151,7 @@ async function mountSuspended(component, options) {
150
151
  stubs: {
151
152
  Suspense: false,
152
153
  MountSuspendedHelper: false,
153
- [typeof component.name === "string" ? component.name : "MountSuspendedComponent"]: false
154
+ [component && typeof component === "object" && "name" in component && typeof component.name === "string" ? component.name : "MountSuspendedComponent"]: false
154
155
  },
155
156
  components: { RouterLink }
156
157
  }
@@ -171,21 +172,28 @@ async function renderSuspended(component, options) {
171
172
  ..._options
172
173
  } = options || {};
173
174
  const { render: renderFromTestingLibrary } = await import('@testing-library/vue');
174
- const { vueApp } = globalThis.__unctx__.get("nuxt-app").tryUse();
175
+ const vueApp = tryUseNuxtApp()?.vueApp || globalThis.__unctx__.get("nuxt-app").tryUse().vueApp;
175
176
  const { render, setup } = component;
177
+ for (const fn of window.__cleanup || []) {
178
+ fn();
179
+ }
176
180
  document.querySelector(`#${WRAPPER_EL_ID}`)?.remove();
177
181
  let setupContext;
178
182
  return new Promise((resolve) => {
179
183
  const utils = renderFromTestingLibrary(
180
184
  {
181
- // eslint-disable-next-line @typescript-eslint/no-shadow
182
185
  setup: (props2, ctx) => {
183
186
  setupContext = ctx;
184
- return NuxtRoot.setup(props2, {
187
+ const scope = effectScope();
188
+ window.__cleanup || (window.__cleanup = []);
189
+ window.__cleanup.push(() => {
190
+ scope.stop();
191
+ });
192
+ return scope.run(() => NuxtRoot.setup(props2, {
185
193
  ...ctx,
186
194
  expose: () => {
187
195
  }
188
- });
196
+ }));
189
197
  },
190
198
  render: (renderContext) => (
191
199
  // See discussions in https://github.com/testing-library/vue-testing-library/issues/230
@@ -205,12 +213,9 @@ async function renderSuspended(component, options) {
205
213
  const clonedComponent = {
206
214
  ...component,
207
215
  render: render ? (_ctx, ...args) => render(renderContext, ...args) : void 0,
208
- setup: setup ? (
209
- // eslint-disable-next-line @typescript-eslint/no-shadow
210
- (props2) => setup(props2, setupContext)
211
- ) : void 0
216
+ setup: setup ? (props2) => setup(props2, setupContext) : void 0
212
217
  };
213
- return () => h$1(clonedComponent, { ...props, ...attrs }, slots);
218
+ return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...attrs }, slots);
214
219
  }
215
220
  })
216
221
  }
@@ -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.BegIhSnH.mjs';
1
+ import { u as useTestContext, d as url, c as createTestContext, s as setTestContext, b as stopServer, a as startServer } from './test-utils.D8NWZeqn.mjs';
2
2
  import { existsSync, promises } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
4
  import { defu } from 'defu';
@@ -164,7 +164,7 @@ function createTest(options) {
164
164
  if (ctx.browser) {
165
165
  await ctx.browser.close();
166
166
  }
167
- await Promise.all((ctx.teardown || []).map((fn) => fn()));
167
+ await Promise.all(!ctx.teardown ? [] : ctx.teardown.map((fn) => fn()));
168
168
  };
169
169
  const setup2 = async () => {
170
170
  if (ctx.options.fixture) {
@@ -84,7 +84,7 @@ async function startServer(options = {}) {
84
84
  for (let i = 0; i < 150; i++) {
85
85
  await new Promise((resolve2) => setTimeout(resolve2, 100));
86
86
  try {
87
- const res = await $fetch(ctx.nuxt.options.app.baseURL);
87
+ const res = await $fetch(ctx.nuxt.options.app.baseURL, { responseType: "text" });
88
88
  if (!res.includes("__NUXT_LOADING__")) {
89
89
  return;
90
90
  }
@@ -113,15 +113,15 @@ async function startServer(options = {}) {
113
113
  async function stopServer() {
114
114
  const ctx = useTestContext();
115
115
  if (ctx.serverProcess) {
116
- await ctx.serverProcess.kill();
116
+ ctx.serverProcess.kill();
117
117
  }
118
118
  }
119
119
  function fetch(path, options) {
120
120
  return fetch$1(url(path), options);
121
121
  }
122
- function $fetch(path, options) {
122
+ const $fetch = function(path, options) {
123
123
  return $fetch$1(url(path), options);
124
- }
124
+ };
125
125
  function url(path) {
126
126
  const ctx = useTestContext();
127
127
  if (!ctx.url) {
@@ -42,7 +42,7 @@ interface TestContext {
42
42
  browser?: Browser;
43
43
  url?: string;
44
44
  serverProcess?: ExecaChildProcess;
45
- mockFn?: Function;
45
+ mockFn?: (...args: unknown[]) => unknown;
46
46
  /**
47
47
  * Functions to run on the vitest `afterAll` hook.
48
48
  * Useful for removing anything created during the test.
@@ -42,7 +42,7 @@ interface TestContext {
42
42
  browser?: Browser;
43
43
  url?: string;
44
44
  serverProcess?: ExecaChildProcess;
45
- mockFn?: Function;
45
+ mockFn?: (...args: unknown[]) => unknown;
46
46
  /**
47
47
  * Functions to run on the vitest `afterAll` hook.
48
48
  * Useful for removing anything created during the test.
@@ -1,5 +1,6 @@
1
- import { Environment } from 'vitest';
1
+ import { Environment, JSDOMOptions, HappyDOMOptions } from 'vitest';
2
2
  import { App } from 'h3';
3
+ import { $Fetch } from 'nitropack';
3
4
 
4
5
  declare const _default: Environment;
5
6
 
@@ -8,15 +9,19 @@ interface NuxtWindow extends Window {
8
9
  __app: App;
9
10
  __registry: Set<string>;
10
11
  __NUXT_VITEST_ENVIRONMENT__?: boolean;
11
- __NUXT__: any;
12
- $fetch: any;
13
- fetch: any;
14
- IntersectionObserver: any;
15
- Headers: any;
12
+ __NUXT__: Record<string, unknown>;
13
+ $fetch: $Fetch;
14
+ fetch: ((input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>);
15
+ IntersectionObserver: unknown;
16
+ Headers: typeof Headers;
16
17
  }
17
- type EnvironmentNuxt = (global: any, options: Record<string, any>) => Promise<{
18
+ interface EnvironmentNuxtOptions {
19
+ jsdom?: JSDOMOptions;
20
+ happyDom?: HappyDOMOptions;
21
+ }
22
+ type EnvironmentNuxt = (global: typeof globalThis, options: EnvironmentNuxtOptions) => Promise<{
18
23
  window: NuxtWindow;
19
24
  teardown(): void;
20
25
  }>;
21
26
 
22
- export { type EnvironmentNuxt, type NuxtBuiltinEnvironment, type NuxtWindow, _default as default };
27
+ export { type EnvironmentNuxt, type EnvironmentNuxtOptions, type NuxtBuiltinEnvironment, type NuxtWindow, _default as default };
@@ -1,5 +1,6 @@
1
- import { Environment } from 'vitest';
1
+ import { Environment, JSDOMOptions, HappyDOMOptions } from 'vitest';
2
2
  import { App } from 'h3';
3
+ import { $Fetch } from 'nitropack';
3
4
 
4
5
  declare const _default: Environment;
5
6
 
@@ -8,15 +9,19 @@ interface NuxtWindow extends Window {
8
9
  __app: App;
9
10
  __registry: Set<string>;
10
11
  __NUXT_VITEST_ENVIRONMENT__?: boolean;
11
- __NUXT__: any;
12
- $fetch: any;
13
- fetch: any;
14
- IntersectionObserver: any;
15
- Headers: any;
12
+ __NUXT__: Record<string, unknown>;
13
+ $fetch: $Fetch;
14
+ fetch: ((input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>);
15
+ IntersectionObserver: unknown;
16
+ Headers: typeof Headers;
16
17
  }
17
- type EnvironmentNuxt = (global: any, options: Record<string, any>) => Promise<{
18
+ interface EnvironmentNuxtOptions {
19
+ jsdom?: JSDOMOptions;
20
+ happyDom?: HappyDOMOptions;
21
+ }
22
+ type EnvironmentNuxt = (global: typeof globalThis, options: EnvironmentNuxtOptions) => Promise<{
18
23
  window: NuxtWindow;
19
24
  teardown(): void;
20
25
  }>;
21
26
 
22
- export { type EnvironmentNuxt, type NuxtBuiltinEnvironment, type NuxtWindow, _default as default };
27
+ export { type EnvironmentNuxt, type EnvironmentNuxtOptions, type NuxtBuiltinEnvironment, type NuxtWindow, _default as default };
@@ -9,9 +9,7 @@ import { createCall, createFetch } from 'unenv/runtime/fetch/index';
9
9
  import { importModule } from 'local-pkg';
10
10
 
11
11
  const happyDom = (async function(_, { happyDom = {} }) {
12
- const { Window, GlobalWindow } = await importModule(
13
- "happy-dom"
14
- );
12
+ const { Window, GlobalWindow } = await importModule("happy-dom");
15
13
  const window = new (GlobalWindow || Window)(happyDom);
16
14
  return {
17
15
  window,
@@ -23,30 +21,21 @@ const happyDom = (async function(_, { happyDom = {} }) {
23
21
 
24
22
  const jsdom = (async function(global, { jsdom = {} }) {
25
23
  const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await importModule("jsdom");
26
- const {
27
- html = "<!DOCTYPE html>",
28
- userAgent,
29
- url = "http://localhost:3000",
30
- contentType = "text/html",
31
- pretendToBeVisual = true,
32
- includeNodeLocations = false,
33
- runScripts = "dangerously",
34
- resources,
35
- console = false,
36
- cookieJar = false,
37
- ...restOptions
38
- } = jsdom;
39
- const window = new JSDOM(html, {
40
- pretendToBeVisual,
41
- resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : void 0),
42
- runScripts,
43
- url,
44
- virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
45
- cookieJar: cookieJar ? new CookieJar() : void 0,
46
- includeNodeLocations,
47
- contentType,
48
- userAgent,
49
- ...restOptions
24
+ const jsdomOptions = defu(jsdom, {
25
+ html: "<!DOCTYPE html>",
26
+ url: "http://localhost:3000",
27
+ contentType: "text/html",
28
+ pretendToBeVisual: true,
29
+ includeNodeLocations: false,
30
+ runScripts: "dangerously",
31
+ console: false,
32
+ cookieJar: false
33
+ });
34
+ const window = new JSDOM(jsdomOptions.html, {
35
+ ...jsdomOptions,
36
+ resources: jsdomOptions.resources ?? (jsdomOptions.userAgent ? new ResourceLoader({ userAgent: jsdomOptions.userAgent }) : void 0),
37
+ virtualConsole: jsdomOptions.console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
38
+ cookieJar: jsdomOptions.cookieJar ? new CookieJar() : void 0
50
39
  }).window;
51
40
  window.scrollTo = () => {
52
41
  };
@@ -114,7 +103,10 @@ const index = {
114
103
  init = "/_" + init;
115
104
  }
116
105
  }
117
- return localFetch(init, options);
106
+ return localFetch(init.toString(), {
107
+ ...options,
108
+ headers: Array.isArray(options?.headers) ? new Headers(options?.headers) : options?.headers
109
+ });
118
110
  };
119
111
  win.$fetch = createFetch$1({ fetch: win.fetch, Headers: win.Headers });
120
112
  win.__registry = registry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/test-utils",
3
- "version": "3.12.1",
3
+ "version": "3.13.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/test-utils.git"
@@ -30,9 +30,9 @@
30
30
  "vitest-environment.d.ts"
31
31
  ],
32
32
  "scripts": {
33
- "lint": "eslint --ext .vue,.ts,.js,.mjs .",
34
- "lint:fix": "eslint --ext .vue,.ts,.js,.mjs . --fix",
35
- "test:examples": "pnpm -r test --filter !nuxt-app-cucumber && pnpm -r test --filter nuxt-app-cucumber",
33
+ "lint": "eslint .",
34
+ "lint:fix": "eslint . --fix",
35
+ "test:examples": "pnpm -r test --filter !example-app-cucumber && pnpm -r test --filter example-app-cucumber",
36
36
  "test:types": "vue-tsc --noEmit",
37
37
  "test:unit": "vitest test/unit --run",
38
38
  "prepack": "unbuild",
@@ -40,8 +40,8 @@
40
40
  "release": "pnpm prepack && pnpm test:examples && changelogen --release --push"
41
41
  },
42
42
  "dependencies": {
43
- "@nuxt/kit": "^3.11.1",
44
- "@nuxt/schema": "^3.11.1",
43
+ "@nuxt/kit": "^3.11.2",
44
+ "@nuxt/schema": "^3.11.2",
45
45
  "c12": "^1.10.0",
46
46
  "consola": "^3.2.3",
47
47
  "defu": "^6.1.4",
@@ -51,62 +51,60 @@
51
51
  "fake-indexeddb": "^5.0.2",
52
52
  "get-port-please": "^3.1.2",
53
53
  "local-pkg": "^0.5.0",
54
- "magic-string": "^0.30.8",
55
- "node-fetch-native": "^1.6.2",
56
- "ofetch": "^1.3.3",
54
+ "magic-string": "^0.30.10",
55
+ "node-fetch-native": "^1.6.4",
56
+ "ofetch": "^1.3.4",
57
57
  "pathe": "^1.1.2",
58
58
  "perfect-debounce": "^1.0.0",
59
- "radix3": "^1.1.1",
59
+ "radix3": "^1.1.2",
60
60
  "scule": "^1.3.0",
61
61
  "std-env": "^3.7.0",
62
- "ufo": "^1.5.2",
62
+ "ufo": "^1.5.3",
63
63
  "unenv": "^1.9.0",
64
- "unplugin": "^1.10.0",
64
+ "unplugin": "^1.10.1",
65
65
  "vitest-environment-nuxt": "^1.0.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@cucumber/cucumber": "10.3.1",
68
+ "@cucumber/cucumber": "10.7.0",
69
69
  "@jest/globals": "29.7.0",
70
70
  "@nuxt/devtools": "1.0.8",
71
- "@nuxt/eslint-config": "0.2.0",
72
- "@nuxt/module-builder": "0.5.5",
73
- "@playwright/test": "1.42.1",
74
- "@testing-library/vue": "8.0.3",
71
+ "@nuxt/eslint-config": "0.3.13",
72
+ "@nuxt/module-builder": "0.6.0",
73
+ "@playwright/test": "1.44.0",
74
+ "@testing-library/vue": "8.1.0",
75
75
  "@types/estree": "1.0.5",
76
76
  "@types/jsdom": "21.1.6",
77
77
  "@types/semver": "7.5.8",
78
- "@vitest/ui": "1.4.0",
79
- "@vue/test-utils": "2.4.5",
78
+ "@vitest/ui": "1.6.0",
79
+ "@vue/test-utils": "2.4.6",
80
80
  "changelogen": "0.5.5",
81
- "eslint": "8.57.0",
82
- "eslint-plugin-import": "2.29.1",
83
- "eslint-plugin-jsdoc": "48.2.1",
84
- "eslint-plugin-no-only-tests": "3.1.0",
85
- "eslint-plugin-unicorn": "51.0.1",
81
+ "eslint": "9.3.0",
86
82
  "h3": "1.11.1",
87
83
  "jiti": "1.21.0",
88
- "nuxt": "3.11.1",
89
- "playwright-core": "1.42.1",
90
- "rollup": "4.13.0",
91
- "semver": "7.6.0",
84
+ "nitropack": "2.9.6",
85
+ "nuxt": "3.11.2",
86
+ "playwright-core": "1.44.0",
87
+ "rollup": "4.17.2",
88
+ "semver": "7.6.2",
92
89
  "unbuild": "latest",
93
90
  "unimport": "3.7.1",
94
- "vite": "5.1.6",
95
- "vitest": "1.4.0",
96
- "vue-router": "4.3.0",
97
- "vue-tsc": "2.0.6"
91
+ "vite": "5.2.11",
92
+ "vitest": "1.6.0",
93
+ "vue-router": "4.3.2",
94
+ "vue-tsc": "2.0.19"
98
95
  },
99
96
  "peerDependencies": {
100
97
  "@cucumber/cucumber": "^10.3.1",
101
98
  "@jest/globals": "^29.5.0",
102
- "@playwright/test": "^1.42.1",
99
+ "@playwright/test": "^1.43.1",
103
100
  "@testing-library/vue": "^7.0.0 || ^8.0.1",
104
101
  "@vitest/ui": "^0.34.6 || ^1.0.0",
105
102
  "@vue/test-utils": "^2.4.2",
106
103
  "h3": "*",
107
104
  "happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
108
105
  "jsdom": "^22.0.0 || ^23.0.0 || ^24.0.0",
109
- "playwright-core": "^1.34.3",
106
+ "nitropack": "*",
107
+ "playwright-core": "^1.43.1",
110
108
  "vite": "*",
111
109
  "vitest": "^0.34.6 || ^1.0.0",
112
110
  "vue": "^3.3.4",
@@ -145,15 +143,21 @@
145
143
  }
146
144
  },
147
145
  "resolutions": {
148
- "@nuxt/kit": "^3.11.1",
149
- "@nuxt/schema": "^3.11.1",
146
+ "@cucumber/cucumber": "10.7.0",
147
+ "@nuxt/kit": "^3.11.2",
148
+ "@nuxt/schema": "^3.11.2",
150
149
  "@nuxt/test-utils": "workspace:*",
151
- "rollup": "4.13.0",
152
- "vite": "5.1.6",
153
- "vue": "^3.4.21"
150
+ "rollup": "4.17.2",
151
+ "vite": "5.2.11",
152
+ "vue": "^3.4.27"
154
153
  },
155
154
  "engines": {
156
- "node": "^14.18.0 || >=16.10.0"
155
+ "node": ">=18.20.2"
157
156
  },
158
- "packageManager": "pnpm@8.15.5"
159
- }
157
+ "packageManager": "pnpm@9.1.1",
158
+ "pnpm": {
159
+ "patchedDependencies": {
160
+ "nuxt@3.11.2": "patches/nuxt@3.11.2.patch"
161
+ }
162
+ }
163
+ }