@ohos-ports/nuxt-test-utils 0.0.0-stage → 4.4.0-beta.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/LICENSE +21 -0
- package/README.md +20 -2
- package/dirs.js +4 -0
- package/dist/browser/index.d.mts +7 -0
- package/dist/browser/index.mjs +12 -0
- package/dist/browser/pure.d.mts +2 -0
- package/dist/browser/pure.mjs +1 -0
- package/dist/config.d.mts +82 -0
- package/dist/config.mjs +336 -0
- package/dist/e2e/dev-server.d.mts +1 -0
- package/dist/e2e/dev-server.mjs +10 -0
- package/dist/e2e-BO5mj9tk.d.mts +244 -0
- package/dist/e2e-DzsWJ8cS.mjs +373 -0
- package/dist/e2e.d.mts +2 -0
- package/dist/e2e.mjs +3 -0
- package/dist/experimental.d.mts +5 -0
- package/dist/experimental.mjs +20 -0
- package/dist/interface-Dhh_nx8F.mjs +34 -0
- package/dist/module.d.mts +32 -0
- package/dist/module.mjs +987 -0
- package/dist/playwright.d.mts +33 -0
- package/dist/playwright.mjs +68 -0
- package/dist/pure-Ba9-jZYN.d.mts +56 -0
- package/dist/pure-C_CSGRkt.mjs +114 -0
- package/dist/runtime/browser-entry.mjs +15 -0
- package/dist/runtime/entry.mjs +19 -0
- package/dist/runtime/global-setup.mjs +15 -0
- package/dist/runtime/mocks/vue-devtools.mjs +11 -0
- package/dist/runtime/nuxt-root.mjs +17 -0
- package/dist/runtime/shared/environment.mjs +67 -0
- package/dist/runtime/shared/h3-v1.mjs +32 -0
- package/dist/runtime/shared/h3-v2.mjs +34 -0
- package/dist/runtime/shared/h3.mjs +5 -0
- package/dist/runtime/shared/nuxt.mjs +17 -0
- package/dist/runtime/shared/vue-wrapper-plugin.mjs +42 -0
- package/dist/runtime-utils/index.d.mts +208 -0
- package/dist/runtime-utils/index.mjs +276 -0
- package/dist/server-Vl1UKNYB.mjs +301 -0
- package/dist/suspended-BbyJTvUP.d.mts +45 -0
- package/dist/suspended-Bjq6Zao6.mjs +1 -0
- package/dist/suspended-UrdAzOmb.mjs +255 -0
- package/dist/utils-CCklE0VI.mjs +196 -0
- package/dist/vitest-environment.d.mts +42 -0
- package/dist/vitest-environment.mjs +318 -0
- package/dist/vitest-wrapper/cli.d.mts +1 -0
- package/dist/vitest-wrapper/cli.mjs +81 -0
- package/package.json +145 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present - Nuxt Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Nuxt Test Utils
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://nuxt.care/?search=test-utils)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
🧪 [Nuxt](https://nuxt.com/) Test Utils
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Nuxt offers first-class support for e2e and unit testing of your Nuxt applications.
|
|
11
|
+
|
|
12
|
+
Nuxt Test Utils is currently powering [the tests we use on Nuxt itself](https://github.com/nuxt/nuxt/tree/main/test), as well as tests used throughout the module ecosystem.
|
|
13
|
+
|
|
14
|
+
You can find out more about how to use Nuxt Test Utils:
|
|
15
|
+
|
|
16
|
+
- in [a general overview](https://nuxt.com/docs/getting-started/testing)
|
|
17
|
+
- in [an in-depth guide for module authors](https://nuxt.com/docs/4.x/guide/modules/testing)
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
[MIT](./LICENSE)
|
package/dirs.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { n as config, r as render, t as cleanup } from "../pure-C_CSGRkt.mjs";
|
|
2
|
+
import { page } from "vitest/browser";
|
|
3
|
+
import { beforeEach } from "vitest";
|
|
4
|
+
// src/browser/index.ts
|
|
5
|
+
page.extend({
|
|
6
|
+
render,
|
|
7
|
+
[Symbol.for("vitest:component-cleanup")]: cleanup
|
|
8
|
+
});
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
cleanup();
|
|
11
|
+
});
|
|
12
|
+
export { cleanup, config, render };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as cleanup, n as config, r as render } from "../pure-C_CSGRkt.mjs";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { InlineConfig, UserWorkspaceConfig } from "vitest/node";
|
|
2
|
+
import { Nuxt, NuxtConfig, ViteConfig } from "@nuxt/schema";
|
|
3
|
+
import { TestProjectInlineConfiguration } from "vitest/config";
|
|
4
|
+
import { UserConfig, UserConfigFnPromise } from "vite";
|
|
5
|
+
interface DotenvOptions {
|
|
6
|
+
/** Directory to resolve `fileName` against. */
|
|
7
|
+
cwd?: string;
|
|
8
|
+
/**
|
|
9
|
+
* File or files to load; later files take priority.
|
|
10
|
+
* @default '.env'
|
|
11
|
+
*/
|
|
12
|
+
fileName?: string | string[];
|
|
13
|
+
/** @default true */
|
|
14
|
+
interpolate?: boolean;
|
|
15
|
+
/** @default process.env */
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
}
|
|
18
|
+
interface GetVitestConfigOptions {
|
|
19
|
+
nuxt: Nuxt;
|
|
20
|
+
viteConfig: ViteConfig;
|
|
21
|
+
nitro?: {
|
|
22
|
+
current?: NitroLike;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface LoadNuxtOptions {
|
|
26
|
+
dotenv?: Partial<DotenvOptions>;
|
|
27
|
+
overrides?: Partial<NuxtConfig>;
|
|
28
|
+
}
|
|
29
|
+
interface NitroLike {
|
|
30
|
+
hooks: {
|
|
31
|
+
callHook: (name: 'close') => Promise<unknown>;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadNuxtOptions?: LoadNuxtOptions, userConfig?: UserConfig & {
|
|
35
|
+
test?: InlineConfig;
|
|
36
|
+
} | UserWorkspaceConfig): Promise<UserConfig & {
|
|
37
|
+
test: InlineConfig;
|
|
38
|
+
}>;
|
|
39
|
+
export declare function defineVitestProject(config: TestProjectInlineConfiguration): Promise<TestProjectInlineConfiguration>;
|
|
40
|
+
export declare function defineVitestConfig(config?: UserConfig & {
|
|
41
|
+
test?: InlineConfig;
|
|
42
|
+
}): UserConfigFnPromise;
|
|
43
|
+
export interface NuxtEnvironmentOptions {
|
|
44
|
+
rootDir?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The starting URL for your Nuxt window environment
|
|
47
|
+
* @default 'http://localhost:3000'
|
|
48
|
+
*/
|
|
49
|
+
url?: string;
|
|
50
|
+
/**
|
|
51
|
+
* You can define how environment options are read when loading the Nuxt configuration.
|
|
52
|
+
*/
|
|
53
|
+
dotenv?: Partial<DotenvOptions>;
|
|
54
|
+
/**
|
|
55
|
+
* Configuration that will override the values in your `nuxt.config` file.
|
|
56
|
+
*/
|
|
57
|
+
overrides?: NuxtConfig;
|
|
58
|
+
/**
|
|
59
|
+
* The id of the root element to which the app should be mounted. Takes precedence over the id
|
|
60
|
+
* resolved from your Nuxt config, falling back to `'nuxt-test'` when neither is set.
|
|
61
|
+
* @deprecated Set `overrides.app.rootAttrs.id` (or `app.rootId` in your Nuxt config) instead
|
|
62
|
+
*/
|
|
63
|
+
rootId?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The name of the DOM environment to use.
|
|
66
|
+
*
|
|
67
|
+
* It also needs to be installed as a dev dependency in your project.
|
|
68
|
+
* @default 'happy-dom'
|
|
69
|
+
*/
|
|
70
|
+
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
71
|
+
h3Version?: 1 | 2;
|
|
72
|
+
mock?: {
|
|
73
|
+
intersectionObserver?: boolean;
|
|
74
|
+
indexedDb?: boolean;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
declare module 'vitest/node' {
|
|
78
|
+
interface EnvironmentOptions {
|
|
79
|
+
nuxt?: NuxtEnvironmentOptions;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export {};
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { a as resolveH3Package, i as loadKit, n as deepCopy, t as applyEnv } from "./utils-CCklE0VI.mjs";
|
|
2
|
+
import { createDefu, defu as defu$1 } from "defu";
|
|
3
|
+
import { resolve } from "pathe";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { resolveModulePath } from "exsolve";
|
|
6
|
+
import { version } from "vitest/node";
|
|
7
|
+
import { readFile, stat } from "node:fs/promises";
|
|
8
|
+
import { parseEnv } from "node:util";
|
|
9
|
+
import { createResolver, findPath } from "@nuxt/kit";
|
|
10
|
+
// src/dotenv.ts
|
|
11
|
+
const dotenvKeys = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
async function setupDotenv(options = {}) {
|
|
13
|
+
const target = options.env ?? process.env;
|
|
14
|
+
const cwd = resolve(options.cwd || ".");
|
|
15
|
+
const fileNames = typeof options.fileName === "string" ? [options.fileName] : options.fileName ?? [".env"];
|
|
16
|
+
const environment = Object.assign(Object.create(null), target);
|
|
17
|
+
const loaded = /* @__PURE__ */ new Set();
|
|
18
|
+
const owned = dotenvKeys.get(target) ?? /* @__PURE__ */ new Set();
|
|
19
|
+
dotenvKeys.set(target, owned);
|
|
20
|
+
for (const fileName of fileNames) {
|
|
21
|
+
const path = resolve(cwd, fileName);
|
|
22
|
+
if (!(await stat(path).catch(() => void 0))?.isFile()) continue;
|
|
23
|
+
const parsed = parseEnv(await readFile(path, "utf8"));
|
|
24
|
+
for (const key in parsed) {
|
|
25
|
+
if (key in environment && !owned.has(key) && !loaded.has(key)) continue;
|
|
26
|
+
environment[key] = parsed[key];
|
|
27
|
+
loaded.add(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (options.interpolate ?? true) interpolate(environment);
|
|
31
|
+
for (const key of loaded) {
|
|
32
|
+
owned.add(key);
|
|
33
|
+
if (!key.startsWith("_")) target[key] = environment[key];
|
|
34
|
+
}
|
|
35
|
+
return environment;
|
|
36
|
+
}
|
|
37
|
+
const REFERENCE_RE = /(\\)?\$(?:\{([\w:]+)\}|([\w:]+))/g;
|
|
38
|
+
function interpolate(env) {
|
|
39
|
+
const resolveValue = (value, parents) => {
|
|
40
|
+
if (typeof value !== "string") return value;
|
|
41
|
+
return value.replace(REFERENCE_RE, (match, escaped, braced, bare) => {
|
|
42
|
+
if (escaped) return match.slice(1);
|
|
43
|
+
const key = braced ?? bare;
|
|
44
|
+
if (parents.includes(key)) {
|
|
45
|
+
console.warn(`Please avoid recursive environment variables ( loop: ${parents.join(" > ")} > ${key} )`);
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
return resolveValue(env[key], [...parents, key]) ?? match;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
for (const key in env) env[key] = resolveValue(env[key], [key]);
|
|
52
|
+
}
|
|
53
|
+
// src/module/plugins/options.ts
|
|
54
|
+
const PLUGIN_NAME = "nuxt:vitest:nuxt-environment-options";
|
|
55
|
+
const STUB_ID = "nuxt-vitest-environment-options";
|
|
56
|
+
function NuxtVitestEnvironmentOptionsPlugin(environmentOptions = {}) {
|
|
57
|
+
return {
|
|
58
|
+
name: PLUGIN_NAME,
|
|
59
|
+
enforce: "pre",
|
|
60
|
+
resolveId(id) {
|
|
61
|
+
if (id.endsWith(STUB_ID)) return STUB_ID;
|
|
62
|
+
},
|
|
63
|
+
load(id) {
|
|
64
|
+
if (id.endsWith(STUB_ID)) return `export default ${JSON.stringify(environmentOptions || {})}`;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// src/config.ts
|
|
69
|
+
async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {}) {
|
|
70
|
+
const { buildNuxt, loadNuxt } = await loadKit(rootDir);
|
|
71
|
+
const nuxt = await loadNuxt({
|
|
72
|
+
cwd: rootDir,
|
|
73
|
+
dev: options.nitroEnvironment || (options.overrides?.dev ?? false),
|
|
74
|
+
dotenv: defu$1(options.dotenv, {
|
|
75
|
+
cwd: rootDir,
|
|
76
|
+
fileName: ".env.test"
|
|
77
|
+
}),
|
|
78
|
+
defaults: { compatibilityDate: "2024-04-03" },
|
|
79
|
+
overrides: defu$1({
|
|
80
|
+
appId: "nuxt-app",
|
|
81
|
+
buildId: "test",
|
|
82
|
+
ssr: false,
|
|
83
|
+
test: true,
|
|
84
|
+
modules: ["@nuxt/test-utils/module"],
|
|
85
|
+
testUtils: { _fromVitestConfig: true }
|
|
86
|
+
}, options.overrides, options.nitroEnvironment ? {} : DISABLE_NITRO_ENVIRONMENT)
|
|
87
|
+
});
|
|
88
|
+
if (!nuxt.options._installedModules.find((i) => i?.meta?.name === "@nuxt/test-utils")) throw new Error("Failed to load `@nuxt/test-utils/module`. You may need to add it to your nuxt.config.");
|
|
89
|
+
const nitro = options.nitroEnvironment ? {} : void 0;
|
|
90
|
+
if (nitro) nuxt.hook("nitro:init", (instance) => {
|
|
91
|
+
nitro.current = instance;
|
|
92
|
+
});
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
nuxt.hook("vite:configResolved", (viteConfig, { isClient }) => {
|
|
95
|
+
if (isClient) {
|
|
96
|
+
resolve({
|
|
97
|
+
nuxt,
|
|
98
|
+
viteConfig,
|
|
99
|
+
nitro
|
|
100
|
+
});
|
|
101
|
+
throw new Error("_stop_");
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
buildNuxt(nuxt).catch((err) => {
|
|
105
|
+
if (!err.toString().includes("_stop_")) reject(err);
|
|
106
|
+
});
|
|
107
|
+
}).finally(() => nuxt.close());
|
|
108
|
+
}
|
|
109
|
+
const DISABLE_NITRO_ENVIRONMENT = { experimental: { nitroViteEnvironment: false } };
|
|
110
|
+
function nitroTeardownPlugin(nitro) {
|
|
111
|
+
let closed;
|
|
112
|
+
return {
|
|
113
|
+
name: "nuxt:test-utils:nitro-teardown",
|
|
114
|
+
async closeBundle() {
|
|
115
|
+
closed ||= nitro.current?.hooks.callHook("close") ?? Promise.resolve();
|
|
116
|
+
await closed;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const excludedPlugins = [
|
|
121
|
+
"nuxt:import-protection",
|
|
122
|
+
"nuxt:import-conditions",
|
|
123
|
+
"nuxt:devtools:rpc",
|
|
124
|
+
"nuxt:devtools:config-retriever",
|
|
125
|
+
"vite-plugin-checker",
|
|
126
|
+
"vite-plugin-inspect",
|
|
127
|
+
"vite-plugin-vue-tracer"
|
|
128
|
+
];
|
|
129
|
+
async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}, userConfig = {}) {
|
|
130
|
+
const { test: testConfig = {} } = userConfig;
|
|
131
|
+
const { rootDir = process.cwd(), ..._overrides } = loadNuxtOptions.overrides || {};
|
|
132
|
+
if (!options) options = await startNuxtAndGetViteConfig(rootDir, {
|
|
133
|
+
dotenv: loadNuxtOptions.dotenv,
|
|
134
|
+
nitroEnvironment: loadNuxtOptions.nitroEnvironment,
|
|
135
|
+
overrides: {
|
|
136
|
+
test: true,
|
|
137
|
+
..._overrides
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
delete options.viteConfig.root;
|
|
141
|
+
options.viteConfig.plugins = (options.viteConfig.plugins || []).filter((p) => !p || !("name" in p) || !excludedPlugins.includes(p.name));
|
|
142
|
+
const h3Info = resolveH3Package(rootDir, options.nuxt.options.appDir, options.nuxt.options.modulesDir);
|
|
143
|
+
const h3Version = h3Info?.version ?? 1;
|
|
144
|
+
const h3Entry = h3Info && resolveModulePath(h3Version === 2 ? "h3/generic" : "h3", {
|
|
145
|
+
from: `${h3Info.rootPath}/`,
|
|
146
|
+
try: true
|
|
147
|
+
});
|
|
148
|
+
const define = {
|
|
149
|
+
"process.env.NODE_ENV": "\"test\"",
|
|
150
|
+
"__NUXT_VITEST_RESOLVED__": "true"
|
|
151
|
+
};
|
|
152
|
+
const resolver = createResolver(import.meta.url);
|
|
153
|
+
const resolvedConfig = defu$1({
|
|
154
|
+
define,
|
|
155
|
+
...options.viteConfig.environments?.client && { environments: { client: { define } } },
|
|
156
|
+
resolve: { alias: {
|
|
157
|
+
"@vue/devtools-kit": resolver.resolve("./runtime/mocks/vue-devtools"),
|
|
158
|
+
"@vue/devtools-core": resolver.resolve("./runtime/mocks/vue-devtools"),
|
|
159
|
+
...h3Entry && { "#nuxt-test-utils/h3": h3Entry }
|
|
160
|
+
} },
|
|
161
|
+
optimizeDeps: { ...vitestMajor >= 5 && testConfig.browser?.enabled ? {
|
|
162
|
+
include: ["@testing-library/vue", "#nuxt-test-utils/h3"],
|
|
163
|
+
exclude: ["@vue/devtools-kit", "@vue/devtools-core"]
|
|
164
|
+
} : { noDiscovery: true } },
|
|
165
|
+
test: {
|
|
166
|
+
environmentOptions: {
|
|
167
|
+
nuxtRuntimeConfig: applyEnv(deepCopy(options.nuxt.options.runtimeConfig), {
|
|
168
|
+
prefix: "NUXT_",
|
|
169
|
+
env: await setupDotenv(defu$1(loadNuxtOptions.dotenv, {
|
|
170
|
+
cwd: rootDir,
|
|
171
|
+
fileName: ".env.test"
|
|
172
|
+
}))
|
|
173
|
+
}),
|
|
174
|
+
nuxtRouteRules: defu$1({}, options.nuxt.options.routeRules, options.nuxt.options.nitro?.routeRules),
|
|
175
|
+
nuxtAppConfig: {
|
|
176
|
+
rootAttrs: options.nuxt.options.app.rootAttrs,
|
|
177
|
+
rootTag: options.nuxt.options.app.rootTag,
|
|
178
|
+
teleportAttrs: options.nuxt.options.app.teleportAttrs,
|
|
179
|
+
teleportTag: options.nuxt.options.app.teleportTag
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
server: { deps: { inline: [
|
|
183
|
+
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
|
184
|
+
/^#/,
|
|
185
|
+
"@nuxt/test-utils",
|
|
186
|
+
"@nuxt/test-utils-nightly",
|
|
187
|
+
"@nuxt/test-utils-edge",
|
|
188
|
+
"vitest-environment-nuxt",
|
|
189
|
+
...options.nuxt.options.build.transpile.filter((r) => typeof r === "string" || r instanceof RegExp)
|
|
190
|
+
] } },
|
|
191
|
+
deps: { optimizer: { client: { enabled: false } } }
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
server: { middlewareMode: false },
|
|
195
|
+
plugins: [
|
|
196
|
+
{
|
|
197
|
+
name: "disable-auto-execute",
|
|
198
|
+
enforce: "pre",
|
|
199
|
+
transform(code, id) {
|
|
200
|
+
if (id.match(/nuxt(3|-nightly)?\/.*\/entry\./)) return code.replace(/(?<!vueAppPromise = )entry\(\)/, "Promise.resolve()");
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
...options.nitro ? [nitroTeardownPlugin(options.nitro)] : [],
|
|
204
|
+
{
|
|
205
|
+
name: "nuxt:test-utils:browser-conditions",
|
|
206
|
+
enforce: "pre",
|
|
207
|
+
config() {
|
|
208
|
+
if (testConfig.browser?.enabled) return;
|
|
209
|
+
return { resolve: { conditions: [
|
|
210
|
+
"web",
|
|
211
|
+
"import",
|
|
212
|
+
"module",
|
|
213
|
+
"default"
|
|
214
|
+
] } };
|
|
215
|
+
},
|
|
216
|
+
configResolved(config) {
|
|
217
|
+
if (config.ssr.resolve?.conditions) config.ssr.resolve.conditions = config.ssr.resolve.conditions.filter((x) => x !== "import");
|
|
218
|
+
},
|
|
219
|
+
configEnvironment: {
|
|
220
|
+
order: "post",
|
|
221
|
+
handler(name) {
|
|
222
|
+
if (name === "client") {
|
|
223
|
+
if (testConfig.browser?.enabled) return { dev: { moduleRunnerTransform: false } };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}, options.viteConfig, {
|
|
230
|
+
...vitestMajor >= 5 && testConfig.browser?.enabled && { optimizeDeps: { noDiscovery: true } },
|
|
231
|
+
test: { environmentOptions: { nuxt: {
|
|
232
|
+
rootId: options.nuxt.options.app.rootAttrs?.id || void 0,
|
|
233
|
+
h3Version,
|
|
234
|
+
mock: {
|
|
235
|
+
intersectionObserver: true,
|
|
236
|
+
indexedDb: false
|
|
237
|
+
}
|
|
238
|
+
} } }
|
|
239
|
+
});
|
|
240
|
+
delete resolvedConfig.define["process.browser"];
|
|
241
|
+
delete resolvedConfig.customLogger;
|
|
242
|
+
delete resolvedConfig.ssr;
|
|
243
|
+
if (!Array.isArray(resolvedConfig.test.setupFiles)) resolvedConfig.test.setupFiles = [resolvedConfig.test.setupFiles].filter(Boolean);
|
|
244
|
+
const entryPath = resolver.resolve("./runtime/entry");
|
|
245
|
+
resolvedConfig.test.setupFiles.unshift(await findPath(entryPath) ?? entryPath);
|
|
246
|
+
return resolvedConfig;
|
|
247
|
+
}
|
|
248
|
+
const vitestMajor = Number(version.split(".")[0]);
|
|
249
|
+
const optOutOfExtends = false;
|
|
250
|
+
async function defineVitestProject(config) {
|
|
251
|
+
const resolvedConfig = await resolveConfig(defu$1({ test: { environment: "nuxt" } }, config));
|
|
252
|
+
resolvedConfig.extends ??= optOutOfExtends;
|
|
253
|
+
return resolvedConfig;
|
|
254
|
+
}
|
|
255
|
+
const defineViteConfig = (config) => config;
|
|
256
|
+
function defineVitestConfig(config = {}) {
|
|
257
|
+
return defineViteConfig(async () => {
|
|
258
|
+
const resolvedConfig = await resolveConfig(config);
|
|
259
|
+
if (resolvedConfig.test.browser?.enabled) return resolvedConfig;
|
|
260
|
+
if ("workspace" in resolvedConfig.test || "projects" in resolvedConfig.test) throw new Error("The `projects` option is not supported with `defineVitestConfig`. Instead, use `defineVitestProject` to define each workspace project that uses the Nuxt environment.");
|
|
261
|
+
const defaultEnvironment = resolvedConfig.test.environment || "node";
|
|
262
|
+
if (defaultEnvironment !== "nuxt") {
|
|
263
|
+
const merge = createDefu((obj, key, value) => {
|
|
264
|
+
if (Array.isArray(value) && Array.isArray(obj[key])) {
|
|
265
|
+
obj[key] = [.../* @__PURE__ */ new Set([...value, ...obj[key]])];
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
const nuxtProject = merge({
|
|
270
|
+
...resolvedConfig,
|
|
271
|
+
extends: optOutOfExtends,
|
|
272
|
+
test: {
|
|
273
|
+
...resolvedConfig.test,
|
|
274
|
+
name: "nuxt",
|
|
275
|
+
environment: "nuxt",
|
|
276
|
+
include: []
|
|
277
|
+
}
|
|
278
|
+
}, resolvedConfig);
|
|
279
|
+
nuxtProject.test.include = ["**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}", "{test,tests}/nuxt/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
280
|
+
const defaultProject = merge({
|
|
281
|
+
...resolvedConfig,
|
|
282
|
+
extends: optOutOfExtends,
|
|
283
|
+
test: {
|
|
284
|
+
...resolvedConfig.test,
|
|
285
|
+
name: defaultEnvironment,
|
|
286
|
+
environment: defaultEnvironment,
|
|
287
|
+
exclude: [
|
|
288
|
+
"**/node_modules/**",
|
|
289
|
+
"**/dist/**",
|
|
290
|
+
"**/cypress/**",
|
|
291
|
+
"**/.{idea,git,cache,output,temp}/**",
|
|
292
|
+
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*",
|
|
293
|
+
...nuxtProject.test.include
|
|
294
|
+
]
|
|
295
|
+
}
|
|
296
|
+
}, resolvedConfig);
|
|
297
|
+
delete resolvedConfig.test.name;
|
|
298
|
+
delete resolvedConfig.test.environment;
|
|
299
|
+
delete resolvedConfig.test.include;
|
|
300
|
+
delete resolvedConfig.test.exclude;
|
|
301
|
+
delete resolvedConfig.test.includeSource;
|
|
302
|
+
delete defaultProject.test.includeSource;
|
|
303
|
+
resolvedConfig.test.projects = [nuxtProject, defaultProject];
|
|
304
|
+
}
|
|
305
|
+
return resolvedConfig;
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
function isCoverageEnabled(config) {
|
|
309
|
+
if (config.test && "coverage" in config.test && config.test.coverage?.enabled) return true;
|
|
310
|
+
return process.argv.some((arg) => arg === "--coverage" || arg === "--coverage.enabled" || arg === "--coverage=true" || arg === "--coverage.enabled=true");
|
|
311
|
+
}
|
|
312
|
+
async function resolveConfig(config) {
|
|
313
|
+
const overrides = config.test?.environmentOptions?.nuxt?.overrides || {};
|
|
314
|
+
overrides.rootDir = config.test?.environmentOptions?.nuxt?.rootDir;
|
|
315
|
+
if (isCoverageEnabled(config)) {
|
|
316
|
+
if (overrides.sourcemap === void 0) overrides.sourcemap = { client: true };
|
|
317
|
+
else if (typeof overrides.sourcemap === "object" && overrides.sourcemap.client === void 0) overrides.sourcemap.client = true;
|
|
318
|
+
}
|
|
319
|
+
if (config.test?.setupFiles && !Array.isArray(config.test.setupFiles)) config.test.setupFiles = [config.test.setupFiles].filter(Boolean);
|
|
320
|
+
const resolvedConfig = defu$1(config, await getVitestConfigFromNuxt(void 0, {
|
|
321
|
+
dotenv: config.test?.environmentOptions?.nuxt?.dotenv,
|
|
322
|
+
nitroEnvironment: config.test?.environmentOptions?.nuxt?.nitroEnvironment,
|
|
323
|
+
overrides: deepCopy(overrides)
|
|
324
|
+
}, config));
|
|
325
|
+
resolvedConfig.plugins.push(NuxtVitestEnvironmentOptionsPlugin(resolvedConfig.test.environmentOptions));
|
|
326
|
+
if (resolvedConfig.test.browser?.enabled) {
|
|
327
|
+
if (resolvedConfig.test.environment === "nuxt") {
|
|
328
|
+
resolvedConfig.test.setupFiles = Array.isArray(resolvedConfig.test.setupFiles) ? resolvedConfig.test.setupFiles : [resolvedConfig.test.setupFiles].filter(Boolean);
|
|
329
|
+
const resolver = createResolver(import.meta.url);
|
|
330
|
+
const browserEntry = await findPath(resolver.resolve("./runtime/browser-entry")) || resolver.resolve("./runtime/browser-entry");
|
|
331
|
+
resolvedConfig.test.setupFiles.unshift(browserEntry);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return resolvedConfig;
|
|
335
|
+
}
|
|
336
|
+
export { defineVitestConfig, defineVitestProject, getVitestConfigFromNuxt };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
// src/e2e/dev-server.ts
|
|
4
|
+
const overrides = JSON.parse(process.env.__NUXT_TEST_DEV_OVERRIDES__ || "{}");
|
|
5
|
+
delete process.env.__NUXT_TEST_DEV_OVERRIDES__;
|
|
6
|
+
process.on("unhandledRejection", (err) => console.error("[unhandledRejection]", err));
|
|
7
|
+
process.on("uncaughtException", (err) => console.error("[uncaughtException]", err));
|
|
8
|
+
const { runCommand } = await import(pathToFileURL(process.argv[2]).href);
|
|
9
|
+
await runCommand("_dev", [], { overrides });
|
|
10
|
+
export {};
|