@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
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { dirname, join } from "pathe";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { resolveModulePath } from "exsolve";
|
|
6
|
+
// src/utils.ts
|
|
7
|
+
function getEnv(key, opts) {
|
|
8
|
+
const env = opts.env ?? process.env;
|
|
9
|
+
const envKey = toEnvKey(key);
|
|
10
|
+
return parseEnvValue(env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey]);
|
|
11
|
+
}
|
|
12
|
+
function toEnvKey(key) {
|
|
13
|
+
return key.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/[-./\s]+/g, "_").toUpperCase();
|
|
14
|
+
}
|
|
15
|
+
const JSON_SIGNATURE_RE = /^\s*["[{]|^\s*-?\d{1,16}(?:\.\d{1,17})?(?:e[+-]?\d+)?\s*$/i;
|
|
16
|
+
function parseEnvValue(value) {
|
|
17
|
+
if (typeof value !== "string") return value;
|
|
18
|
+
if (value[0] === "\"" && value.at(-1) === "\"" && !value.includes("\\")) return value.slice(1, -1);
|
|
19
|
+
switch (value.trim().toLowerCase()) {
|
|
20
|
+
case "true": return true;
|
|
21
|
+
case "false": return false;
|
|
22
|
+
case "undefined": return;
|
|
23
|
+
case "null": return null;
|
|
24
|
+
case "nan": return NaN;
|
|
25
|
+
case "infinity": return Number.POSITIVE_INFINITY;
|
|
26
|
+
case "-infinity": return Number.NEGATIVE_INFINITY;
|
|
27
|
+
}
|
|
28
|
+
if (!JSON_SIGNATURE_RE.test(value)) return value;
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(value, (key, val) => key === "__proto__" || key === "constructor" && val && typeof val === "object" && "prototype" in val ? void 0 : val);
|
|
31
|
+
} catch {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _isObject(input) {
|
|
36
|
+
return typeof input === "object" && !Array.isArray(input);
|
|
37
|
+
}
|
|
38
|
+
function applyEnv(obj, opts, parentKey = "") {
|
|
39
|
+
for (const key in obj) {
|
|
40
|
+
const subKey = parentKey ? `${parentKey}_${key}` : key;
|
|
41
|
+
const envValue = getEnv(subKey, opts);
|
|
42
|
+
if (_isObject(obj[key])) {
|
|
43
|
+
if (_isObject(envValue)) {
|
|
44
|
+
obj[key] = {
|
|
45
|
+
...obj[key],
|
|
46
|
+
...envValue
|
|
47
|
+
};
|
|
48
|
+
applyEnv(obj[key], opts, subKey);
|
|
49
|
+
} else if (envValue === void 0) applyEnv(obj[key], opts, subKey);
|
|
50
|
+
else obj[key] = envValue ?? obj[key];
|
|
51
|
+
} else obj[key] = envValue ?? obj[key];
|
|
52
|
+
}
|
|
53
|
+
return obj;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Deep-copy plain objects and arrays, passing anything else through by reference.
|
|
57
|
+
*
|
|
58
|
+
* `structuredClone` throws `DataCloneError` on proxies and functions, both of which turn up in
|
|
59
|
+
* `nuxt.options` (module mutation tracking wraps options in proxies) and in user-provided config
|
|
60
|
+
* overrides. Only plain containers need copying here; the clone exists to avoid mutating the
|
|
61
|
+
* caller's objects.
|
|
62
|
+
*/
|
|
63
|
+
function deepCopy(input, seen = /* @__PURE__ */ new WeakMap()) {
|
|
64
|
+
if (typeof input !== "object" || input === null) return input;
|
|
65
|
+
const proto = Object.getPrototypeOf(input);
|
|
66
|
+
if (proto !== Object.prototype && proto !== Array.prototype && proto !== null) return input;
|
|
67
|
+
const existing = seen.get(input);
|
|
68
|
+
if (existing) return existing;
|
|
69
|
+
if (Array.isArray(input)) {
|
|
70
|
+
const copy = [];
|
|
71
|
+
seen.set(input, copy);
|
|
72
|
+
for (const item of input) copy.push(deepCopy(item, seen));
|
|
73
|
+
return copy;
|
|
74
|
+
}
|
|
75
|
+
const copy = {};
|
|
76
|
+
seen.set(input, copy);
|
|
77
|
+
for (const key in input) copy[key] = deepCopy(input[key], seen);
|
|
78
|
+
return copy;
|
|
79
|
+
}
|
|
80
|
+
async function loadKit(rootDir) {
|
|
81
|
+
try {
|
|
82
|
+
const kitPath = resolveModulePath("@nuxt/kit", { from: tryResolveNuxt(rootDir) || rootDir });
|
|
83
|
+
let kit = await import(pathToFileURL(kitPath).href);
|
|
84
|
+
if (!kit.writeTypes) kit = {
|
|
85
|
+
...kit,
|
|
86
|
+
writeTypes: () => {
|
|
87
|
+
throw new Error("`writeTypes` is not available in this version of `@nuxt/kit`. Please upgrade to v3.7 or newer.");
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return kit;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
if (e.toString().includes("Cannot find module '@nuxt/kit'")) throw new Error("`@nuxt/test-utils` requires `@nuxt/kit` to be installed in your project. Try installing `nuxt` v3+ or `@nuxt/bridge` first.", { cause: e });
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function resolveNuxtCli(rootDir) {
|
|
97
|
+
const cliPath = resolveModulePath("@nuxt/cli", {
|
|
98
|
+
from: tryResolveNuxt(rootDir) || rootDir,
|
|
99
|
+
try: true
|
|
100
|
+
});
|
|
101
|
+
if (!cliPath) throw new Error("`@nuxt/test-utils` requires `@nuxt/cli` to start a dev server. Make sure `nuxt` is installed in your project.");
|
|
102
|
+
return cliPath;
|
|
103
|
+
}
|
|
104
|
+
const OMITTED = Symbol("omitted");
|
|
105
|
+
/**
|
|
106
|
+
* Copy plain objects, arrays and primitives, leaving out any value that cannot be represented as JSON
|
|
107
|
+
* (functions, class instances, regular expressions, circular references, ...).
|
|
108
|
+
* Returns the copy along with the paths of the values that were left out. `undefined` values are dropped without being reported.
|
|
109
|
+
*/
|
|
110
|
+
function toSerializable(input) {
|
|
111
|
+
const omitted = [];
|
|
112
|
+
const value = serializableCopy(input, "", omitted, /* @__PURE__ */ new Set());
|
|
113
|
+
return {
|
|
114
|
+
value: value === OMITTED ? void 0 : value,
|
|
115
|
+
omitted
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function serializableCopy(input, path, omitted, ancestors) {
|
|
119
|
+
if (input === void 0) return OMITTED;
|
|
120
|
+
if (input === null || typeof input === "string" || typeof input === "boolean" || typeof input === "number" && Number.isFinite(input)) return input;
|
|
121
|
+
if (!(Array.isArray(input) || typeof input === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(input))) || ancestors.has(input)) {
|
|
122
|
+
omitted.push(path);
|
|
123
|
+
return OMITTED;
|
|
124
|
+
}
|
|
125
|
+
ancestors.add(input);
|
|
126
|
+
let copy;
|
|
127
|
+
if (Array.isArray(input)) copy = input.map((item, index) => serializableCopy(item, `${path}[${index}]`, omitted, ancestors)).filter((item) => item !== OMITTED);
|
|
128
|
+
else {
|
|
129
|
+
copy = {};
|
|
130
|
+
for (const key in input) {
|
|
131
|
+
const value = serializableCopy(input[key], path ? `${path}.${key}` : key, omitted, ancestors);
|
|
132
|
+
if (value !== OMITTED) copy[key] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
ancestors.delete(input);
|
|
136
|
+
return copy;
|
|
137
|
+
}
|
|
138
|
+
function tryResolveNuxt(rootDir) {
|
|
139
|
+
for (const pkg of [
|
|
140
|
+
"nuxt-nightly",
|
|
141
|
+
"nuxt",
|
|
142
|
+
"nuxt3",
|
|
143
|
+
"nuxt-edge"
|
|
144
|
+
]) {
|
|
145
|
+
const path = resolveModulePath(pkg, {
|
|
146
|
+
from: rootDir,
|
|
147
|
+
try: true
|
|
148
|
+
});
|
|
149
|
+
if (path) return path;
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
function getPackageInfo(name, dirs = process.cwd()) {
|
|
154
|
+
const bases = (Array.isArray(dirs) ? dirs : [dirs]).map((dir) => dir.endsWith("/") ? dir : `${dir}/`);
|
|
155
|
+
const entry = resolveModulePath(`${name}/package.json`, {
|
|
156
|
+
from: bases,
|
|
157
|
+
try: true
|
|
158
|
+
}) ?? resolveModulePath(name, {
|
|
159
|
+
from: bases,
|
|
160
|
+
try: true
|
|
161
|
+
});
|
|
162
|
+
if (!entry) return;
|
|
163
|
+
let dir = dirname(entry);
|
|
164
|
+
while (true) {
|
|
165
|
+
const packageJsonPath = join(dir, "package.json");
|
|
166
|
+
if (existsSync(packageJsonPath)) {
|
|
167
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
168
|
+
return {
|
|
169
|
+
rootPath: dir,
|
|
170
|
+
version: packageJson.version,
|
|
171
|
+
packageJson
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const parent = dirname(dir);
|
|
175
|
+
if (parent === dir) return;
|
|
176
|
+
dir = parent;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function resolveH3Package(rootDir, appDir, modulesDir) {
|
|
180
|
+
const nuxtServerIntegration = getPackageInfo("@nuxt/nitro-server", appDir);
|
|
181
|
+
let nitroPath;
|
|
182
|
+
for (const nitroCandidate of [...nuxtServerIntegration?.packageJson.dependencies?.nitro ? ["nitro", "nitro-nightly"] : ["nitropack", "nitropack-nightly"]]) {
|
|
183
|
+
nitroPath = resolveModulePath(nitroCandidate, {
|
|
184
|
+
from: nuxtServerIntegration?.rootPath || appDir,
|
|
185
|
+
try: true
|
|
186
|
+
});
|
|
187
|
+
if (nitroPath) break;
|
|
188
|
+
}
|
|
189
|
+
const h3Info = getPackageInfo("h3", nitroPath ? dirname(nitroPath) : modulesDir) || getPackageInfo("h3", rootDir);
|
|
190
|
+
if (!h3Info) return;
|
|
191
|
+
return {
|
|
192
|
+
...h3Info,
|
|
193
|
+
version: h3Info.version?.startsWith("2.") ? 2 : 1
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export { resolveH3Package as a, loadKit as i, deepCopy as n, resolveNuxtCli as o, getPackageInfo as r, toSerializable as s, applyEnv as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EnvironmentOptions } from "vitest/node";
|
|
2
|
+
import { H3Event } from "h3";
|
|
3
|
+
import { Environment } from "vitest/runtime";
|
|
4
|
+
import { $Fetch } from "nitropack";
|
|
5
|
+
declare const _default: Environment;
|
|
6
|
+
interface H3V2Event {
|
|
7
|
+
url: URL;
|
|
8
|
+
method: string;
|
|
9
|
+
}
|
|
10
|
+
type NuxtBuiltinEnvironment = 'happy-dom' | 'jsdom';
|
|
11
|
+
interface GenericAppUse {
|
|
12
|
+
(route: string, handler: (event: H3V2Event | H3Event) => unknown, options?: {
|
|
13
|
+
match: (...args: [string, H3Event | undefined] | [H3V2Event]) => boolean;
|
|
14
|
+
}): void;
|
|
15
|
+
(handler: (event: H3V2Event | H3Event) => unknown, options?: {
|
|
16
|
+
match: (...args: [string, H3Event | undefined] | [H3V2Event]) => boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
}
|
|
19
|
+
interface GenericApp {
|
|
20
|
+
use: GenericAppUse;
|
|
21
|
+
}
|
|
22
|
+
interface NuxtWindow extends Window {
|
|
23
|
+
__app?: GenericApp;
|
|
24
|
+
__registry: Set<string>;
|
|
25
|
+
__NUXT_VITEST_ENVIRONMENT__?: boolean;
|
|
26
|
+
__NUXT_VITEST_ENVIRONMENT_PROMISE__?: Promise<void>;
|
|
27
|
+
__NUXT_VITEST_ENVIRONMENT_BROWSER_ENTRY__?: boolean;
|
|
28
|
+
__NUXT__: Record<string, unknown>;
|
|
29
|
+
$fetch: $Fetch;
|
|
30
|
+
fetch: ((input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>);
|
|
31
|
+
IntersectionObserver: unknown;
|
|
32
|
+
Headers: typeof Headers;
|
|
33
|
+
}
|
|
34
|
+
interface EnvironmentNuxtOptions {
|
|
35
|
+
jsdom?: EnvironmentOptions['jsdom'];
|
|
36
|
+
happyDom?: EnvironmentOptions['happyDOM'];
|
|
37
|
+
}
|
|
38
|
+
type EnvironmentNuxt = (global: typeof globalThis, options: EnvironmentNuxtOptions) => Promise<{
|
|
39
|
+
window: NuxtWindow;
|
|
40
|
+
teardown(): void;
|
|
41
|
+
}>;
|
|
42
|
+
export { type EnvironmentNuxt, type EnvironmentNuxtOptions, type GenericApp, type NuxtBuiltinEnvironment, type NuxtWindow, _default as default };
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { r as getPackageInfo } from "./utils-CCklE0VI.mjs";
|
|
2
|
+
import defu from "defu";
|
|
3
|
+
import { joinURL } from "ufo";
|
|
4
|
+
import { createFetch } from "ofetch";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { resolveModulePath } from "exsolve";
|
|
7
|
+
import { indexedDB } from "fake-indexeddb";
|
|
8
|
+
import { createRouter, exportMatcher, toRouteMatcher } from "radix3";
|
|
9
|
+
// src/runtime/shared/h3.ts
|
|
10
|
+
function defineEventHandler(handler) {
|
|
11
|
+
return Object.assign(handler, { __is_handler__: true });
|
|
12
|
+
}
|
|
13
|
+
// src/runtime/shared/h3-v1.ts
|
|
14
|
+
async function createFetchForH3V1() {
|
|
15
|
+
const { createApp, toWebHandler } = await import("#nuxt-test-utils/h3");
|
|
16
|
+
const h3App = createApp();
|
|
17
|
+
const webHandler = toWebHandler(h3App);
|
|
18
|
+
const registry = /* @__PURE__ */ new Set();
|
|
19
|
+
const _fetch = fetch;
|
|
20
|
+
const h3Fetch = (async (input, _init) => {
|
|
21
|
+
let url;
|
|
22
|
+
let init = _init;
|
|
23
|
+
if (typeof input === "string") url = input;
|
|
24
|
+
else if (input instanceof URL) url = input.toString();
|
|
25
|
+
else {
|
|
26
|
+
url = input.url;
|
|
27
|
+
init = {
|
|
28
|
+
method: init?.method ?? input.method,
|
|
29
|
+
body: init?.body ?? input.body,
|
|
30
|
+
headers: init?.headers ?? input.headers
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const base = url.split("?")[0];
|
|
34
|
+
if (registry.has(base) || registry.has(url)) url = "/_" + url;
|
|
35
|
+
if (url.startsWith("/")) return webHandler(new Request(new URL(url, "http://localhost"), init));
|
|
36
|
+
return _fetch(input, _init);
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
h3App,
|
|
40
|
+
registry,
|
|
41
|
+
fetch: h3Fetch
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// src/runtime/shared/h3-v2.ts
|
|
45
|
+
async function createFetchForH3V2() {
|
|
46
|
+
const { H3 } = await import("#nuxt-test-utils/h3");
|
|
47
|
+
const h3App = new H3();
|
|
48
|
+
const registry = /* @__PURE__ */ new Set();
|
|
49
|
+
const _fetch = fetch;
|
|
50
|
+
const h3Fetch = (async (input, _init) => {
|
|
51
|
+
let url;
|
|
52
|
+
let init = _init;
|
|
53
|
+
if (typeof input === "string") url = input;
|
|
54
|
+
else if (input instanceof URL) url = input.toString();
|
|
55
|
+
else {
|
|
56
|
+
url = input.url;
|
|
57
|
+
init = {
|
|
58
|
+
method: init?.method ?? input.method,
|
|
59
|
+
body: init?.body ?? input.body,
|
|
60
|
+
headers: init?.headers ?? input.headers
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const base = url.split("?")[0];
|
|
64
|
+
if (registry.has(base) || registry.has(url)) return h3App.fetch(new Request("/_" + url, init));
|
|
65
|
+
if (url.startsWith("/")) return new Response("Not Found", {
|
|
66
|
+
status: 404,
|
|
67
|
+
statusText: "Not Found"
|
|
68
|
+
});
|
|
69
|
+
return _fetch(input, _init);
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
h3App,
|
|
73
|
+
registry,
|
|
74
|
+
fetch: h3Fetch
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// src/runtime/shared/environment.ts
|
|
78
|
+
async function setupWindow(win, environmentOptions) {
|
|
79
|
+
win.__NUXT_VITEST_ENVIRONMENT__ = true;
|
|
80
|
+
win.__NUXT__ = {
|
|
81
|
+
serverRendered: false,
|
|
82
|
+
config: {
|
|
83
|
+
public: {},
|
|
84
|
+
app: { baseURL: "/" },
|
|
85
|
+
...environmentOptions?.nuxtRuntimeConfig
|
|
86
|
+
},
|
|
87
|
+
data: {},
|
|
88
|
+
state: {}
|
|
89
|
+
};
|
|
90
|
+
const consoleInfo = console.info;
|
|
91
|
+
console.info = (...args) => {
|
|
92
|
+
if (args[0] === "<Suspense> is an experimental feature and its API will likely change.") return;
|
|
93
|
+
return consoleInfo(...args);
|
|
94
|
+
};
|
|
95
|
+
const appConfig = environmentOptions.nuxtAppConfig;
|
|
96
|
+
createElementAndAppend(win, appConfig?.rootTag || "div", {
|
|
97
|
+
...appConfig?.rootAttrs,
|
|
98
|
+
id: environmentOptions.nuxt.rootId || appConfig?.rootAttrs?.id || "nuxt-test"
|
|
99
|
+
});
|
|
100
|
+
createElementAndAppend(win, appConfig?.teleportTag || "div", appConfig?.teleportAttrs || { id: "teleports" });
|
|
101
|
+
const res = environmentOptions.nuxt.h3Version === 2 ? await createFetchForH3V2() : await createFetchForH3V1();
|
|
102
|
+
win.fetch = res.fetch;
|
|
103
|
+
win.$fetch = createFetch({
|
|
104
|
+
fetch: win.fetch,
|
|
105
|
+
Headers: win.Headers
|
|
106
|
+
});
|
|
107
|
+
win.__registry = res.registry;
|
|
108
|
+
win.__app = res.h3App;
|
|
109
|
+
const timestamp = Date.now();
|
|
110
|
+
const routeRulesMatcher = toRouteMatcher(createRouter({ routes: environmentOptions.nuxtRouteRules || {} }));
|
|
111
|
+
const matcher = exportMatcher(routeRulesMatcher);
|
|
112
|
+
const manifestOutputPath = joinURL(environmentOptions?.nuxtRuntimeConfig?.app?.baseURL || "/", environmentOptions?.nuxtRuntimeConfig?.app?.buildAssetsDir || "_nuxt", "builds");
|
|
113
|
+
const manifestBaseRoutePath = joinURL("/_", manifestOutputPath);
|
|
114
|
+
const buildId = win.__NUXT__.config?.app.buildId || "test";
|
|
115
|
+
res.h3App.use(`${manifestBaseRoutePath}/latest.json`, defineEventHandler(() => ({
|
|
116
|
+
id: buildId,
|
|
117
|
+
timestamp
|
|
118
|
+
})));
|
|
119
|
+
res.h3App.use(`${manifestBaseRoutePath}/meta/${buildId}.json`, defineEventHandler(() => ({
|
|
120
|
+
id: buildId,
|
|
121
|
+
timestamp,
|
|
122
|
+
matcher,
|
|
123
|
+
prerendered: []
|
|
124
|
+
})));
|
|
125
|
+
res.registry.add(`${manifestOutputPath}/latest.json`);
|
|
126
|
+
res.registry.add(`${manifestOutputPath}/meta/${buildId}.json`);
|
|
127
|
+
return () => {
|
|
128
|
+
console.info = consoleInfo;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function createElementAndAppend(win, tag, attrs) {
|
|
132
|
+
if (attrs?.id && win.document.getElementById(attrs.id)) return;
|
|
133
|
+
const element = win.document.createElement(tag);
|
|
134
|
+
for (const [key, value] of Object.entries(attrs ?? {})) if (value !== false && value != null) element.setAttribute(key, value === true ? "" : String(value));
|
|
135
|
+
win.document.body.appendChild(element);
|
|
136
|
+
}
|
|
137
|
+
// src/environments/vitest/env/happy-dom.ts
|
|
138
|
+
var happy_dom_default = async function(_, { happyDom = {} }) {
|
|
139
|
+
const { Window, GlobalWindow, PropertySymbol } = await import("happy-dom");
|
|
140
|
+
const window = new (GlobalWindow || Window)(happyDom);
|
|
141
|
+
const { Headers: NativeHeaders } = globalThis;
|
|
142
|
+
class Headers extends NativeHeaders {
|
|
143
|
+
get [PropertySymbol.entries]() {
|
|
144
|
+
const entries = Object.create(null);
|
|
145
|
+
for (const [key, val] of this) {
|
|
146
|
+
const name = key.toLowerCase();
|
|
147
|
+
entries[name] ||= {
|
|
148
|
+
name,
|
|
149
|
+
value: []
|
|
150
|
+
};
|
|
151
|
+
entries[name].value.push(val);
|
|
152
|
+
}
|
|
153
|
+
return new Proxy(entries, { deleteProperty: (_, property) => {
|
|
154
|
+
Reflect.deleteProperty(entries, property);
|
|
155
|
+
this.delete(String(property));
|
|
156
|
+
return true;
|
|
157
|
+
} });
|
|
158
|
+
}
|
|
159
|
+
static [Symbol.hasInstance](value) {
|
|
160
|
+
return value instanceof NativeHeaders;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
window.Headers = Headers;
|
|
164
|
+
return {
|
|
165
|
+
window,
|
|
166
|
+
teardown() {
|
|
167
|
+
window.happyDOM.abort();
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
// src/environments/vitest/env/jsdom.ts
|
|
172
|
+
var jsdom_default = async function(global, { jsdom = {} }) {
|
|
173
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import("jsdom");
|
|
174
|
+
const jsdomOptions = defu(jsdom, {
|
|
175
|
+
html: "<!DOCTYPE html>",
|
|
176
|
+
url: "http://localhost:3000",
|
|
177
|
+
contentType: "text/html",
|
|
178
|
+
pretendToBeVisual: true,
|
|
179
|
+
includeNodeLocations: false,
|
|
180
|
+
runScripts: "dangerously",
|
|
181
|
+
console: false,
|
|
182
|
+
cookieJar: false
|
|
183
|
+
});
|
|
184
|
+
const virtualConsole = jsdomOptions.console && global.console ? new VirtualConsole() : void 0;
|
|
185
|
+
const window = new JSDOM(jsdomOptions.html, {
|
|
186
|
+
...jsdomOptions,
|
|
187
|
+
resources: jsdomOptions.resources ?? (jsdomOptions.userAgent ? ResourceLoader ? new ResourceLoader({ userAgent: jsdomOptions.userAgent }) : { userAgent: jsdomOptions.userAgent } : void 0),
|
|
188
|
+
virtualConsole: virtualConsole ? "sendTo" in virtualConsole ? virtualConsole.sendTo(global.console) : virtualConsole.forwardTo(global.console) : void 0,
|
|
189
|
+
cookieJar: jsdomOptions.cookieJar ? new CookieJar() : void 0
|
|
190
|
+
}).window;
|
|
191
|
+
window.scrollTo = () => {};
|
|
192
|
+
window.URLSearchParams = globalThis.URLSearchParams;
|
|
193
|
+
window.Headers = globalThis.Headers;
|
|
194
|
+
const { Blob: NodeBlob, File: NodeFile, FormData: NodeFormData } = globalThis;
|
|
195
|
+
const getImplement = await loadGetImplement();
|
|
196
|
+
const toNodeBlobLike = (val) => {
|
|
197
|
+
const impl = getImplement(val);
|
|
198
|
+
const bytes = impl?._bytes ?? impl?._buffer;
|
|
199
|
+
if (!bytes) throw createJsdomCompatError("Cannot read the bytes of Blob/File");
|
|
200
|
+
if (val instanceof window.File) {
|
|
201
|
+
const { name: filename, type, lastModified } = val;
|
|
202
|
+
return new NodeFile([bytes], filename, {
|
|
203
|
+
type,
|
|
204
|
+
lastModified
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return new NodeBlob([bytes], { type: val.type });
|
|
208
|
+
};
|
|
209
|
+
const toNodePayload = (init) => {
|
|
210
|
+
if (init?.body) {
|
|
211
|
+
if (init.body instanceof window.FormData) {
|
|
212
|
+
const form = new NodeFormData();
|
|
213
|
+
init.body.forEach((val, key) => {
|
|
214
|
+
form.append(key, val instanceof window.Blob ? toNodeBlobLike(val) : val);
|
|
215
|
+
});
|
|
216
|
+
return {
|
|
217
|
+
...init,
|
|
218
|
+
body: form
|
|
219
|
+
};
|
|
220
|
+
} else if (init.body instanceof window.Blob) return {
|
|
221
|
+
...init,
|
|
222
|
+
body: toNodeBlobLike(init.body)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return init;
|
|
226
|
+
};
|
|
227
|
+
window.Request = class Request extends globalThis.Request {
|
|
228
|
+
constructor(input, init) {
|
|
229
|
+
if (typeof input === "string") super(new URL(input, window.location.origin), toNodePayload(init));
|
|
230
|
+
else super(input, toNodePayload(init));
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
return {
|
|
234
|
+
window,
|
|
235
|
+
teardown() {
|
|
236
|
+
window.close();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
let _getImplement;
|
|
241
|
+
async function loadGetImplement() {
|
|
242
|
+
async function load() {
|
|
243
|
+
for (const path of ["lib/generated/idl", "lib/jsdom/living/generated"]) try {
|
|
244
|
+
const { implForWrapper } = await import(
|
|
245
|
+
/* @vite-ignore */
|
|
246
|
+
[
|
|
247
|
+
"jsdom",
|
|
248
|
+
path,
|
|
249
|
+
"utils.js"
|
|
250
|
+
].join("/")
|
|
251
|
+
).then((r) => r.default);
|
|
252
|
+
if (typeof implForWrapper === "function") return implForWrapper;
|
|
253
|
+
} catch {}
|
|
254
|
+
return () => {
|
|
255
|
+
throw createJsdomCompatError("Cannot load jsdom's `implForWrapper` in nuxt environment");
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return _getImplement ||= await load();
|
|
259
|
+
}
|
|
260
|
+
function createJsdomCompatError(message) {
|
|
261
|
+
return /* @__PURE__ */ new Error(`${message}. Please report this to @nuxt/test-utils with your jsdom version.`);
|
|
262
|
+
}
|
|
263
|
+
// src/environments/vitest/index.ts
|
|
264
|
+
const environmentMap = {
|
|
265
|
+
"happy-dom": happy_dom_default,
|
|
266
|
+
jsdom: jsdom_default
|
|
267
|
+
};
|
|
268
|
+
const vitestMajor = Number(getPackageInfo("vitest", fileURLToPath(new URL(".", import.meta.url)))?.version?.split(".")[0]);
|
|
269
|
+
var vitest_default = {
|
|
270
|
+
name: "nuxt",
|
|
271
|
+
viteEnvironment: "client",
|
|
272
|
+
async setup(global, environmentOptions) {
|
|
273
|
+
const { populateGlobal } = await importVitestEnvironments();
|
|
274
|
+
const url = joinURL(environmentOptions.nuxt?.url ?? "http://localhost:3000", environmentOptions.nuxtRuntimeConfig?.app?.baseURL || "/");
|
|
275
|
+
const environmentName = environmentOptions.nuxt?.domEnvironment;
|
|
276
|
+
const { window: win, teardown } = await (environmentMap[environmentName] || environmentMap["happy-dom"])(global, defu(environmentOptions, {
|
|
277
|
+
happyDom: { url },
|
|
278
|
+
jsdom: { url }
|
|
279
|
+
}));
|
|
280
|
+
if (environmentOptions.nuxt?.mock?.intersectionObserver) win.IntersectionObserver ||= IntersectionObserver;
|
|
281
|
+
if (environmentOptions.nuxt?.mock?.indexedDb) win.indexedDB = indexedDB;
|
|
282
|
+
const teardownWindow = await setupWindow(win, environmentOptions);
|
|
283
|
+
const { keys, originals } = populateGlobal(global, win, {
|
|
284
|
+
bindFunctions: true,
|
|
285
|
+
additionalKeys: [
|
|
286
|
+
"fetch",
|
|
287
|
+
"Request",
|
|
288
|
+
"Headers"
|
|
289
|
+
]
|
|
290
|
+
});
|
|
291
|
+
return { teardown() {
|
|
292
|
+
keys.forEach((key) => delete global[key]);
|
|
293
|
+
teardownWindow();
|
|
294
|
+
if (vitestMajor >= 5) originals.forEach((descriptor, k) => Object.defineProperty(global, k, descriptor));
|
|
295
|
+
else originals.forEach((v, k) => global[k] = v);
|
|
296
|
+
if (!global.IntersectionObserver) global.IntersectionObserver = IntersectionObserver;
|
|
297
|
+
teardown();
|
|
298
|
+
} };
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
async function importVitestEnvironments() {
|
|
302
|
+
return await import(
|
|
303
|
+
/* @vite-ignore */
|
|
304
|
+
["vitest", vitestMajor >= 5 || resolveModulePath("vitest/runtime", {
|
|
305
|
+
from: import.meta.url,
|
|
306
|
+
try: true
|
|
307
|
+
}) ? "runtime" : "environments"].join("/")
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
var IntersectionObserver = class {
|
|
311
|
+
observe() {}
|
|
312
|
+
unobserve() {}
|
|
313
|
+
disconnect() {}
|
|
314
|
+
takeRecords() {
|
|
315
|
+
return [];
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
export { vitest_default as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { a as sendMessageToHost, r as listenHostMessages } from "../interface-Dhh_nx8F.mjs";
|
|
2
|
+
import { getPort } from "get-port-please";
|
|
3
|
+
// src/vitest-wrapper/cli.ts
|
|
4
|
+
function createCustomReporter(onVitestInit) {
|
|
5
|
+
let ctx = void 0;
|
|
6
|
+
function getVitestUiUrl() {
|
|
7
|
+
if (!ctx.config.ui) return void 0;
|
|
8
|
+
const protocol = ctx.vite.config.server.https ? "https:" : "http:";
|
|
9
|
+
const host = ctx.config.api.host || "localhost";
|
|
10
|
+
const port = ctx.config.api.port;
|
|
11
|
+
const token = ctx.config.api.token;
|
|
12
|
+
const uiUrl = `${protocol}//${host}:${port}${ctx.config.uiBase}`;
|
|
13
|
+
return token ? `${uiUrl}?token=${token}` : uiUrl;
|
|
14
|
+
}
|
|
15
|
+
function toUpdatedResult() {
|
|
16
|
+
const files = ctx.state.getFiles();
|
|
17
|
+
return {
|
|
18
|
+
failedCount: files.filter((f) => f.result?.state === "fail").length ?? 0,
|
|
19
|
+
passedCount: files.filter((f) => f.result?.state === "pass").length ?? 0,
|
|
20
|
+
totalCount: files.length ?? 0
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function toFinishedResult() {
|
|
24
|
+
return toUpdatedResult();
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
onInit(_ctx) {
|
|
28
|
+
ctx = _ctx;
|
|
29
|
+
onVitestInit(ctx);
|
|
30
|
+
sendMessageToHost("started", { uiUrl: getVitestUiUrl() });
|
|
31
|
+
},
|
|
32
|
+
onTestRunStart() {
|
|
33
|
+
sendMessageToHost("updated", toUpdatedResult());
|
|
34
|
+
},
|
|
35
|
+
onTestModuleCollected() {
|
|
36
|
+
sendMessageToHost("updated", toUpdatedResult());
|
|
37
|
+
},
|
|
38
|
+
onTestCaseResult() {
|
|
39
|
+
sendMessageToHost("updated", toUpdatedResult());
|
|
40
|
+
},
|
|
41
|
+
onTestModuleEnd() {
|
|
42
|
+
sendMessageToHost("updated", toUpdatedResult());
|
|
43
|
+
},
|
|
44
|
+
onTestRunEnd() {
|
|
45
|
+
sendMessageToHost("finished", toFinishedResult());
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function main() {
|
|
50
|
+
const { apiPorts, watchMode } = await new Promise((resolve) => {
|
|
51
|
+
listenHostMessages(({ type, payload }) => {
|
|
52
|
+
if (type === "start") resolve(payload);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
const port = apiPorts ? await getPort({ ports: apiPorts }) : void 0;
|
|
56
|
+
const { startVitest } = await import("vitest/node");
|
|
57
|
+
const customReporter = createCustomReporter((vitest) => {
|
|
58
|
+
listenHostMessages(async ({ type, payload }) => {
|
|
59
|
+
if (type === "stop") {
|
|
60
|
+
await vitest.exit(payload.force);
|
|
61
|
+
process.exit();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
const vitest = await startVitest("test", [], watchMode ? {
|
|
66
|
+
passWithNoTests: true,
|
|
67
|
+
ui: true,
|
|
68
|
+
watch: true,
|
|
69
|
+
open: false,
|
|
70
|
+
api: { port }
|
|
71
|
+
} : {
|
|
72
|
+
ui: false,
|
|
73
|
+
watch: false
|
|
74
|
+
}, { test: { reporters: ["default", customReporter] } });
|
|
75
|
+
if (!watchMode) {
|
|
76
|
+
await vitest.exit();
|
|
77
|
+
process.exit();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
main();
|
|
81
|
+
export {};
|