@nuxt/test-utils 3.21.0 → 3.23.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.
Files changed (32) hide show
  1. package/README.md +1 -1
  2. package/dist/config.d.mts +3 -3
  3. package/dist/config.mjs +40 -21
  4. package/dist/e2e.d.mts +3 -2
  5. package/dist/e2e.mjs +17 -13
  6. package/dist/experimental.mjs +1 -1
  7. package/dist/module.mjs +721 -148
  8. package/dist/playwright.d.mts +2 -1
  9. package/dist/playwright.mjs +3 -3
  10. package/dist/runtime/shared/environment.mjs +11 -66
  11. package/dist/runtime/shared/h3-v1.d.ts +6 -0
  12. package/dist/runtime/shared/h3-v1.mjs +69 -0
  13. package/dist/runtime/shared/h3-v2.d.ts +6 -0
  14. package/dist/runtime/shared/h3-v2.mjs +35 -0
  15. package/dist/runtime/shared/h3.d.ts +3 -0
  16. package/dist/runtime/shared/h3.mjs +3 -0
  17. package/dist/runtime/shared/nuxt.d.ts +1 -1
  18. package/dist/runtime/shared/nuxt.mjs +10 -2
  19. package/dist/runtime/shared/vue-wrapper-plugin.d.ts +50 -0
  20. package/dist/runtime/shared/vue-wrapper-plugin.mjs +41 -0
  21. package/dist/runtime-utils/index.d.mts +26 -25
  22. package/dist/runtime-utils/index.mjs +185 -272
  23. package/dist/shared/{test-utils.3NR-so9-.mjs → test-utils.5cnw0YZR.mjs} +2 -2
  24. package/dist/shared/{test-utils.G1ew4kEe.mjs → test-utils.BIY9XRkB.mjs} +1 -1
  25. package/dist/shared/{test-utils.CtwoJP76.mjs → test-utils.BsmyE2FA.mjs} +10 -8
  26. package/dist/shared/{test-utils.20kU0tZa.d.mts → test-utils.C9GKP_T5.d.mts} +3 -2
  27. package/dist/shared/test-utils.DDUpsMYL.mjs +32 -0
  28. package/dist/vitest-environment.d.mts +15 -3
  29. package/dist/vitest-environment.mjs +118 -66
  30. package/dist/vitest-wrapper/cli.d.mts +2 -0
  31. package/dist/vitest-wrapper/cli.mjs +78 -0
  32. package/package.json +32 -26
