@nuxt/test-utils 3.14.0 → 3.14.2

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
@@ -1,7 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { InlineConfig } from 'vite';
3
3
  import { NuxtConfig, Nuxt } from '@nuxt/schema';
4
- import { InlineConfig as InlineConfig$1 } from 'vitest';
4
+ import { InlineConfig as InlineConfig$1 } from 'vitest/node';
5
5
  import { DotenvOptions } from 'c12';
6
6
 
7
7
  interface GetVitestConfigOptions {
@@ -18,40 +18,46 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
18
18
  declare function defineVitestConfig(config?: InlineConfig & {
19
19
  test?: InlineConfig$1;
20
20
  }): vite.UserConfig & Promise<vite.UserConfig> & (vite.UserConfigFnObject & vite.UserConfigExport);
21
+ interface NuxtEnvironmentOptions {
22
+ rootDir?: string;
23
+ /**
24
+ * The starting URL for your Nuxt window environment
25
+ * @default {http://localhost:3000}
26
+ */
27
+ url?: string;
28
+ /**
29
+ * You can define how environment options are read when loading the Nuxt configuration.
30
+ */
31
+ dotenv?: Partial<DotenvOptions>;
32
+ /**
33
+ * Configuration that will override the values in your `nuxt.config` file.
34
+ */
35
+ overrides?: NuxtConfig;
36
+ /**
37
+ * The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
38
+ * @default {nuxt-test}
39
+ */
40
+ rootId?: string;
41
+ /**
42
+ * The name of the DOM environment to use.
43
+ *
44
+ * It also needs to be installed as a dev dependency in your project.
45
+ * @default {happy-dom}
46
+ */
47
+ domEnvironment?: 'happy-dom' | 'jsdom';
48
+ mock?: {
49
+ intersectionObserver?: boolean;
50
+ indexedDb?: boolean;
51
+ };
52
+ }
53
+ declare module 'vitest/node' {
54
+ interface EnvironmentOptions {
55
+ nuxt?: NuxtEnvironmentOptions;
56
+ }
57
+ }
21
58
  declare module 'vitest' {
22
59
  interface EnvironmentOptions {
23
- nuxt?: {
24
- rootDir?: string;
25
- /**
26
- * The starting URL for your Nuxt window environment
27
- * @default {http://localhost:3000}
28
- */
29
- url?: string;
30
- /**
31
- * You can define how environment options are read when loading the Nuxt configuration.
32
- */
33
- dotenv?: Partial<DotenvOptions>;
34
- /**
35
- * Configuration that will override the values in your `nuxt.config` file.
36
- */
37
- overrides?: NuxtConfig;
38
- /**
39
- * The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
40
- * @default {nuxt-test}
41
- */
42
- rootId?: string;
43
- /**
44
- * The name of the DOM environment to use.
45
- *
46
- * It also needs to be installed as a dev dependency in your project.
47
- * @default {happy-dom}
48
- */
49
- domEnvironment?: 'happy-dom' | 'jsdom';
50
- mock?: {
51
- intersectionObserver?: boolean;
52
- indexedDb?: boolean;
53
- };
54
- };
60
+ nuxt?: NuxtEnvironmentOptions;
55
61
  }
56
62
  }
57
63
 
package/dist/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { InlineConfig } from 'vite';
3
3
  import { NuxtConfig, Nuxt } from '@nuxt/schema';
4
- import { InlineConfig as InlineConfig$1 } from 'vitest';
4
+ import { InlineConfig as InlineConfig$1 } from 'vitest/node';
5
5
  import { DotenvOptions } from 'c12';
6
6
 
7
7
  interface GetVitestConfigOptions {
@@ -18,40 +18,46 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
18
18
  declare function defineVitestConfig(config?: InlineConfig & {
19
19
  test?: InlineConfig$1;
20
20
  }): vite.UserConfig & Promise<vite.UserConfig> & (vite.UserConfigFnObject & vite.UserConfigExport);
21
+ interface NuxtEnvironmentOptions {
22
+ rootDir?: string;
23
+ /**
24
+ * The starting URL for your Nuxt window environment
25
+ * @default {http://localhost:3000}
26
+ */
27
+ url?: string;
28
+ /**
29
+ * You can define how environment options are read when loading the Nuxt configuration.
30
+ */
31
+ dotenv?: Partial<DotenvOptions>;
32
+ /**
33
+ * Configuration that will override the values in your `nuxt.config` file.
34
+ */
35
+ overrides?: NuxtConfig;
36
+ /**
37
+ * The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
38
+ * @default {nuxt-test}
39
+ */
40
+ rootId?: string;
41
+ /**
42
+ * The name of the DOM environment to use.
43
+ *
44
+ * It also needs to be installed as a dev dependency in your project.
45
+ * @default {happy-dom}
46
+ */
47
+ domEnvironment?: 'happy-dom' | 'jsdom';
48
+ mock?: {
49
+ intersectionObserver?: boolean;
50
+ indexedDb?: boolean;
51
+ };
52
+ }
53
+ declare module 'vitest/node' {
54
+ interface EnvironmentOptions {
55
+ nuxt?: NuxtEnvironmentOptions;
56
+ }
57
+ }
21
58
  declare module 'vitest' {
22
59
  interface EnvironmentOptions {
23
- nuxt?: {
24
- rootDir?: string;
25
- /**
26
- * The starting URL for your Nuxt window environment
27
- * @default {http://localhost:3000}
28
- */
29
- url?: string;
30
- /**
31
- * You can define how environment options are read when loading the Nuxt configuration.
32
- */
33
- dotenv?: Partial<DotenvOptions>;
34
- /**
35
- * Configuration that will override the values in your `nuxt.config` file.
36
- */
37
- overrides?: NuxtConfig;
38
- /**
39
- * The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
40
- * @default {nuxt-test}
41
- */
42
- rootId?: string;
43
- /**
44
- * The name of the DOM environment to use.
45
- *
46
- * It also needs to be installed as a dev dependency in your project.
47
- * @default {happy-dom}
48
- */
49
- domEnvironment?: 'happy-dom' | 'jsdom';
50
- mock?: {
51
- intersectionObserver?: boolean;
52
- indexedDb?: boolean;
53
- };
54
- };
60
+ nuxt?: NuxtEnvironmentOptions;
55
61
  }
56
62
  }
57
63
 
package/dist/config.mjs CHANGED
@@ -44,6 +44,10 @@ async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {})
44
44
  cwd: rootDir,
45
45
  fileName: ".env.test"
46
46
  }),
