@nuxt/test-utils 3.20.1 → 3.22.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/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
  /**
package/dist/config.mjs CHANGED
@@ -1,42 +1,35 @@
1
- import process$1 from 'node:process';
1
+ import process from 'node:process';
2
2
  import { defineConfig } from 'vite';
3
3
  import { setupDotenv } from 'c12';
4
4
  import { defu } from 'defu';
5
- import { createResolver, findPath, loadNuxt, buildNuxt } from '@nuxt/kit';
6
- import destr from 'destr';
7
- import { snakeCase } from 'scule';
5
+ import { createResolver, findPath } from '@nuxt/kit';
6
+ import { a as applyEnv, l as loadKit } from './shared/test-utils.BIY9XRkB.mjs';
7
+ import 'destr';
8
+ import 'scule';
9
+ import 'node:url';
10
+ import 'exsolve';
8
11
 
9
- function getEnv(key, opts) {
10
- const env = opts.env ?? process.env;
11
- const envKey = snakeCase(key).toUpperCase();
12
- return destr(
13
- env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey]
14
- );
15
- }
16
- function _isObject(input) {
17
- return typeof input === "object" && !Array.isArray(input);
18
- }
19
- function applyEnv(obj, opts, parentKey = "") {
20
- for (const key in obj) {
21
- const subKey = parentKey ? `${parentKey}_${key}` : key;
22
- const envValue = getEnv(subKey, opts);
23
- if (_isObject(obj[key])) {
24
- if (_isObject(envValue)) {
25
- obj[key] = { ...obj[key], ...envValue };
26
- applyEnv(obj[key], opts, subKey);
27
- } else if (envValue === void 0) {
28
- applyEnv(obj[key], opts, subKey);
29
- } else {
30
- obj[key] = envValue ?? obj[key];
12
+ const PLUGIN_NAME = "nuxt:vitest:nuxt-environment-options";
13
+ const STUB_ID = "nuxt-vitest-environment-options";
14
+ function NuxtVitestEnvironmentOptionsPlugin(environmentOptions = {}) {
15
+ return {
16
+ name: PLUGIN_NAME,
17
+ enforce: "pre",
18
+ resolveId(id) {
19
+ if (id.endsWith(STUB_ID)) {
20
+ return STUB_ID;
21
+ }
22
+ },
23
+ load(id) {
24
+ if (id.endsWith(STUB_ID)) {
25
+ return `export default ${JSON.stringify(environmentOptions || {})}`;
31
26
  }
32
- } else {
33
- obj[key] = envValue ?? obj[key];
34
27
  }
35
- }
36
- return obj;
28
+ };
37
29
  }
38
30
 
39
- async function startNuxtAndGetViteConfig(rootDir = process$1.cwd(), options = {}) {
31
+ async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {}) {
32
+ const { buildNuxt, loadNuxt } = await loadKit(rootDir);
40
33
  const nuxt = await loadNuxt({
41
34
  cwd: rootDir,
42
35
  dev: false,
@@ -89,7 +82,7 @@ const excludedPlugins = [
89
82
  "vite-plugin-vue-tracer"
90
83
  ];
91
84
  async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
92
- const { rootDir = process$1.cwd(), ..._overrides } = loadNuxtOptions.overrides || {};
85
+ const { rootDir = process.cwd(), ..._overrides } = loadNuxtOptions.overrides || {};
93
86
  if (!options) {
94
87
  options = await startNuxtAndGetViteConfig(rootDir, {
95
88
  dotenv: loadNuxtOptions.dotenv,
@@ -99,6 +92,7 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
99
92
  }
100
93
  });
101
94
  }
95
+ delete options.viteConfig.root;
102
96
  options.viteConfig.plugins = (options.viteConfig.plugins || []).filter((p) => !p || !("name" in p) || !excludedPlugins.includes(p.name));
103
97
  const resolver = createResolver(import.meta.url);
104
98
  const resolvedConfig = defu(
@@ -117,7 +111,6 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
117
111
  noDiscovery: true
118
112
  },
119
113
  test: {
120
- dir: process$1.cwd(),
121
114
  environmentOptions: {
122
115
  nuxtRuntimeConfig: applyEnv(structuredClone(options.nuxt.options.runtimeConfig), {
123
116
  prefix: "NUXT_",
@@ -214,14 +207,12 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
214
207
  return resolvedConfig;
215
208
  }
216
209
  async function defineVitestProject(config) {
217
- if (process$1.env.__NUXT_VITEST_RESOLVED__) return config;
218
210
  const resolvedConfig = await resolveConfig(config);
219
211
  resolvedConfig.test.environment = "nuxt";
220
212
  return resolvedConfig;
221
213
  }
222
214
  function defineVitestConfig(config = {}) {
223
215
  return defineConfig(async () => {
224
- if (process$1.env.__NUXT_VITEST_RESOLVED__) return config;
225
216
  const resolvedConfig = await resolveConfig(config);
226
217
  if (resolvedConfig.test.browser?.enabled) {
227
218
  return resolvedConfig;
@@ -282,22 +273,7 @@ async function resolveConfig(config) {
282
273
  overrides: structuredClone(overrides)
283
274
  })
284
275
  );
285
- const PLUGIN_NAME = "nuxt:vitest:nuxt-environment-options";
286
- const STUB_ID = "nuxt-vitest-environment-options";
287
- resolvedConfig.plugins.push({
288
- name: PLUGIN_NAME,
289
- enforce: "pre",
290
- resolveId(id) {
291
- if (id.endsWith(STUB_ID)) {
292
- return STUB_ID;
293
- }
294
- },
295
- load(id) {
296
- if (id.endsWith(STUB_ID)) {
297
- return `export default ${JSON.stringify(resolvedConfig.test.environmentOptions || {})}`;
298
- }
299
- }
300
- });
276
+ resolvedConfig.plugins.push(NuxtVitestEnvironmentOptionsPlugin(resolvedConfig.test.environmentOptions));
301
277
  if (resolvedConfig.test.browser?.enabled) {
302
278
  if (resolvedConfig.test.environment === "nuxt") {
303
279
  resolvedConfig.test.setupFiles = Array.isArray(resolvedConfig.test.setupFiles) ? resolvedConfig.test.setupFiles : [resolvedConfig.test.setupFiles].filter(Boolean);
package/dist/e2e.d.mts CHANGED
@@ -1,5 +1,5 @@
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.ZByFDqps.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.ZByFDqps.mjs';
3
3
  import { LogType } from 'consola';
4
4
  import 'playwright-core';
5
5
  import '@nuxt/schema';
package/dist/e2e.mjs CHANGED
@@ -1,13 +1,17 @@
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.CtoalVlS.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.D2ZzXztg.mjs';
2
+ import { u as useTestContext } from './shared/test-utils.C_clWQBc.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.C_clWQBc.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 '@nuxt/kit';
10
+ import './shared/test-utils.BIY9XRkB.mjs';
11
+ import 'destr';
12
+ import 'scule';
13
+ import 'node:url';
14
+ import 'exsolve';
11
15
  import 'tinyexec';
12
16
  import 'get-port-please';
13
17
  import 'ofetch';
@@ -48,8 +52,10 @@ async function runTests(opts) {
48
52
  {
49
53
  root: opts.rootDir,
50
54
  run: !opts.watch,
51
- deps: {
52
- inline: [/@nuxt\/test-utils/]
55
+ server: {
56
+ deps: {
57
+ inline: [/@nuxt\/test-utils/]
58
+ }
53
59
  }
54
60
  },
55
61
  // Vite options
@@ -59,13 +65,15 @@ async function runTests(opts) {
59
65
  },
60
66
  test: {
61
67
  dir: opts.rootDir,
62
- deps: {
63
- inline: [
64
- distDir,
65
- "@nuxt/test-utils",
66
- "@nuxt/test-utils-nightly",
67
- "@nuxt/test-utils-edge"
68
- ]
68
+ server: {
69
+ deps: {
70
+ inline: [
71
+ distDir,
72
+ "@nuxt/test-utils",
73
+ "@nuxt/test-utils-nightly",
74
+ "@nuxt/test-utils-edge"
75
+ ]
76
+ }
69
77
  },
70
78
  globals: true,
71
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.C_clWQBc.mjs';
4
4
  import 'tinyexec';
5
5
  import 'get-port-please';
6
6
  import 'ofetch';