package/README.md CHANGED
@@ -11,7 +11,7 @@ Nuxt Test Utils is currently powering [the tests we use on Nuxt itself](https://
11
11
  You can find out more about how to use Nuxt Test Utils:
12
12
 
13
13
  - in [a general overview](https://nuxt.com/docs/getting-started/testing)
14
- - in [an in-depth guide for module authors](https://nuxt.com/docs/guide/going-further/modules#testing)
14
+ - in [an in-depth guide for module authors](https://nuxt.com/docs/4.x/guide/modules/testing)
15
15
 
16
16
  ## License
17
17
 
package/dist/config.d.mts CHANGED
@@ -1,9 +1,8 @@
1
- import * as vite from 'vite';
2
- import { UserConfig } from 'vite';
3
1
  import { NuxtConfig, Nuxt } from '@nuxt/schema';
4
2
  import { InlineConfig } from 'vitest/node';
5
3
  import { TestProjectInlineConfiguration } from 'vitest/config';
6
4
  import { DotenvOptions } from 'c12';
5
+ import { UserConfig, UserConfigFnPromise } from 'vite';
7
6
 
8
7
  interface GetVitestConfigOptions {
9
8
  nuxt: Nuxt;
@@ -19,7 +18,7 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
19
18
  declare function defineVitestProject(config: TestProjectInlineConfiguration): Promise<TestProjectInlineConfiguration>;
20
19
  declare function defineVitestConfig(config?: UserConfig & {
21
20
  test?: InlineConfig;
22
- }): vite.UserConfigFnPromise;
21
+ }): UserConfigFnPromise;
23
22
  interface NuxtEnvironmentOptions {
24
23
  rootDir?: string;
25
24
  /**
@@ -47,6 +46,7 @@ interface NuxtEnvironmentOptions {
47
46
  * @default 'happy-dom'
48
47
  */
49
48
  domEnvironment?: 'happy-dom' | 'jsdom';
49
+ h3Version?: 1 | 2;
50
50
  mock?: {
51
51
  intersectionObserver?: boolean;
52
52
  indexedDb?: boolean;
package/dist/config.mjs CHANGED
@@ -3,11 +3,31 @@ import { defineConfig } from 'vite';
3
3
  import { setupDotenv } from 'c12';
4
4
  import { defu } from 'defu';
5
5
  import { createResolver, findPath } from '@nuxt/kit';
6
- import { a as applyEnv, l as loadKit } from './shared/test-utils.G1ew4kEe.mjs';
6
+ import { resolveModulePath } from 'exsolve';
7
+ import { getPackageInfoSync } from 'local-pkg';
8
+ import { a as applyEnv, l as loadKit } from './shared/test-utils.BIY9XRkB.mjs';
7
9
  import 'destr';
8
10
  import 'scule';
9
11
  import 'node:url';
10
- import 'exsolve';
12
+
13
+ const PLUGIN_NAME = "nuxt:vitest:nuxt-environment-options";
14
+ const STUB_ID = "nuxt-vitest-environment-options";
15
+ function NuxtVitestEnvironmentOptionsPlugin(environmentOptions = {}) {
16
+ return {
17
+ name: PLUGIN_NAME,
18
+ enforce: "pre",
19
+ resolveId(id) {
20
+ if (id.endsWith(STUB_ID)) {
21
+ return STUB_ID;
22
+ }
23
+ },
24
+ load(id) {
25
+ if (id.endsWith(STUB_ID)) {
26
+ return `export default ${JSON.stringify(environmentOptions || {})}`;
27
+ }
28
+ }
29
+ };
30
+ }
11
31
 
12
32
  async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {}) {
13
33
  const { buildNuxt, loadNuxt } = await loadKit(rootDir);
@@ -73,7 +93,23 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
73
93
  }
74
94
  });
75
95
  }
96
+ delete options.viteConfig.root;
76
97
  options.viteConfig.plugins = (options.viteConfig.plugins || []).filter((p) => !p || !("name" in p) || !excludedPlugins.includes(p.name));
98
+ const nuxtServerIntegration = getPackageInfoSync("@nuxt/nitro-server", {
99
+ paths: [options.nuxt.options.appDir]
100
+ });
101
+ let nitroPath;
102
+ for (const nitroCandidate of [
103
+ ...nuxtServerIntegration?.packageJson.dependencies?.nitro ? ["nitro", "nitro-nightly"] : ["nitropack", "nitropack-nightly"]
104
+ ]) {
105
+ nitroPath = resolveModulePath(nitroCandidate, { from: nuxtServerIntegration?.rootPath || options.nuxt.options.appDir, try: true });
106
+ if (nitroPath) {
107
+ break;
108
+ }
109
+ }
110
+ const h3Info = getPackageInfoSync("h3", {
111
+ paths: nitroPath ? [nitroPath] : options.nuxt.options.modulesDir
112
+ });
77
113
  const resolver = createResolver(import.meta.url);
78
114
  const resolvedConfig = defu(
79
115
  // overrides
@@ -91,7 +127,6 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
91
127
  noDiscovery: true
92
128
  },
93
129
  test: {
94
- dir: process.cwd(),
95
130
  environmentOptions: {
96
131
  nuxtRuntimeConfig: applyEnv(structuredClone(options.nuxt.options.runtimeConfig), {
97
132
  prefix: "NUXT_",
@@ -169,6 +204,7 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
169
204
  environmentOptions: {
170
205
  nuxt: {
171
206
  rootId: options.nuxt.options.app.rootId || void 0,
207
+ h3Version: h3Info?.version?.startsWith("2.") ? 2 : 1,
172
208
  mock: {
173
209
  intersectionObserver: true,
174
210
  indexedDb: false
@@ -188,14 +224,12 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
188
224
  return resolvedConfig;
189
225
  }
190
226
  async function defineVitestProject(config) {
191
- if (process.env.__NUXT_VITEST_RESOLVED__) return config;
192
227
  const resolvedConfig = await resolveConfig(config);
193
228
  resolvedConfig.test.environment = "nuxt";
194
229
  return resolvedConfig;
195
230
  }
196
231
  function defineVitestConfig(config = {}) {
197
232
  return defineConfig(async () => {
198
- if (process.env.__NUXT_VITEST_RESOLVED__) return config;
199
233
  const resolvedConfig = await resolveConfig(config);
200
234
  if (resolvedConfig.test.browser?.enabled) {
201
235
  return resolvedConfig;
@@ -256,22 +290,7 @@ async function resolveConfig(config) {
256
290
  overrides: structuredClone(overrides)
257
291
  })
258
292
  );
259
- const PLUGIN_NAME = "nuxt:vitest:nuxt-environment-options";
260
- const STUB_ID = "nuxt-vitest-environment-options";
261
- resolvedConfig.plugins.push({
262
- name: PLUGIN_NAME,
263
- enforce: "pre",
264
- resolveId(id) {
265
- if (id.endsWith(STUB_ID)) {
266
- return STUB_ID;
267
- }
268
- },
269
- load(id) {
270
- if (id.endsWith(STUB_ID)) {
271
- return `export default ${JSON.stringify(resolvedConfig.test.environmentOptions || {})}`;
272
- }
273
- }
274
- });
293
+ resolvedConfig.plugins.push(NuxtVitestEnvironmentOptionsPlugin(resolvedConfig.test.environmentOptions));
275
294
  if (resolvedConfig.test.browser?.enabled) {
276
295
  if (resolvedConfig.test.environment === "nuxt") {
277
296
  resolvedConfig.test.setupFiles = Array.isArray(resolvedConfig.test.setupFiles) ? resolvedConfig.test.setupFiles : [resolvedConfig.test.setupFiles].filter(Boolean);
package/dist/e2e.d.mts CHANGED
@@ -1,9 +1,10 @@
1
- import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.20kU0tZa.mjs';
2
- export { $ as $fetch, G as GotoOptions, N as NuxtPage, 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.20kU0tZa.mjs';
1
+ import { T as TestOptions, b as TestContext, a as TestHooks } from './shared/test-utils.C9GKP_T5.mjs';
2
+ export { $ as $fetch, G as GotoOptions, N as NuxtPage, 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.C9GKP_T5.mjs';
3
3
  import { LogType } from 'consola';
4
4
  import 'playwright-core';
5
5
  import '@nuxt/schema';
6
6
  import 'tinyexec';
7
+ import 'ofetch';
7
8
 
8
9
  declare function createTestContext(options: Partial<TestOptions>): TestContext;
9
10
  declare function useTestContext(): TestContext;
package/dist/e2e.mjs CHANGED
@@ -1,13 +1,13 @@
1
- export { b as buildFixture, c as createBrowser, a as createPage, d as createTest, g as getBrowser, l as loadFixture, e as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.3NR-so9-.mjs';
2
- import { u as useTestContext } from './shared/test-utils.CtwoJP76.mjs';
3
- 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.CtwoJP76.mjs';
1
+ export { b as buildFixture, c as createBrowser, a as createPage, d as createTest, g as getBrowser, l as loadFixture, e as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.5cnw0YZR.mjs';
2
+ import { u as useTestContext } from './shared/test-utils.BsmyE2FA.mjs';
3
+ 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.BsmyE2FA.mjs';
4
4
  import { consola } from 'consola';
5
5
  import { resolve } from 'pathe';
6
6
  import { distDir } from '#dirs';
7
7
  import 'node:fs';
8
8
  import 'node:path';
9
9
  import 'defu';
10
- import './shared/test-utils.G1ew4kEe.mjs';
10
+ import './shared/test-utils.BIY9XRkB.mjs';
11
11
  import 'destr';
12
12
  import 'scule';
13
13
  import 'node:url';
@@ -52,8 +52,10 @@ async function runTests(opts) {
52
52
  {
53
53
  root: opts.rootDir,
54
54
  run: !opts.watch,
55
- deps: {
56
- inline: [/@nuxt\/test-utils/]
55
+ server: {
56
+ deps: {
57
+ inline: [/@nuxt\/test-utils/]
58
+ }
57
59
  }
58
60
  },
59
61
  // Vite options
@@ -63,13 +65,15 @@ async function runTests(opts) {
63
65
  },
64
66
  test: {
65
67
  dir: opts.rootDir,
66
- deps: {
67
- inline: [
68
- distDir,
69
- "@nuxt/test-utils",
70
- "@nuxt/test-utils-nightly",
71
- "@nuxt/test-utils-edge"
72
- ]
68
+ server: {
69
+ deps: {
70
+ inline: [
71
+ distDir,
72
+ "@nuxt/test-utils",
73
+ "@nuxt/test-utils-nightly",
74
+ "@nuxt/test-utils-edge"
75
+ ]
76
+ }
73
77
  },
74
78
  globals: true,
75
79
  globalSetup: [
@@ -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.CtwoJP76.mjs';
3
+ import { $ as $fetch, u as useTestContext } from './shared/test-utils.BsmyE2FA.mjs';
4
4
  import 'tinyexec';
5
5
  import 'get-port-please';
6
6
  import 'ofetch';