@untestutils/nuxt 0.5.1 → 0.5.3
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/dist/config/index.d.mts +9 -2
- package/dist/config/index.d.ts +9 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.mjs +6 -5
- package/dist/index.d.mts +10 -3
- package/dist/index.d.ts +12 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +37 -66
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.mjs +26 -38
- package/dist/runtime/index.d.mts +20 -7
- package/dist/runtime/index.d.ts +20 -7
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/nuxt-root.d.ts.map +1 -1
- package/dist/runtime/nuxt-root.mjs +0 -1
- package/dist/runtime/shared/nuxt.d.ts.map +1 -1
- package/dist/runtime/shared/nuxt.mjs +0 -1
- package/dist/runtime/suspended.d.ts.map +1 -1
- package/dist/runtime/suspended.mjs +0 -1
- package/package.json +2 -2
package/dist/config/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type DotenvOptions } from "c12";
|
|
1
2
|
import type { Nuxt, NuxtConfig, ViteConfig as NuxtViteConfig } from "@nuxt/schema";
|
|
2
|
-
import type
|
|
3
|
-
import type { InlineConfig as VitestConfig } from "vitest/node";
|
|
3
|
+
import { type InlineConfig as VitestConfig } from "vitest/node";
|
|
4
4
|
import type { Plugin, UserConfig as ViteUserConfig } from "vite";
|
|
5
5
|
type NitroRef = {
|
|
6
6
|
current?: {
|
|
@@ -35,6 +35,13 @@ type ResolvedVitestConfig = ViteUserConfig & {
|
|
|
35
35
|
};
|
|
36
36
|
customLogger?: unknown;
|
|
37
37
|
};
|
|
38
|
+
/** Reject e2e plugin + unit environment in the same Vitest project. */
|
|
39
|
+
export declare function assertNoE2ePluginMixed(config: {
|
|
40
|
+
plugins?: unknown[];
|
|
41
|
+
test?: {
|
|
42
|
+
environment?: unknown;
|
|
43
|
+
};
|
|
44
|
+
}): void;
|
|
38
45
|
export interface NuxtConfigOptions {
|
|
39
46
|
rootDir?: string;
|
|
40
47
|
domEnvironment?: "happy-dom" | "jsdom";
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type DotenvOptions } from 'c12';
|
|
1
2
|
import type { Nuxt, NuxtConfig, ViteConfig as NuxtViteConfig } from '@nuxt/schema';
|
|
2
|
-
import type
|
|
3
|
-
import type { InlineConfig as VitestConfig } from 'vitest/node';
|
|
3
|
+
import { type InlineConfig as VitestConfig } from 'vitest/node';
|
|
4
4
|
import type { Plugin, UserConfig as ViteUserConfig } from 'vite';
|
|
5
5
|
type NitroRef = {
|
|
6
6
|
current?: {
|
|
@@ -35,6 +35,13 @@ type ResolvedVitestConfig = ViteUserConfig & {
|
|
|
35
35
|
};
|
|
36
36
|
customLogger?: unknown;
|
|
37
37
|
};
|
|
38
|
+
/** Reject e2e plugin + unit environment in the same Vitest project. */
|
|
39
|
+
export declare function assertNoE2ePluginMixed(config: {
|
|
40
|
+
plugins?: unknown[];
|
|
41
|
+
test?: {
|
|
42
|
+
environment?: unknown;
|
|
43
|
+
};
|
|
44
|
+
}): void;
|
|
38
45
|
export interface NuxtConfigOptions {
|
|
39
46
|
rootDir?: string;
|
|
40
47
|
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,KAAK,CAAC;AAGtD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAW,KAAK,YAAY,IAAI,YAAY,EAAE,MAAM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OAAO,CAAA;KAAE,CAAC;CAClC,GAAG,IAAI,CASP;AAgGD,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IACvC,SAAS,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAChC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC7D,IAAI,CAAC,EAAE,YAAY,GAAG;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,kBAAkB,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,iBAAiB,CAAC;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAE,CAAC;KAC3E,CAAC;CACH;AAED,wBAAsB,uBAAuB,CAC3C,OAAO,CAAC,EAAE,oBAAoB,EAC9B,eAAe,GAAE,gBAAqB,GACrC,OAAO,CAAC,oBAAoB,CAAC,CAuJ/B;AAKD,wBAAsB,mBAAmB,CACvC,MAAM,CAAC,EAAE,uBAAuB,GAC/B,OAAO,CAAC,oBAAoB,CAAC,CAO/B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,GAAE,uBAA4B,GACnC,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAqErC"}
|
package/dist/config/index.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import { deepCopy, loadKit, applyEnv } from "./utils.mjs";
|
|
|
3
3
|
import { createDefu, defu } from "defu";
|
|
4
4
|
import { resolveModulePath } from "exsolve";
|
|
5
5
|
import process from "node:process";
|
|
6
|
-
import { version } from "vitest/node";
|
|
7
6
|
import { setupDotenv } from "c12";
|
|
8
7
|
import { getPackageInfoSync } from "local-pkg";
|
|
9
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { version } from "vitest/node";
|
|
10
10
|
|
|
11
11
|
function runtimeFile(rel) {
|
|
12
12
|
return fileURLToPath(new URL(`../runtime/${rel}.mjs`, import.meta.url));
|
|
@@ -17,12 +17,13 @@ function isUnitEnvironmentName(env) {
|
|
|
17
17
|
function isNamedPlugin(plugin) {
|
|
18
18
|
return typeof plugin === "object" && plugin !== null && "name" in plugin;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
export function assertNoE2ePluginMixed(config) {
|
|
21
22
|
const plugins = config.plugins || [];
|
|
22
23
|
const hasE2e = plugins.some((p) => isNamedPlugin(p) && p.name === "untestutils");
|
|
23
24
|
const env = config.test?.environment;
|
|
24
25
|
if (hasE2e && isUnitEnvironmentName(env)) {
|
|
25
|
-
|
|
26
|
+
throw new Error("[untestutils] Do not mix `untestutils/vitest/plugin` (e2e) with `environment: 'untestutils'` (unit). Use separate Vitest projects.");
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
const PLUGIN_NAME = "untestutils:vitest:environment-options";
|
|
@@ -216,7 +217,7 @@ const UNIT_ENVIRONMENT = "untestutils";
|
|
|
216
217
|
export async function defineVitestProject(config) {
|
|
217
218
|
const resolvedConfig = await resolveConfig(defu({ test: { environment: UNIT_ENVIRONMENT } }, config));
|
|
218
219
|
resolvedConfig.extends ??= false;
|
|
219
|
-
|
|
220
|
+
assertNoE2ePluginMixed(resolvedConfig);
|
|
220
221
|
return resolvedConfig;
|
|
221
222
|
}
|
|
222
223
|
export function defineVitestConfig(config = {}) {
|
|
@@ -273,7 +274,7 @@ export function defineVitestConfig(config = {}) {
|
|
|
273
274
|
} else {
|
|
274
275
|
resolvedConfig.test.environment = UNIT_ENVIRONMENT;
|
|
275
276
|
}
|
|
276
|
-
|
|
277
|
+
assertNoE2ePluginMixed(resolvedConfig);
|
|
277
278
|
return resolvedConfig;
|
|
278
279
|
};
|
|
279
280
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NuxtConfig } from "@nuxt/schema";
|
|
2
|
+
import { waitForHttpReady, type Driver, type Recipe } from "@untestutils/core";
|
|
2
3
|
export type NuxtRun = "server" | "static" | "dev";
|
|
4
|
+
/** User overrides for `loadNuxt({ overrides })` — includes Nitro fields Nuxt schema omits at the top level. */
|
|
5
|
+
export type NuxtConfigOverride = Partial<NuxtConfig> & {
|
|
6
|
+
nitro?: Record<string, unknown>;
|
|
7
|
+
};
|
|
3
8
|
export interface NuxtOptions {
|
|
4
9
|
id?: string;
|
|
5
10
|
root: string;
|
|
6
11
|
run?: NuxtRun;
|
|
7
|
-
|
|
12
|
+
/** Nuxt config overrides merged into `loadNuxt({ overrides })`. */
|
|
13
|
+
nuxtConfig?: NuxtConfigOverride;
|
|
8
14
|
hashInputs?: string[];
|
|
9
15
|
/** Include nearby monorepo package src dirs in prepare hash (auto when workspace exists). */
|
|
10
16
|
workspaceDeps?: boolean | "auto";
|
|
@@ -24,12 +30,13 @@ export declare const _internals: NuxtInternals;
|
|
|
24
30
|
* `run: 'static'` — generate + static file server
|
|
25
31
|
* `run: 'dev'` — nuxi `_dev` only (HMR fixtures; never shared). Default path is still build → nitro.
|
|
26
32
|
*/
|
|
27
|
-
export declare
|
|
33
|
+
export declare const nuxt: Driver<NuxtOptions>;
|
|
28
34
|
export { waitForHttpReady };
|
|
29
35
|
export type MatrixVariant = Partial<Pick<NuxtOptions, "env" | "nuxtConfig" | "hashInputs" | "run" | "preset" | "readyTimeoutMs" | "workspaceDeps">>;
|
|
30
36
|
/**
|
|
31
37
|
* Expand one Nuxt recipe base into many recipes with distinct ids / identity.
|
|
32
38
|
* Variant key `default` keeps `base.id`; other keys become `${baseId}__${key}`.
|
|
39
|
+
* Nitro-aware merge of `nuxtConfig` (generic `matrixRecipe` lives in `@untestutils/core`).
|
|
33
40
|
*/
|
|
34
41
|
export declare function matrix(base: NuxtOptions, variants: Record<string, MatrixVariant>): Record<string, Recipe>;
|
|
35
42
|
/** Nuxt-aware goto wait helpers are provided by vitest/playwright runners via playwright page. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NuxtConfig } from '@nuxt/schema';
|
|
2
|
+
import { findWorkspaceRoot, waitForHttpReady, workspacePackageSrcDirs, type Driver, type Recipe } from '@untestutils/core';
|
|
2
3
|
export type NuxtRun = 'server' | 'static' | 'dev';
|
|
4
|
+
/** User overrides for `loadNuxt({ overrides })` — includes Nitro fields Nuxt schema omits at the top level. */
|
|
5
|
+
export type NuxtConfigOverride = Partial<NuxtConfig> & {
|
|
6
|
+
nitro?: Record<string, unknown>;
|
|
7
|
+
};
|
|
3
8
|
export interface NuxtOptions {
|
|
4
9
|
id?: string;
|
|
5
10
|
root: string;
|
|
6
11
|
run?: NuxtRun;
|
|
7
|
-
|
|
12
|
+
/** Nuxt config overrides merged into `loadNuxt({ overrides })`. */
|
|
13
|
+
nuxtConfig?: NuxtConfigOverride;
|
|
8
14
|
hashInputs?: string[];
|
|
9
15
|
/** Include nearby monorepo package src dirs in prepare hash (auto when workspace exists). */
|
|
10
16
|
workspaceDeps?: boolean | 'auto';
|
|
@@ -24,12 +30,10 @@ declare function resolveKit(rootDir: string): string;
|
|
|
24
30
|
* Walks fixture → cwd → workspace root so bare fixture package.json still works.
|
|
25
31
|
*/
|
|
26
32
|
declare function resolveNuxiEntry(rootDir: string): string;
|
|
27
|
-
declare function findWorkspaceRoot(from: string): string | undefined;
|
|
28
|
-
declare function workspacePackageSrcDirs(from: string): Promise<string[]>;
|
|
29
33
|
declare function resolveHashInputs(opts: NuxtOptions, root: string): Promise<string[]>;
|
|
30
34
|
declare function withEnv<T>(env: Record<string, string> | undefined, fn: () => Promise<T>): Promise<T>;
|
|
31
|
-
declare function buildNuxtApp(rootDir: string, outDir: string, nuxtConfig?:
|
|
32
|
-
declare function generateNuxtApp(rootDir: string, outDir: string, nuxtConfig?:
|
|
35
|
+
declare function buildNuxtApp(rootDir: string, outDir: string, nuxtConfig?: NuxtConfigOverride, ssr?: boolean): Promise<void>;
|
|
36
|
+
declare function generateNuxtApp(rootDir: string, outDir: string, nuxtConfig?: NuxtConfigOverride): Promise<void>;
|
|
33
37
|
declare function findServerEntry(outDir: string): string;
|
|
34
38
|
declare function findPublicDir(outDir: string): string;
|
|
35
39
|
/** @internal test seams */
|
|
@@ -52,12 +56,13 @@ export declare const _internals: NuxtInternals;
|
|
|
52
56
|
* `run: 'static'` — generate + static file server
|
|
53
57
|
* `run: 'dev'` — nuxi `_dev` only (HMR fixtures; never shared). Default path is still build → nitro.
|
|
54
58
|
*/
|
|
55
|
-
export declare
|
|
59
|
+
export declare const nuxt: Driver<NuxtOptions>;
|
|
56
60
|
export { waitForHttpReady };
|
|
57
61
|
export type MatrixVariant = Partial<Pick<NuxtOptions, 'env' | 'nuxtConfig' | 'hashInputs' | 'run' | 'preset' | 'readyTimeoutMs' | 'workspaceDeps'>>;
|
|
58
62
|
/**
|
|
59
63
|
* Expand one Nuxt recipe base into many recipes with distinct ids / identity.
|
|
60
64
|
* Variant key `default` keeps `base.id`; other keys become `${baseId}__${key}`.
|
|
65
|
+
* Nitro-aware merge of `nuxtConfig` (generic `matrixRecipe` lives in `@untestutils/core`).
|
|
61
66
|
*/
|
|
62
67
|
export declare function matrix(base: NuxtOptions, variants: Record<string, MatrixVariant>): Record<string, Recipe>;
|
|
63
68
|
/** Nuxt-aware goto wait helpers are provided by vitest/playwright runners via playwright page. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAIL,iBAAiB,EAKjB,gBAAgB,E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,aAAa,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBxB;AAED,kGAAkG;AAClG,eAAe,IAAI,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { readdir } from "node:fs/promises";
|
|
4
3
|
import { dirname, join, resolve } from "pathe";
|
|
5
4
|
import { pathToFileURL } from "node:url";
|
|
6
|
-
import { defineRecipe, loopbackUrl,
|
|
5
|
+
import { assertAppRoot, defineDriver, defineRecipe, findWorkspaceRoot, loopbackUrl, matrixRecipe, spawnManaged, staticDir, waitForHttpReady, withQuietLogger, workspacePackageSrcDirs } from "@untestutils/core";
|
|
7
6
|
function resolveKit(rootDir) {
|
|
8
7
|
|
|
9
8
|
assertAppRoot(rootDir, "nuxt", { requirePackageJson: false });
|
|
@@ -39,34 +38,10 @@ function resolveNuxiEntry(rootDir) {
|
|
|
39
38
|
}
|
|
40
39
|
throw new Error(`[untestutils/nuxt] cannot resolve Nuxt CLI from ${rootDir} (tried nuxi/cli and nuxt/bin/nuxt.mjs)`);
|
|
41
40
|
}
|
|
42
|
-
function findWorkspaceRoot(from) {
|
|
43
|
-
let dir = resolve(from);
|
|
44
|
-
for (let i = 0; i < 12; i++) {
|
|
45
|
-
if (existsSync(join(dir, "pnpm-workspace.yaml")) || existsSync(join(dir, "pnpm-workspace.yml"))) {
|
|
46
|
-
return dir;
|
|
47
|
-
}
|
|
48
|
-
const parent = dirname(dir);
|
|
49
|
-
if (parent === dir) break;
|
|
50
|
-
dir = parent;
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
async function workspacePackageSrcDirs(from) {
|
|
55
|
-
const ws = findWorkspaceRoot(from);
|
|
56
|
-
if (!ws) return [];
|
|
57
|
-
const packagesDir = join(ws, "packages");
|
|
58
|
-
if (!existsSync(packagesDir)) return [];
|
|
59
|
-
const names = await readdir(packagesDir, { withFileTypes: true }).catch(() => []);
|
|
60
|
-
const out = [];
|
|
61
|
-
for (const e of names) {
|
|
62
|
-
if (!e.isDirectory()) continue;
|
|
63
|
-
const src = join(packagesDir, e.name, "src");
|
|
64
|
-
if (existsSync(src)) out.push(src);
|
|
65
|
-
}
|
|
66
|
-
return out;
|
|
67
|
-
}
|
|
68
41
|
async function resolveHashInputs(opts, root) {
|
|
69
42
|
const inputs = [...opts.hashInputs ?? [root]];
|
|
43
|
+
|
|
44
|
+
|
|
70
45
|
const wantWs = opts.workspaceDeps === true || opts.workspaceDeps !== false && Boolean(findWorkspaceRoot(root));
|
|
71
46
|
if (wantWs) {
|
|
72
47
|
inputs.push(...await workspacePackageSrcDirs(root));
|
|
@@ -192,7 +167,7 @@ export const _internals = {
|
|
|
192
167
|
withEnv
|
|
193
168
|
};
|
|
194
169
|
|
|
195
|
-
export
|
|
170
|
+
export const nuxt = defineDriver((opts) => {
|
|
196
171
|
const root = resolve(opts.root);
|
|
197
172
|
const runMode = opts.run ?? "server";
|
|
198
173
|
const id = opts.id ?? `nuxt-${runMode}-${root.split("/").pop()}`;
|
|
@@ -308,47 +283,43 @@ export function nuxt(opts) {
|
|
|
308
283
|
});
|
|
309
284
|
recipe.root = root;
|
|
310
285
|
return recipe;
|
|
311
|
-
}
|
|
286
|
+
});
|
|
312
287
|
export { waitForHttpReady };
|
|
313
288
|
|
|
314
289
|
export function matrix(base, variants) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
290
|
+
const withId = {
|
|
291
|
+
...base,
|
|
292
|
+
id: base.id ?? `nuxt-${base.run ?? "server"}`
|
|
293
|
+
};
|
|
294
|
+
return matrixRecipe(nuxt, withId, variants, {
|
|
295
|
+
label: "nuxt",
|
|
296
|
+
merge: (b, patch, id, name) => {
|
|
297
|
+
const baseNitro = b.nuxtConfig?.nitro ?? {};
|
|
298
|
+
const patchNitro = patch.nuxtConfig?.nitro ?? {};
|
|
299
|
+
return {
|
|
300
|
+
...b,
|
|
301
|
+
...patch,
|
|
302
|
+
id,
|
|
303
|
+
env: {
|
|
304
|
+
...b.env ?? {},
|
|
305
|
+
...patch.env ?? {}
|
|
306
|
+
},
|
|
307
|
+
nuxtConfig: {
|
|
308
|
+
...b.nuxtConfig ?? {},
|
|
309
|
+
...patch.nuxtConfig ?? {},
|
|
310
|
+
nitro: {
|
|
311
|
+
...baseNitro,
|
|
312
|
+
...patchNitro
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
hashInputs: [
|
|
316
|
+
...b.hashInputs ?? [b.root],
|
|
317
|
+
...patch.hashInputs ?? [],
|
|
318
|
+
`variant:${name}`
|
|
319
|
+
]
|
|
320
|
+
};
|
|
324
321
|
}
|
|
325
|
-
|
|
326
|
-
const patchNitro = patch.nuxtConfig?.nitro ?? {};
|
|
327
|
-
const merged = {
|
|
328
|
-
...base,
|
|
329
|
-
...patch,
|
|
330
|
-
id,
|
|
331
|
-
env: {
|
|
332
|
-
...base.env ?? {},
|
|
333
|
-
...patch.env ?? {}
|
|
334
|
-
},
|
|
335
|
-
nuxtConfig: {
|
|
336
|
-
...base.nuxtConfig ?? {},
|
|
337
|
-
...patch.nuxtConfig ?? {},
|
|
338
|
-
nitro: {
|
|
339
|
-
...baseNitro,
|
|
340
|
-
...patchNitro
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
hashInputs: [
|
|
344
|
-
...base.hashInputs ?? [base.root],
|
|
345
|
-
...patch.hashInputs ?? [],
|
|
346
|
-
`variant:${name}`
|
|
347
|
-
]
|
|
348
|
-
};
|
|
349
|
-
out[id] = nuxt(merged);
|
|
350
|
-
}
|
|
351
|
-
return out;
|
|
322
|
+
});
|
|
352
323
|
}
|
|
353
324
|
|
|
354
325
|
export default nuxt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAA8B,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/module/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAA8B,UAAU,EAAE,MAAM,cAAc,CAAC;AAgZ3E,QAAA,MAAM,iBAAiB,EAAE,UA4DvB,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
package/dist/module/index.mjs
CHANGED
|
@@ -12,6 +12,7 @@ const HELPER_MOCK_IMPORT = "mockNuxtImport";
|
|
|
12
12
|
const HELPER_UNMOCK_IMPORT = "unmockNuxtImport";
|
|
13
13
|
const HELPER_MOCK_COMPONENT = "mockComponent";
|
|
14
14
|
const HELPER_MOCK_HOIST = "__NUXT_VITEST_MOCKS";
|
|
15
|
+
const HELPER_MOCK_HOIST_FNS = "__NUXT_VITEST_MOCK_FNS";
|
|
15
16
|
const HELPER_MOCK_HOIST_ORIGINAL = "__NUXT_VITEST_MOCKS_ORIGINAL";
|
|
16
17
|
const HELPER_MOCK_HOIST_PREVIOUS = "__NUXT_VITEST_MOCKS_PREVIOUS";
|
|
17
18
|
const HELPERS_NAME = [
|
|
@@ -19,6 +20,7 @@ const HELPERS_NAME = [
|
|
|
19
20
|
HELPER_UNMOCK_IMPORT,
|
|
20
21
|
HELPER_MOCK_COMPONENT
|
|
21
22
|
];
|
|
23
|
+
|
|
22
24
|
const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
23
25
|
return {
|
|
24
26
|
name: PLUGIN_NAME,
|
|
@@ -36,12 +38,15 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
|
36
38
|
let insertionPoint = 0;
|
|
37
39
|
let hasViImport = false;
|
|
38
40
|
const s = new MagicString(code);
|
|
39
|
-
const
|
|
40
|
-
const unmocksFrom = new Set();
|
|
41
|
+
const mockModules = new Set();
|
|
41
42
|
const mocksComponent = [];
|
|
42
43
|
const importPathsList = new Set();
|
|
44
|
+
let touchedImportHelpers = false;
|
|
43
45
|
// @ts-expect-error mismatch between acorn/estree types
|
|
44
46
|
walk(ast, { enter: (node, parent) => {
|
|
47
|
+
const overwriteCall = (replacement) => {
|
|
48
|
+
s.overwrite(isExpressionStatement(parent) ? startOf(parent) : startOf(node), isExpressionStatement(parent) ? endOf(parent) : endOf(node), replacement);
|
|
49
|
+
};
|
|
45
50
|
const removeCallExpression = (start, end = start) => {
|
|
46
51
|
s.overwrite(isExpressionStatement(parent) ? startOf(parent) : startOf(start), isExpressionStatement(parent) ? endOf(parent) : endOf(end), "");
|
|
47
52
|
};
|
|
@@ -67,24 +72,21 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
|
67
72
|
if (node.arguments.length !== 2) return this.error(new Error(`${HELPER_MOCK_IMPORT}() should have exactly 2 arguments`), startOf(node));
|
|
68
73
|
const { name, importItem } = parseMockImportTarget(node.arguments[0], HELPER_MOCK_IMPORT);
|
|
69
74
|
if (!importItem) return this.error(`Cannot find import "${name}" to mock`);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const factoryCode = code.slice(startOf(node.arguments[1]), endOf(node.arguments[1]));
|
|
76
|
+
const quotedFrom = JSON.stringify(importItem.from);
|
|
77
|
+
const quotedName = JSON.stringify(importItem.name);
|
|
78
|
+
overwriteCall(`(() => {` + ` const __from = ${quotedFrom};` + ` const __name = ${quotedName};` + ` const __factory = (${factoryCode});` + ` globalThis.${HELPER_MOCK_HOIST_FNS} ??= {};` + ` (globalThis.${HELPER_MOCK_HOIST_FNS}[__from] ??= {})[__name] = __factory;` + ` const __entry = globalThis.${HELPER_MOCK_HOIST}?.[__from];` + ` if (__entry) {` + ` const __value = __factory(__entry.${HELPER_MOCK_HOIST_ORIGINAL}[__name]);` + ` if (__value != null && typeof __value.then === 'function')` + ` throw new Error('mockNuxtImport() factory must be synchronous once the import module is loaded');` + ` __entry[__name] = __value;` + ` __entry.${HELPER_MOCK_HOIST_PREVIOUS}[__name] = __value;` + ` }` + ` })()`);
|
|
79
|
+
mockModules.add(importItem.from);
|
|
80
|
+
touchedImportHelpers = true;
|
|
76
81
|
}
|
|
77
82
|
if (isIdentifier(node.callee) && node.callee.name === HELPER_UNMOCK_IMPORT) {
|
|
78
83
|
if (node.arguments.length !== 1) return this.error(new Error(`${HELPER_UNMOCK_IMPORT}() should have exactly 1 argument`), startOf(node));
|
|
79
84
|
const { name, importItem } = parseMockImportTarget(node.arguments[0], HELPER_UNMOCK_IMPORT);
|
|
80
85
|
if (!importItem) return this.error(`Cannot find import "${name}" to unmock`);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
import: importItem,
|
|
86
|
-
factory: undefined
|
|
87
|
-
});
|
|
86
|
+
const quotedFrom = JSON.stringify(importItem.from);
|
|
87
|
+
const quotedName = JSON.stringify(importItem.name);
|
|
88
|
+
overwriteCall(`(() => {` + ` const __from = ${quotedFrom};` + ` const __name = ${quotedName};` + ` globalThis.${HELPER_MOCK_HOIST_FNS} ??= {};` + ` (globalThis.${HELPER_MOCK_HOIST_FNS}[__from] ??= {})[__name] = null;` + ` const __entry = globalThis.${HELPER_MOCK_HOIST}?.[__from];` + ` if (__entry) {` + ` __entry[__name] = __entry.${HELPER_MOCK_HOIST_ORIGINAL}[__name];` + ` delete __entry.${HELPER_MOCK_HOIST_PREVIOUS}[__name];` + ` }` + ` })()`);
|
|
89
|
+
touchedImportHelpers = true;
|
|
88
90
|
}
|
|
89
91
|
if (isIdentifier(node.callee) && node.callee.name === HELPER_MOCK_COMPONENT) {
|
|
90
92
|
if (node.arguments.length !== 2) return this.error(new Error(`${HELPER_MOCK_COMPONENT}() should have exactly 2 arguments`), startOf(node));
|
|
@@ -99,22 +101,14 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
} });
|
|
102
|
-
if (
|
|
104
|
+
if (!touchedImportHelpers && mocksComponent.length === 0) return;
|
|
103
105
|
const mockLines = [];
|
|
104
|
-
for (const from of
|
|
105
|
-
for (const [from, mocks] of mapGroupBy(mocksImport, (mock) => mock.import.from)) {
|
|
106
|
+
for (const from of mockModules) {
|
|
106
107
|
importPathsList.add(from);
|
|
107
108
|
const quotedFrom = JSON.stringify(from);
|
|
108
109
|
const mockModuleEntry = `globalThis.${HELPER_MOCK_HOIST}[${quotedFrom}]`;
|
|
109
|
-
|
|
110
|
-
for (const
|
|
111
|
-
const quotedName = JSON.stringify(mock.import.name);
|
|
112
|
-
const original = `${mockModuleEntry}.${HELPER_MOCK_HOIST_ORIGINAL}[${quotedName}]`;
|
|
113
|
-
if (mock.factory === undefined) mockLines.push(` ${mockModuleEntry}[${quotedName}] = ${original}`, ` delete ${mockModuleEntry}.${HELPER_MOCK_HOIST_PREVIOUS}[${quotedName}]`);
|
|
114
|
-
else mockLines.push(` ${mockModuleEntry}[${quotedName}] = await (${mock.factory})(${original})`, ` ${mockModuleEntry}.${HELPER_MOCK_HOIST_PREVIOUS}[${quotedName}] = ${mockModuleEntry}[${quotedName}]`);
|
|
115
|
-
}
|
|
116
|
-
mockLines.push(` return ${mockModuleEntry}`);
|
|
117
|
-
mockLines.push(`});`);
|
|
110
|
+
const fnsEntry = `globalThis.${HELPER_MOCK_HOIST_FNS}?.[${quotedFrom}]`;
|
|
111
|
+
mockLines.push(`vi.mock(${quotedFrom}, async (importOriginal) => {`, ` if (!${mockModuleEntry}) {`, ` const original = await importOriginal()`, ` const previous = {}`, ` ${mockModuleEntry} = { ...original, ...previous }`, ` ${mockModuleEntry}.${HELPER_MOCK_HOIST_ORIGINAL} = { ...original }`, ` ${mockModuleEntry}.${HELPER_MOCK_HOIST_PREVIOUS} = { ...previous }`, ` }`, ` const __fns = ${fnsEntry} ?? {}`, ` for (const __name of Object.keys(__fns)) {`, ` const __factory = __fns[__name]`, ` const __original = ${mockModuleEntry}.${HELPER_MOCK_HOIST_ORIGINAL}[__name]`, ` if (__factory == null) {`, ` ${mockModuleEntry}[__name] = __original`, ` delete ${mockModuleEntry}.${HELPER_MOCK_HOIST_PREVIOUS}[__name]`, ` } else {`, ` ${mockModuleEntry}[__name] = await __factory(__original)`, ` ${mockModuleEntry}.${HELPER_MOCK_HOIST_PREVIOUS}[__name] = ${mockModuleEntry}[__name]`, ` }`, ` }`, ` return ${mockModuleEntry}`, `});`);
|
|
118
112
|
}
|
|
119
113
|
if (mocksComponent.length) mockLines.push(...mocksComponent.flatMap((mock) => {
|
|
120
114
|
return [
|
|
@@ -125,18 +119,21 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
|
125
119
|
"});"
|
|
126
120
|
];
|
|
127
121
|
}));
|
|
128
|
-
if (!mockLines.length) return;
|
|
122
|
+
if (!mockLines.length && !touchedImportHelpers) return;
|
|
129
123
|
s.appendLeft(insertionPoint, [
|
|
130
124
|
``,
|
|
131
125
|
`vi.hoisted(() => {`,
|
|
132
126
|
` if(!globalThis.${HELPER_MOCK_HOIST}){`,
|
|
133
127
|
` vi.stubGlobal(${JSON.stringify(HELPER_MOCK_HOIST)}, {})`,
|
|
134
128
|
` }`,
|
|
129
|
+
` if(!globalThis.${HELPER_MOCK_HOIST_FNS}){`,
|
|
130
|
+
` vi.stubGlobal(${JSON.stringify(HELPER_MOCK_HOIST_FNS)}, {})`,
|
|
131
|
+
` }`,
|
|
135
132
|
`});`,
|
|
136
133
|
``
|
|
137
134
|
].join("\n"));
|
|
138
135
|
if (!hasViImport) s.prepend(`import {vi} from "vitest";\n`);
|
|
139
|
-
s.appendLeft(insertionPoint, "\n" + mockLines.join("\n") + "\n");
|
|
136
|
+
if (mockLines.length) s.appendLeft(insertionPoint, "\n" + mockLines.join("\n") + "\n");
|
|
140
137
|
importPathsList.forEach((p) => {
|
|
141
138
|
s.append(`\n import ${JSON.stringify(p)};`);
|
|
142
139
|
});
|
|
@@ -173,15 +170,6 @@ const isLiteral = (node) => node.type === "Literal";
|
|
|
173
170
|
const isExpressionStatement = (node) => node?.type === "ExpressionStatement";
|
|
174
171
|
const startOf = (node) => "range" in node && node.range ? node.range[0] : "start" in node ? node.start : 0;
|
|
175
172
|
const endOf = (node) => "range" in node && node.range ? node.range[1] : "end" in node ? node.end : startOf(node);
|
|
176
|
-
function mapGroupBy(items, keySelector) {
|
|
177
|
-
const map = new Map();
|
|
178
|
-
for (const item of items) {
|
|
179
|
-
const key = keySelector(item);
|
|
180
|
-
if (!map.has(key)) map.set(key, []);
|
|
181
|
-
map.get(key).push(item);
|
|
182
|
-
}
|
|
183
|
-
return map;
|
|
184
|
-
}
|
|
185
173
|
//#endregion
|
|
186
174
|
//#region import mocking setup
|
|
187
175
|
const isTestPluginFile = (src) => src.includes(".spec.") || src.includes(".test.");
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* untestutils Nuxt in-process runtime utilities.
|
|
3
|
+
*
|
|
4
|
+
* Hybrid port of `@nuxt/test-utils/runtime`. These helpers run inside the
|
|
5
|
+
* `untestutils` vitest environment (see `vitest-environment-untestutils`) with
|
|
6
|
+
* the `untestutils/module` Nuxt module enabled so that `mockNuxtImport`,
|
|
7
|
+
* `mockComponent` and friends are transformed at build time.
|
|
8
|
+
*
|
|
9
|
+
* `suspended` is loaded dynamically because it imports Nuxt virtual modules
|
|
10
|
+
* (`#imports`, `#build/root-component.mjs`) that only resolve inside the test environment.
|
|
11
|
+
*/
|
|
12
|
+
import { type Component, type VNode } from "vue";
|
|
13
|
+
import { type MountingOptions, type VueWrapper } from "@vue/test-utils";
|
|
3
14
|
import type { render as testingLibraryRender } from "@testing-library/vue";
|
|
4
15
|
type Awaitable<T> = T | Promise<T>;
|
|
5
16
|
type RuntimeH3Event = {
|
|
@@ -17,7 +28,7 @@ type MountSuspendedOptions<T extends Component> = MountingOptions<T> & {
|
|
|
17
28
|
};
|
|
18
29
|
type TestingLibraryRender = typeof testingLibraryRender;
|
|
19
30
|
type RenderSuspendedOptions<T extends Component> = Parameters<TestingLibraryRender>[1] & MountSuspendedOptions<T>;
|
|
20
|
-
type RenderSuspendedResult<
|
|
31
|
+
type RenderSuspendedResult<_T extends Component = Component> = ReturnType<TestingLibraryRender> & {
|
|
21
32
|
rerender: (props?: Record<string, unknown>) => Promise<void>;
|
|
22
33
|
};
|
|
23
34
|
export type SuspendedHelpers = {
|
|
@@ -54,13 +65,15 @@ export interface RegisterEndpointOptions {
|
|
|
54
65
|
*/
|
|
55
66
|
export declare function registerEndpoint(url: string, options: RegisterEndpointOptions | RuntimeEndpointHandler): () => void;
|
|
56
67
|
/**
|
|
57
|
-
* `mockNuxtImport` mocks Nuxt
|
|
58
|
-
*
|
|
68
|
+
* `mockNuxtImport` mocks a Nuxt auto-import. `untestutils/module` rewrites the
|
|
69
|
+
* call to a runtime registry mutation on top of a hoisted `vi.mock`, so mock
|
|
70
|
+
* and `unmockNuxtImport` can be used in the same file (even across tests).
|
|
59
71
|
*/
|
|
60
72
|
export declare function mockNuxtImport<T = unknown>(_target: string | T, _factory: (original?: T) => T): void;
|
|
61
73
|
/**
|
|
62
|
-
* `unmockNuxtImport`
|
|
63
|
-
*
|
|
74
|
+
* `unmockNuxtImport` restores a previously mocked Nuxt auto-import. Safe to
|
|
75
|
+
* call in the same file as `mockNuxtImport` — it mutates the shared mock
|
|
76
|
+
* registry instead of emitting `vi.unmock`.
|
|
64
77
|
*/
|
|
65
78
|
export declare function unmockNuxtImport<T = unknown>(_target: string | T): void;
|
|
66
79
|
/**
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* untestutils Nuxt in-process runtime utilities.
|
|
3
|
+
*
|
|
4
|
+
* Hybrid port of `@nuxt/test-utils/runtime`. These helpers run inside the
|
|
5
|
+
* `untestutils` vitest environment (see `vitest-environment-untestutils`) with
|
|
6
|
+
* the `untestutils/module` Nuxt module enabled so that `mockNuxtImport`,
|
|
7
|
+
* `mockComponent` and friends are transformed at build time.
|
|
8
|
+
*
|
|
9
|
+
* `suspended` is loaded dynamically because it imports Nuxt virtual modules
|
|
10
|
+
* (`#imports`, `#build/root-component.mjs`) that only resolve inside the test environment.
|
|
11
|
+
*/
|
|
12
|
+
import { type Component, type VNode } from 'vue';
|
|
13
|
+
import { type MountingOptions, type VueWrapper } from '@vue/test-utils';
|
|
3
14
|
import type { render as testingLibraryRender } from '@testing-library/vue';
|
|
4
15
|
type Awaitable<T> = T | Promise<T>;
|
|
5
16
|
type RuntimeH3Event = {
|
|
@@ -17,7 +28,7 @@ type MountSuspendedOptions<T extends Component> = MountingOptions<T> & {
|
|
|
17
28
|
};
|
|
18
29
|
type TestingLibraryRender = typeof testingLibraryRender;
|
|
19
30
|
type RenderSuspendedOptions<T extends Component> = Parameters<TestingLibraryRender>[1] & MountSuspendedOptions<T>;
|
|
20
|
-
type RenderSuspendedResult<
|
|
31
|
+
type RenderSuspendedResult<_T extends Component = Component> = ReturnType<TestingLibraryRender> & {
|
|
21
32
|
rerender: (props?: Record<string, unknown>) => Promise<void>;
|
|
22
33
|
};
|
|
23
34
|
export type SuspendedHelpers = {
|
|
@@ -54,13 +65,15 @@ export interface RegisterEndpointOptions {
|
|
|
54
65
|
*/
|
|
55
66
|
export declare function registerEndpoint(url: string, options: RegisterEndpointOptions | RuntimeEndpointHandler): () => void;
|
|
56
67
|
/**
|
|
57
|
-
* `mockNuxtImport` mocks Nuxt
|
|
58
|
-
*
|
|
68
|
+
* `mockNuxtImport` mocks a Nuxt auto-import. `untestutils/module` rewrites the
|
|
69
|
+
* call to a runtime registry mutation on top of a hoisted `vi.mock`, so mock
|
|
70
|
+
* and `unmockNuxtImport` can be used in the same file (even across tests).
|
|
59
71
|
*/
|
|
60
72
|
export declare function mockNuxtImport<T = unknown>(_target: string | T, _factory: (original?: T) => T): void;
|
|
61
73
|
/**
|
|
62
|
-
* `unmockNuxtImport`
|
|
63
|
-
*
|
|
74
|
+
* `unmockNuxtImport` restores a previously mocked Nuxt auto-import. Safe to
|
|
75
|
+
* call in the same file as `mockNuxtImport` — it mutates the shared mock
|
|
76
|
+
* registry instead of emitting `vi.unmock`.
|
|
64
77
|
*/
|
|
65
78
|
export declare function unmockNuxtImport<T = unknown>(_target: string | T): void;
|
|
66
79
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAe,KAAK,SAAS,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAS,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,KAAK,EAAE,MAAM,IAAI,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAS3E,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AACnC,KAAK,cAAc,GAAG;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AACF,KAAK,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG;IACrF,cAAc,CAAC,EAAE,IAAI,CAAC;CACvB,CAAC;AAgBF,KAAK,qBAAqB,CAAC,CAAC,SAAS,SAAS,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG;IACrE,KAAK,CAAC,EAAE,OAAO,YAAY,EAAE,gBAAgB,GAAG,KAAK,CAAC;IACt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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt-root.d.ts","sourceRoot":"","sources":["../../src/runtime/nuxt-root.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nuxt-root.d.ts","sourceRoot":"","sources":["../../src/runtime/nuxt-root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,eAAe,EAA2C,MAAM,KAAK,CAAC;AAoCzF,QAAA,MAAM,iBAAiB,EAAE,UAAU,CAAC,OAAO,eAAe,CAkBxD,CAAC;AAEH,OAAO,EAAE,iBAAiB,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../../../src/runtime/shared/nuxt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nuxt.d.ts","sourceRoot":"","sources":["../../../src/runtime/shared/nuxt.ts"],"names":[],"mappings":"AAOA,kGAAkG;AAClG,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAe/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suspended.d.ts","sourceRoot":"","sources":["../../src/runtime/suspended.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"suspended.d.ts","sourceRoot":"","sources":["../../src/runtime/suspended.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EACR,KAAK,SAAS,EAKd,KAAK,KAAK,EAMX,MAAM,KAAK,CAAC;AAKb,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1C,KAAK,OAAO,GAAG,MAAM,IAAI,CAAC;AAI1B,KAAK,mBAAmB,GAAG,OAAO,iBAAiB,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG;IAChF,KAAK,CAAC,EAAE,OAAO,YAAY,EAAE,gBAAgB,GAAG,KAAK,CAAC;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;IAC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CAE1B;AAcD,iBAAS,gBAAgB,CAAC,QAAQ,EAChC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,mBAAmB,GAAG,SAAc,EAC7C,EACE,SAAS,EACT,aAAuC,EACvC,mBAAmB,EACnB,mBAAmB,EACnB,cAAqB,GACtB,EAAE,sBAAsB,GACxB,OAAO,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAC,CAqJ3C;AAqDD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@untestutils/nuxt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Nuxt recipes + in-process unit runtime, config, module, and Vitest environment",
|
|
5
5
|
"homepage": "https://s00d.github.io/untestutils/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"ufo": "^1.6.4",
|
|
93
93
|
"unimport": "^6.5.0",
|
|
94
94
|
"unplugin": "^3.3.0",
|
|
95
|
-
"@untestutils/core": "0.5.
|
|
95
|
+
"@untestutils/core": "0.5.3"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@types/estree": "^1.0.8",
|