47
+ defaults: {
48
+ // suppress compatibility date warning for runtime environment tests
49
+ compatibilityDate: "2024-04-03"
50
+ },
47
51
  overrides: defu(
48
52
  {
49
53
  appId: "nuxt-app",
@@ -77,6 +81,7 @@ async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {})
77
81
  }
78
82
  const excludedPlugins = [
79
83
  "nuxt:import-protection",
84
+ "nuxt:import-conditions",
80
85
  "vite-plugin-checker"
81
86
  ];
82
87
  async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
package/dist/e2e.d.mts CHANGED
@@ -1,10 +1,9 @@
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';
1
+ import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.C0h0-xb8.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.C0h0-xb8.mjs';
3
3
  import { LogType } from 'consola';
4
4
  import 'playwright-core';
5
5
  import '@nuxt/schema';
6
- import 'execa';
7
- import 'nitropack';
6
+ import 'tinyexec';
8
7
 
9
8
  declare function createTestContext(options: Partial<TestOptions>): TestContext;
10
9
  declare function useTestContext(): TestContext;
package/dist/e2e.d.ts CHANGED
@@ -1,10 +1,9 @@
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';
1
+ import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.C0h0-xb8.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.C0h0-xb8.js';
3
3
  import { LogType } from 'consola';
4
4
  import 'playwright-core';
5
5
  import '@nuxt/schema';
6
- import 'execa';
7
- import 'nitropack';
6
+ import 'tinyexec';
8
7
 
9
8
  declare function createTestContext(options: Partial<TestOptions>): TestContext;
10
9
  declare function useTestContext(): TestContext;
package/dist/e2e.mjs CHANGED
@@ -1,7 +1,7 @@
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';
1
+ import { d as distDir } from './shared/test-utils.CaqvQLs_.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.CaqvQLs_.mjs';
3
+ import { u as useTestContext } from './shared/test-utils.ClQ9CUdo.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.ClQ9CUdo.mjs';
5
5
  import { consola } from 'consola';
6
6
  import { resolve } from 'pathe';
7
7
  import 'node:fs';
@@ -9,7 +9,7 @@ import 'node:path';
9
9
  import 'defu';
10
10
  import '@nuxt/kit';
11
11
  import 'node:url';
