@nuxt/test-utils 3.22.0 → 4.0.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
@@ -1,5 +1,8 @@
1
1
  # Nuxt Test Utils
2
2
 
3
+ [![nuxt.care health](https://img.shields.io/endpoint?url=https://nuxt.care/api/badge/test-utils)](https://nuxt.care/?search=test-utils)
4
+
5
+
3
6
  🧪 [Nuxt](https://nuxt.com/) Test Utils
4
7
 
5
8
  ## Overview
package/dist/config.d.mts CHANGED
@@ -46,6 +46,7 @@ interface NuxtEnvironmentOptions {
46
46
  * @default 'happy-dom'
47
47
  */
48
48
  domEnvironment?: 'happy-dom' | 'jsdom';
49
+ h3Version?: 1 | 2;
49
50
  mock?: {
50
51
  intersectionObserver?: boolean;
51
52
  indexedDb?: boolean;
@@ -56,11 +57,6 @@ declare module 'vitest/node' {
56
57
  nuxt?: NuxtEnvironmentOptions;
57
58
  }
58
59
  }
59
- declare module 'vitest' {
60
- interface EnvironmentOptions {
61
- nuxt?: NuxtEnvironmentOptions;
62
- }
63
- }
64
60
 
65
61
  export { defineVitestConfig, defineVitestProject, getVitestConfigFromNuxt };
66
62
  export type { NuxtEnvironmentOptions };
package/dist/config.mjs CHANGED
@@ -1,13 +1,14 @@
1
1
  import process from 'node:process';
2
2
  import { defineConfig } from 'vite';
3
3
  import { setupDotenv } from 'c12';
4
- import { defu } from 'defu';
4
+ import { createDefu, defu } from 'defu';
5
5
  import { createResolver, findPath } from '@nuxt/kit';
6
+ import { resolveModulePath } from 'exsolve';
7
+ import { getPackageInfoSync } from 'local-pkg';
6
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';
11
12
 
12
13
  const PLUGIN_NAME = "nuxt:vitest:nuxt-environment-options";
13
14
  const STUB_ID = "nuxt-vitest-environment-options";
@@ -94,6 +95,21 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
94
95
  }
95
96
  delete options.viteConfig.root;
96
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
+ });
97
113
  const resolver = createResolver(import.meta.url);
98
114
  const resolvedConfig = defu(
99
115
  // overrides
@@ -188,6 +204,7 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
188
204
  environmentOptions: {
189
205
  nuxt: {
190
206
  rootId: options.nuxt.options.app.rootId || void 0,
207
+ h3Version: h3Info?.version?.startsWith("2.") ? 2 : 1,
191
208
  mock: {
192
209
  intersectionObserver: true,
193
210
  indexedDb: false
@@ -224,25 +241,29 @@ function defineVitestConfig(config = {}) {
224
241
  }
225
242
  const defaultEnvironment = resolvedConfig.test.environment || "node";
226
243
  if (defaultEnvironment !== "nuxt") {
227
- const key = "projects" in resolvedConfig.test ? "projects" : "workspace" in resolvedConfig.test ? "workspace" : await import('vitest/package.json', { with: { type: 'json' } }).then((r) => {
228
- const [major, minor] = (r.default || r).version.split(".");
229
- return Number.parseInt(major, 10) > 3 || Number.parseInt(major, 10) === 3 && Number.parseInt(minor, 10) >= 2;
230
- }) ? "projects" : "workspace";
231
- resolvedConfig.test[key] = [];
232
- resolvedConfig.test[key].push({
233
- extends: true,
244
+ const merge = createDefu((obj, key, value) => {
245
+ if (Array.isArray(value) && Array.isArray(obj[key])) {
246
+ obj[key] = [.../* @__PURE__ */ new Set([...value, ...obj[key]])];
247
+ return true;
248
+ }
249
+ });
250
+ const nuxtProject = merge({
251
+ ...resolvedConfig,
234
252
  test: {
253
+ ...resolvedConfig.test,
235
254
  name: "nuxt",
236
255
  environment: "nuxt",
237
- include: [
238
- "**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}",
239
- "{test,tests}/nuxt/**.*"
240
- ]
256
+ include: []
241
257
  }
242
- });
243
- resolvedConfig.test[key].push({
244
- extends: true,
258
+ }, resolvedConfig);
259
+ nuxtProject.test.include = [
260
+ "**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}",
261
+ "{test,tests}/nuxt/**.*"
262
+ ];
263
+ const defaultProject = merge({
264
+ ...resolvedConfig,
245
265
  test: {
266
+ ...resolvedConfig.test,
246
267
  name: defaultEnvironment,
247
268
  environment: defaultEnvironment,
248
269
  exclude: [
@@ -255,7 +276,10 @@ function defineVitestConfig(config = {}) {
255
276
  "./{test,tests}/nuxt/**.*"
256
277
  ]
257
278
  }
258
- });
279
+ }, resolvedConfig);
280
+ resolvedConfig.test = {
281
+ projects: [nuxtProject, defaultProject]
282
+ };
259
283
  }
260
284
  return resolvedConfig;
261
285
  });
package/dist/e2e.d.mts CHANGED
@@ -1,9 +1,10 @@
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';
1
+ import { T as TestOptions, b as TestContext, a as TestHooks } from './shared/test-utils.BLyxqr96.mjs';
2
+ export { $ as $fetch, G as GotoOptions, N as NuxtPage, S as StartServerOptions, c as TestRunner, d as createBrowser, e as createPage, f as fetch, g as getBrowser, s as startServer, h as stopServer, u as url, w as waitForHydration } from './shared/test-utils.BLyxqr96.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,6 +1,6 @@
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';
1
+ export { b as buildFixture, c as createBrowser, a as createPage, d as createTest, g as getBrowser, l as loadFixture, s as setup, e as setupMaps, w as waitForHydration } from './shared/test-utils.E_cAGA8l.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';
@@ -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.C_clWQBc.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';
package/dist/module.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { UserConfig } from 'vitest/node';
2
+ import { TestUserConfig } from 'vitest/config';
3
3
 
4
4
  interface NuxtVitestOptions {
5
5
  startOnBoot?: boolean;
6
6
  logToConsole?: boolean;
7
- vitestConfig?: UserConfig;
7
+ vitestConfig?: TestUserConfig;
8
8
  }
9
9
  declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions, NuxtVitestOptions, false>;
10
10