12
- import 'execa';
12
+ import 'tinyexec';
13
13
  import 'get-port-please';
14
14
  import 'ofetch';
15
15
  import 'ufo';
@@ -1,7 +1,7 @@
1
1
  import { resolve } from 'pathe';
2
2
  import { stringifyQuery } from 'ufo';
3
- import { $ as $fetch, u as useTestContext } from './shared/test-utils.iUoJhWDR.mjs';
4
- import 'execa';
3
+ import { $ as $fetch, u as useTestContext } from './shared/test-utils.ClQ9CUdo.mjs';
4
+ import 'tinyexec';
5
5
  import 'get-port-please';
6
6
  import 'ofetch';
7
7
  import '@nuxt/kit';
package/dist/module.d.mts CHANGED
@@ -6,6 +6,6 @@ interface NuxtVitestOptions {
6
6
  logToConsole?: boolean;
7
7
  vitestConfig?: UserConfig;
8
8
  }
9
- declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions>;
9
+ declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions, NuxtVitestOptions, false>;
10
10
 
11
11
  export { type NuxtVitestOptions, _default as default };
package/dist/module.d.ts CHANGED
@@ -6,6 +6,6 @@ interface NuxtVitestOptions {
6
6
  logToConsole?: boolean;
7
7
  vitestConfig?: UserConfig;
8
8
  }
9
- declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions>;
9
+ declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions, NuxtVitestOptions, false>;
10
10
 
11
11
  export { type NuxtVitestOptions, _default as default };
package/dist/module.mjs CHANGED
@@ -35,7 +35,7 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
35
35
  ecmaVersion: "latest",
36
36
  ranges: true
37
37
  });
38
- } catch (e) {
38
+ } catch {
39
39
  return;
40
40
  }
41
41
  let insertionPoint = 0;
@@ -316,7 +316,7 @@ const NuxtRootStubPlugin = createUnplugin((options) => {
316
316
  };
317
317
  });
318
318
 
319
- const vitePluginBlocklist = ["vite-plugin-vue-inspector", "vite-plugin-vue-inspector:post", "vite-plugin-inspect"];
319
+ const vitePluginBlocklist = ["vite-plugin-vue-inspector", "vite-plugin-vue-inspector:post", "vite-plugin-inspect", "nuxt:type-check"];
320
320
  const module = defineNuxtModule({
321
321
  meta: {
322
322
  name: "@nuxt/test-utils",
@@ -1,10 +1,9 @@
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.Bfk23aTC.mjs';
4
+ import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.C0h0-xb8.mjs';
5
5
  import '@nuxt/schema';
6
- import 'execa';
7
- import 'nitropack';
6
+ import 'tinyexec';
8
7
 
9
8
  type ConfigOptions = {
10
9
  nuxt: Partial<TestOptions$1> | undefined;
@@ -1,10 +1,9 @@
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.Bfk23aTC.js';
4
+ import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.C0h0-xb8.js';
5
5
  import '@nuxt/schema';
6
- import 'execa';
7
- import 'nitropack';
6
+ import 'tinyexec';
8
7
 
9
8
  type ConfigOptions = {
10
9
  nuxt: Partial<TestOptions$1> | undefined;
@@ -1,16 +1,16 @@
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.CSumGjP7.mjs';
3
+ import { e as createTest, w as waitForHydration } from './shared/test-utils.CaqvQLs_.mjs';
4
4
  import 'node:path';
5
5
  import 'defu';
6
6
  import 'ufo';
7
7
  import 'consola';
8
8
  import 'node:fs';
9
9
  import '@nuxt/kit';
10
- import { d as url } from './shared/test-utils.iUoJhWDR.mjs';
10
+ import { d as url } from './shared/test-utils.ClQ9CUdo.mjs';
11
11
  import 'pathe';
12
12
  import 'node:url';
13
- import 'execa';
13
+ import 'tinyexec';
14
14
  import 'get-port-please';
15
15
  import 'ofetch';
16
16
 
@@ -1,4 +1,4 @@
1
1
  declare const _default: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
2
2
  [key: string]: any;
3
- }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
3
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
4
4
  export default _default;
@@ -1,7 +1,6 @@
1
1
  import { Browser, BrowserContextOptions, Page, Response as Response$1, LaunchOptions } from 'playwright-core';
2
2
  import { NuxtConfig, Nuxt } from '@nuxt/schema';
3
- import { ExecaChildProcess } from 'execa';
4
- import * as nitropack from 'nitropack';
3
+ import { exec } from 'tinyexec';
5
4
 
6
5
  declare function createBrowser(): Promise<void>;
7
6
  declare function getBrowser(): Promise<Browser>;
@@ -21,30 +20,68 @@ interface StartServerOptions {
21
20
  declare function startServer(options?: StartServerOptions): Promise<void>;
22
21
  declare function stopServer(): Promise<void>;
23
22
  declare function fetch(path: string, options?: RequestInit): Promise<Response>;
24
- declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
23
+ declare const $fetch: (typeof globalThis)["$fetch"];
25
24
  declare function url(path: string): string;
26
25
 
27
26
  type TestRunner = 'vitest' | 'jest' | 'cucumber';
28
27
  interface TestOptions {
29
28
  testDir: string;
30
29
  fixture: string;
30
+ /**
31
+ * Name of the configuration file.
32
+ * @default `'nuxt.config`
33
+ */
31
34
  configFile: string;
35
+ /**
36
+ * Path to a directory with a Nuxt app to be put under test.
37
+ * @default `'.'`
38
+ */
32
39
  rootDir: string;
33
40
  buildDir: string;
34
41
  nuxtConfig: NuxtConfig;
42
+ /**
43
+ * Whether to run a separate build step.
44
+ * @default `true` (`false` if `browser` or `server` is disabled, or if a `host` is provided)
45
+ */
35
46
  build: boolean;
36
47
  dev: boolean;
48
+ /**
49
+ * The amount of time (in milliseconds) to allow for `setupTest` to complete its work (which could include building or generating files for a Nuxt application, depending on the options that are passed).
50
+ * @default `60000`
51
+ */
37
52
  setupTimeout: number;
38
53
  waitFor: number;
54
+ /**
55
+ * Under the hood, Nuxt test utils uses [`playwright`](https://playwright.dev) to carry out browser testing. If this option is set, a browser will be launched and can be controlled in the subsequent test suite.
56
+ * @default `false`
57
+ */
39
58
  browser: boolean;
59
+ /**
60
+ * Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber'`.
61
+ * @default `vitest`
62
+ */
40
63
  runner: TestRunner;
41
64
  logLevel: number;
42
65
  browserOptions: {
66
+ /** The type of browser to launch - either `chromium`, `firefox` or `webkit` */
43
67
  type: 'chromium' | 'firefox' | 'webkit';
68
+ /** `object` of options that will be passed to playwright when launching the browser. See [full API reference](https://playwright.dev/docs/api/class-browsertype#browser-type-launch). */
44
69
  launch?: LaunchOptions;
45
70
  };
71
+ /**
72
+ * Whether to launch a server to respond to requests in the test suite.
73
+ * @default `true` (`false` if a `host` is provided)
74
+ */
46
75
  server: boolean;
76
+ /**
77
+ * If provided, a URL to use as the test target instead of building and running a new server. Useful for running "real" end-to-end tests against a deployed version of your application, or against an already running local server.
78
+ * @default `undefined`
79
+ */
47
80
  host?: string;
81
+ /**
82
+ * If provided, set the launched test server port to the value.
83
+ * @default `undefined`
84
+ */
48
85
  port?: number;
49
86
  env?: StartServerOptions['env'];
50
87
  }
@@ -53,7 +90,7 @@ interface TestContext {
53
90
  nuxt?: Nuxt;
54
91
  browser?: Browser;
55
92
  url?: string;
56
- serverProcess?: ExecaChildProcess;
93
+ serverProcess?: ReturnType<typeof exec>;
57
94
  mockFn?: (...args: unknown[]) => unknown;
58
95
  /**
59
96
  * Functions to run on the vitest `afterAll` hook.
@@ -1,7 +1,6 @@
1
1
  import { Browser, BrowserContextOptions, Page, Response as Response$1, LaunchOptions } from 'playwright-core';
2
2
  import { NuxtConfig, Nuxt } from '@nuxt/schema';
3
- import { ExecaChildProcess } from 'execa';
4
- import * as nitropack from 'nitropack';
3
+ import { exec } from 'tinyexec';
5
4
 
6
5
  declare function createBrowser(): Promise<void>;
7
6
  declare function getBrowser(): Promise<Browser>;
@@ -21,30 +20,68 @@ interface StartServerOptions {
21
20
  declare function startServer(options?: StartServerOptions): Promise<void>;
22
21
  declare function stopServer(): Promise<void>;
23
22
  declare function fetch(path: string, options?: RequestInit): Promise<Response>;
24
- declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
23
+ declare const $fetch: (typeof globalThis)["$fetch"];
25
24
  declare function url(path: string): string;
26
25
 
27
26
  type TestRunner = 'vitest' | 'jest' | 'cucumber';
28
27
  interface TestOptions {
29
28
  testDir: string;
30
29
  fixture: string;
30
+ /**
31
+ * Name of the configuration file.
32
+ * @default `'nuxt.config`
33
+ */
31
34
  configFile: string;
35
+ /**
36
+ * Path to a directory with a Nuxt app to be put under test.
37
+ * @default `'.'`
38
+ */
32
39
  rootDir: string;
33
40
  buildDir: string;
34
41
  nuxtConfig: NuxtConfig;
42
+ /**
43
+ * Whether to run a separate build step.
44
+ * @default `true` (`false` if `browser` or `server` is disabled, or if a `host` is provided)
45
+ */
35
46
  build: boolean;
36
47
  dev: boolean;
48
+ /**
49
+ * The amount of time (in milliseconds) to allow for `setupTest` to complete its work (which could include building or generating files for a Nuxt application, depending on the options that are passed).
50
+ * @default `60000`
51
+ */
37
52
  setupTimeout: number;
38
53
  waitFor: number;
54
+ /**
55
+ * Under the hood, Nuxt test utils uses [`playwright`](https://playwright.dev) to carry out browser testing. If this option is set, a browser will be launched and can be controlled in the subsequent test suite.
56
+ * @default `false`
57
+ */
39
58
  browser: boolean;
59
+ /**
60
+ * Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber'`.
61
+ * @default `vitest`
62
+ */
40
63
  runner: TestRunner;
41
64
  logLevel: number;
42
65
  browserOptions: {
66
+ /** The type of browser to launch - either `chromium`, `firefox` or `webkit` */
43
67
  type: 'chromium' | 'firefox' | 'webkit';
68
+ /** `object` of options that will be passed to playwright when launching the browser. See [full API reference](https://playwright.dev/docs/api/class-browsertype#browser-type-launch). */
44
69
  launch?: LaunchOptions;
45
70
  };
71
+ /**
72
+ * Whether to launch a server to respond to requests in the test suite.
73
+ * @default `true` (`false` if a `host` is provided)
74
+ */
46
75
  server: boolean;
76
+ /**
77
+ * If provided, a URL to use as the test target instead of building and running a new server. Useful for running "real" end-to-end tests against a deployed version of your application, or against an already running local server.
78
+ * @default `undefined`
79
+ */
47
80
  host?: string;
81
+ /**
82
+ * If provided, set the launched test server port to the value.
83
+ * @default `undefined`
84
+ */
48
85
  port?: number;
49
86
  env?: StartServerOptions['env'];
50
87
  }
@@ -53,7 +90,7 @@ interface TestContext {
53
90
  nuxt?: Nuxt;
54
91
  browser?: Browser;
55
92
  url?: string;
56
- serverProcess?: ExecaChildProcess;
93
+ serverProcess?: ReturnType<typeof exec>;
57
94
  mockFn?: (...args: unknown[]) => unknown;
58
95
  /**
59
96
  * Functions to run on the vitest `afterAll` hook.
@@ -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.iUoJhWDR.mjs';
1
+ import { u as useTestContext, d as url, c as createTestContext, s as setTestContext, b as stopServer, a as startServer } from './test-utils.ClQ9CUdo.mjs';
2
2
  import { existsSync, promises } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
4
  import { defu } from 'defu';
@@ -1,4 +1,4 @@
1
- import { execa } from 'execa';
1
+ import { exec } from 'tinyexec';
2
2
  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';
@@ -18,7 +18,10 @@ function createTestContext(options) {
18
18
  logLevel: 1,
19
19
  server: true,
20
20
  build: options.browser !== false || options.server !== false,
21
- nuxtConfig: {},
21
+ nuxtConfig: {
22
+ // suppress compatibility date warning for runtime environment tests
23
+ compatibilityDate: "2024-04-03"
24
+ },
22
25
  browserOptions: {
23
26
  type: "chromium"
24
27
  }
@@ -71,18 +74,20 @@ async function startServer(options = {}) {
71
74
  ctx.url = `http://${host}:${port}/`;
72
75
  if (ctx.options.dev) {
73
76
  const nuxiCLI = await kit.resolvePath("nuxi/cli");
74
- ctx.serverProcess = execa(nuxiCLI, ["_dev"], {
75
- cwd: ctx.nuxt.options.rootDir,
76
- stdio: "inherit",
77
- env: {
78
- ...process.env,
79
- _PORT: String(port),
80
- // Used by internal _dev command
81
- PORT: String(port),
82
- HOST: host,
83
- NODE_ENV: "development",
84
- ...options.env,
85
- ...ctx.options.env
77
+ ctx.serverProcess = exec(nuxiCLI, ["_dev"], {
78
+ nodeOptions: {
79
+ cwd: ctx.nuxt.options.rootDir,
80
+ stdio: "inherit",
81
+ env: {
82
+ ...process.env,
83
+ _PORT: String(port),
84
+ // Used by internal _dev command
85
+ PORT: String(port),
86
+ HOST: host,
87
+ NODE_ENV: "development",
88
+ ...options.env,
89
+ ...ctx.options.env
90
+ }
86
91
  }
87
92
  });
88
93
  await waitForPort(port, { retries: 32, host }).catch(() => {
@@ -91,7 +96,9 @@ async function startServer(options = {}) {
91
96
  for (let i = 0; i < 150; i++) {
92
97
  await new Promise((resolve2) => setTimeout(resolve2, 100));
93
98
  try {
94
- const res = await $fetch(ctx.nuxt.options.app.baseURL, { responseType: "text" });
99
+ const res = await $fetch(ctx.nuxt.options.app.baseURL, {
100
+ responseType: "text"
101
+ });
95
102
  if (!res.includes("__NUXT_LOADING__")) {
96
103
  return;
97
104
  }
@@ -102,19 +109,23 @@ async function startServer(options = {}) {
102
109
  ctx.serverProcess.kill();
103
110
  throw lastError || new Error("Timeout waiting for dev server!");
104
111
  } else {
105
- ctx.serverProcess = execa("node", [
106
- resolve$1(ctx.nuxt.options.nitro.output.dir, "server/index.mjs")
107
- ], {
108
- stdio: "inherit",
109
- env: {
110
- ...process.env,
111
- PORT: String(port),
112
- HOST: host,
113
- NODE_ENV: "test",
114
- ...options.env,
115
- ...ctx.options.env
112
+ ctx.serverProcess = exec(
113
+ "node",
114
+ [resolve$1(ctx.nuxt.options.nitro.output.dir, "server/index.mjs")],
115
+ {
116
+ nodeOptions: {
117
+ stdio: "inherit",
118
+ env: {
119
+ ...process.env,
120
+ PORT: String(port),
121
+ HOST: host,
122
+ NODE_ENV: "test",
123
+ ...options.env,
124
+ ...ctx.options.env
125
+ }
126
+ }
116
127
  }
117
- });
128
+ );
118
129
  await waitForPort(port, { retries: 20, host });
119
130
  }
120
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/test-utils",
3
- "version": "3.14.0",
3
+ "version": "3.14.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/test-utils.git"
@@ -40,18 +40,17 @@
40
40
  "release": "pnpm prepack && pnpm test:examples && changelogen --release --push"
41
41
  },
42
42
  "dependencies": {
43
- "@nuxt/kit": "^3.12.4",
44
- "@nuxt/schema": "^3.12.4",
45
- "c12": "^1.11.1",
43
+ "@nuxt/kit": "^3.13.1",
44
+ "@nuxt/schema": "^3.13.1",
45
+ "c12": "^1.11.2",
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
- "execa": "^8.0.1",
51
50
  "fake-indexeddb": "^6.0.0",
52
51
  "get-port-please": "^3.1.2",
53
52
  "local-pkg": "^0.5.0",
54
- "magic-string": "^0.30.10",
53
+ "magic-string": "^0.30.11",
55
54
  "node-fetch-native": "^1.6.4",
56
55
  "ofetch": "^1.3.4",
57
56
  "pathe": "^1.1.2",
@@ -59,50 +58,53 @@
59
58
  "radix3": "^1.1.2",
60
59
  "scule": "^1.3.0",
61
60
  "std-env": "^3.7.0",
61
+ "tinyexec": "^0.3.0",
62
62
  "ufo": "^1.5.4",
63
63
  "unenv": "^1.10.0",
64
- "unplugin": "^1.12.0",
65
- "vitest-environment-nuxt": "^1.0.0"
64
+ "unplugin": "^1.14.0",
65
+ "vitest-environment-nuxt": "^1.0.1"
66
66
  },
67
67
  "devDependencies": {
68
- "@cucumber/cucumber": "10.8.0",
68
+ "@cucumber/cucumber": "11.0.0",
69
69
  "@jest/globals": "29.7.0",
70
70
  "@nuxt/devtools": "1.0.8",
71
- "@nuxt/eslint-config": "0.3.13",
72
- "@nuxt/module-builder": "0.8.1",
73
- "@playwright/test": "1.45.3",
71
+ "@nuxt/eslint-config": "0.5.6",
72
+ "@nuxt/module-builder": "0.8.3",
73
+ "@playwright/test": "1.47.0",
74
74
  "@testing-library/vue": "8.1.0",
75
75
  "@types/estree": "1.0.5",
76
76
  "@types/jsdom": "21.1.7",
77
77
  "@types/semver": "7.5.8",
78
- "@vitest/ui": "2.0.4",
78
+ "@vitest/ui": "2.0.5",
79
79
  "@vue/test-utils": "2.4.6",
80
80
  "changelogen": "0.5.5",
81
- "eslint": "9.7.0",
81
+ "compatx": "0.1.8",
82
+ "eslint": "9.10.0",
82
83
  "h3": "1.12.0",
83
84
  "jiti": "1.21.6",
84
85
  "nitropack": "2.9.7",
85
- "nuxt": "3.12.4",
86
- "playwright-core": "1.45.3",
87
- "rollup": "4.19.0",
86
+ "nuxt": "3.13.1",
87
+ "playwright-core": "1.47.0",
88
+ "rollup": "4.21.2",
88
89
  "semver": "7.6.3",
90
+ "typescript": "5.6.2",
89
91
  "unbuild": "latest",
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"
92
+ "unimport": "3.11.1",
93
+ "vite": "5.4.3",
94
+ "vitest": "2.0.5",
95
+ "vue-router": "4.4.3",
96
+ "vue-tsc": "2.1.6"
95
97
  },
96
98
  "peerDependencies": {
97
- "@cucumber/cucumber": "^10.3.1",
99
+ "@cucumber/cucumber": "^10.3.1 || ^11.0.0",
98
100
  "@jest/globals": "^29.5.0",
99
101
  "@playwright/test": "^1.43.1",
100
102
  "@testing-library/vue": "^7.0.0 || ^8.0.1",
101
103
  "@vitest/ui": "^0.34.6 || ^1.0.0 || ^2.0.0",
102
104
  "@vue/test-utils": "^2.4.2",
103
105
  "h3": "*",
104
- "happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
105
- "jsdom": "^22.0.0 || ^23.0.0 || ^24.0.0",
106
+ "happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
107
+ "jsdom": "^22.0.0 || ^23.0.0 || ^24.0.0 || ^25.0.0",
106
108
  "nitropack": "*",
107
109
  "playwright-core": "^1.43.1",
108
110
  "vite": "*",
@@ -143,21 +145,19 @@
143
145
  }
144
146
  },
145
147
  "resolutions": {
146
- "@cucumber/cucumber": "10.8.0",
147
- "@nuxt/kit": "^3.12.4",
148
- "@nuxt/schema": "^3.12.4",
148
+ "@cucumber/cucumber": "11.0.0",
149
+ "@nuxt/devtools": "1.0.8",
150
+ "@nuxt/kit": "^3.13.1",
151
+ "@nuxt/schema": "^3.13.1",
149
152
  "@nuxt/test-utils": "workspace:*",
150
- "rollup": "4.19.0",
151
- "vite": "5.3.5",
152
- "vue": "^3.4.34"
153
+ "rollup": "4.21.2",
154
+ "vite": "5.4.3",
155
+ "vite-node": "2.0.5",
156
+ "vitest": "2.0.5",
157
+ "vue": "^3.5.4"
153
158
  },
154
159
  "engines": {
155
160
  "node": ">=18.20.4"
156
161
  },
157
- "packageManager": "pnpm@9.6.0",
158
- "pnpm": {
159
- "patchedDependencies": {
160
- "nuxt@3.11.2": "patches/nuxt@3.11.2.patch"
161
- }
162
- }
162
+ "packageManager": "pnpm@9.10.0"
163
163
  }