@nuxt/test-utils-nightly 4.0.0-1702810232.fba662c → 4.0.0-1702910449.8cf01bd
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.d.mts +13 -1
- package/dist/config.d.ts +13 -1
- package/dist/config.mjs +57 -8
- package/dist/e2e.mjs +2 -2
- package/dist/experimental.mjs +1 -1
- package/dist/module.mjs +5 -2
- package/dist/shared/{test-utils-nightly.ddf5bsCK.mjs → test-utils-nightly.B1uaYm8K.mjs} +1 -2
- package/package.json +4 -1
package/dist/config.d.mts
CHANGED
|
@@ -2,12 +2,17 @@ import * as vite from 'vite';
|
|
|
2
2
|
import { InlineConfig } from 'vite';
|
|
3
3
|
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
4
4
|
import { InlineConfig as InlineConfig$1 } from 'vitest';
|
|
5
|
+
import { DotenvOptions } from 'c12';
|
|
5
6
|
|
|
6
7
|
interface GetVitestConfigOptions {
|
|
7
8
|
nuxt: Nuxt;
|
|
8
9
|
viteConfig: InlineConfig;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
interface LoadNuxtOptions {
|
|
12
|
+
dotenv?: Partial<DotenvOptions>;
|
|
13
|
+
overrides?: Partial<NuxtConfig>;
|
|
14
|
+
}
|
|
15
|
+
declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadNuxtOptions?: LoadNuxtOptions): Promise<InlineConfig & {
|
|
11
16
|
test: InlineConfig$1;
|
|
12
17
|
}>;
|
|
13
18
|
declare function defineVitestConfig(config?: InlineConfig & {
|
|
@@ -22,6 +27,13 @@ declare module 'vitest' {
|
|
|
22
27
|
* @default {http://localhost:3000}
|
|
23
28
|
*/
|
|
24
29
|
url?: string;
|
|
30
|
+
/**
|
|
31
|
+
* You can define how environment options are read when loading the Nuxt configuration.
|
|
32
|
+
*/
|
|
33
|
+
dotenv?: Partial<DotenvOptions>;
|
|
34
|
+
/**
|
|
35
|
+
* Configuration that will override the values in your `nuxt.config` file.
|
|
36
|
+
*/
|
|
25
37
|
overrides?: NuxtConfig;
|
|
26
38
|
/**
|
|
27
39
|
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
package/dist/config.d.ts
CHANGED
|
@@ -2,12 +2,17 @@ import * as vite from 'vite';
|
|
|
2
2
|
import { InlineConfig } from 'vite';
|
|
3
3
|
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
4
4
|
import { InlineConfig as InlineConfig$1 } from 'vitest';
|
|
5
|
+
import { DotenvOptions } from 'c12';
|
|
5
6
|
|
|
6
7
|
interface GetVitestConfigOptions {
|
|
7
8
|
nuxt: Nuxt;
|
|
8
9
|
viteConfig: InlineConfig;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
interface LoadNuxtOptions {
|
|
12
|
+
dotenv?: Partial<DotenvOptions>;
|
|
13
|
+
overrides?: Partial<NuxtConfig>;
|
|
14
|
+
}
|
|
15
|
+
declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadNuxtOptions?: LoadNuxtOptions): Promise<InlineConfig & {
|
|
11
16
|
test: InlineConfig$1;
|
|
12
17
|
}>;
|
|
13
18
|
declare function defineVitestConfig(config?: InlineConfig & {
|
|
@@ -22,6 +27,13 @@ declare module 'vitest' {
|
|
|
22
27
|
* @default {http://localhost:3000}
|
|
23
28
|
*/
|
|
24
29
|
url?: string;
|
|
30
|
+
/**
|
|
31
|
+
* You can define how environment options are read when loading the Nuxt configuration.
|
|
32
|
+
*/
|
|
33
|
+
dotenv?: Partial<DotenvOptions>;
|
|
34
|
+
/**
|
|
35
|
+
* Configuration that will override the values in your `nuxt.config` file.
|
|
36
|
+
*/
|
|
25
37
|
overrides?: NuxtConfig;
|
|
26
38
|
/**
|
|
27
39
|
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
package/dist/config.mjs
CHANGED
|
@@ -1,19 +1,56 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
|
+
import { setupDotenv } from 'c12';
|
|
2
3
|
import { defu } from 'defu';
|
|
3
4
|
import { createResolver } from '@nuxt/kit';
|
|
5
|
+
import destr from 'destr';
|
|
6
|
+
import { snakeCase } from 'scule';
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
function getEnv(key, opts) {
|
|
9
|
+
const env = opts.env ?? process.env;
|
|
10
|
+
const envKey = snakeCase(key).toUpperCase();
|
|
11
|
+
return destr(
|
|
12
|
+
env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey]
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
function _isObject(input) {
|
|
16
|
+
return typeof input === "object" && !Array.isArray(input);
|
|
17
|
+
}
|
|
18
|
+
function applyEnv(obj, opts, parentKey = "") {
|
|
19
|
+
for (const key in obj) {
|
|
20
|
+
const subKey = parentKey ? `${parentKey}_${key}` : key;
|
|
21
|
+
const envValue = getEnv(subKey, opts);
|
|
22
|
+
if (_isObject(obj[key])) {
|
|
23
|
+
if (_isObject(envValue)) {
|
|
24
|
+
obj[key] = { ...obj[key], ...envValue };
|
|
25
|
+
applyEnv(obj[key], opts, subKey);
|
|
26
|
+
} else if (envValue === void 0) {
|
|
27
|
+
applyEnv(obj[key], opts, subKey);
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = envValue ?? obj[key];
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = envValue ?? obj[key];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {}) {
|
|
6
39
|
const { loadNuxt, buildNuxt } = await import('@nuxt/kit');
|
|
7
40
|
const nuxt = await loadNuxt({
|
|
8
41
|
cwd: rootDir,
|
|
9
42
|
dev: false,
|
|
43
|
+
dotenv: defu(options.dotenv, {
|
|
44
|
+
cwd: rootDir,
|
|
45
|
+
fileName: ".env.test"
|
|
46
|
+
}),
|
|
10
47
|
overrides: defu(
|
|
11
48
|
{
|
|
12
49
|
ssr: false,
|
|
13
50
|
test: true,
|
|
14
51
|
modules: ["@nuxt/test-utils/module"]
|
|
15
52
|
},
|
|
16
|
-
overrides
|
|
53
|
+
options.overrides
|
|
17
54
|
)
|
|
18
55
|
});
|
|
19
56
|
if (!nuxt.options._installedModules.find((i) => i?.meta?.name === "@nuxt/test-utils")) {
|
|
@@ -40,12 +77,15 @@ const excludedPlugins = [
|
|
|
40
77
|
"nuxt:import-protection",
|
|
41
78
|
"vite-plugin-checker"
|
|
42
79
|
];
|
|
43
|
-
async function getVitestConfigFromNuxt(options,
|
|
44
|
-
const { rootDir = process.cwd(), ..._overrides } = overrides || {};
|
|
80
|
+
async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
|
|
81
|
+
const { rootDir = process.cwd(), ..._overrides } = loadNuxtOptions.overrides || {};
|
|
45
82
|
if (!options) {
|
|
46
83
|
options = await startNuxtAndGetViteConfig(rootDir, {
|
|
47
|
-
|
|
48
|
-
|
|
84
|
+
dotenv: loadNuxtOptions.dotenv,
|
|
85
|
+
overrides: {
|
|
86
|
+
test: true,
|
|
87
|
+
..._overrides
|
|
88
|
+
}
|
|
49
89
|
});
|
|
50
90
|
}
|
|
51
91
|
options.viteConfig.plugins = (options.viteConfig.plugins || []).filter((p) => !excludedPlugins.includes(p?.name));
|
|
@@ -58,7 +98,13 @@ async function getVitestConfigFromNuxt(options, overrides) {
|
|
|
58
98
|
test: {
|
|
59
99
|
dir: process.cwd(),
|
|
60
100
|
environmentOptions: {
|
|
61
|
-
nuxtRuntimeConfig: options.nuxt.options.runtimeConfig,
|
|
101
|
+
nuxtRuntimeConfig: applyEnv(structuredClone(options.nuxt.options.runtimeConfig), {
|
|
102
|
+
prefix: "NUXT_",
|
|
103
|
+
env: await setupDotenv(defu(loadNuxtOptions.dotenv, {
|
|
104
|
+
cwd: rootDir,
|
|
105
|
+
fileName: ".env.test"
|
|
106
|
+
}))
|
|
107
|
+
}),
|
|
62
108
|
nuxtRouteRules: defu(
|
|
63
109
|
{},
|
|
64
110
|
options.nuxt.options.routeRules,
|
|
@@ -148,7 +194,10 @@ function defineVitestConfig(config = {}) {
|
|
|
148
194
|
}
|
|
149
195
|
return defu(
|
|
150
196
|
config,
|
|
151
|
-
await getVitestConfigFromNuxt(void 0,
|
|
197
|
+
await getVitestConfigFromNuxt(void 0, {
|
|
198
|
+
dotenv: config.test?.environmentOptions?.nuxt?.dotenv,
|
|
199
|
+
overrides: structuredClone(overrides)
|
|
200
|
+
})
|
|
152
201
|
);
|
|
153
202
|
});
|
|
154
203
|
}
|
package/dist/e2e.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { u as useTestContext, a as url, c as createTestContext, s as setTestContext, b as stopServer, d as startServer } from './shared/test-utils-nightly.
|
|
2
|
-
export { $ as $fetch, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv } from './shared/test-utils-nightly.
|
|
1
|
+
import { u as useTestContext, a as url, c as createTestContext, s as setTestContext, b as stopServer, d as startServer } from './shared/test-utils-nightly.B1uaYm8K.mjs';
|
|
2
|
+
export { $ as $fetch, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv } from './shared/test-utils-nightly.B1uaYm8K.mjs';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
4
|
import { existsSync, promises } from 'node:fs';
|
|
5
5
|
import { resolve } from 'node:path';
|
package/dist/experimental.mjs
CHANGED
|
@@ -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-nightly.
|
|
3
|
+
import { $ as $fetch, u as useTestContext } from './shared/test-utils-nightly.B1uaYm8K.mjs';
|
|
4
4
|
import 'execa';
|
|
5
5
|
import 'get-port-please';
|
|
6
6
|
import 'ofetch';
|
package/dist/module.mjs
CHANGED
|
@@ -13,6 +13,9 @@ import { normalize, resolve } from 'node:path';
|
|
|
13
13
|
import { createUnplugin } from 'unplugin';
|
|
14
14
|
import { readFileSync } from 'node:fs';
|
|
15
15
|
import { extname, join, dirname } from 'pathe';
|
|
16
|
+
import 'c12';
|
|
17
|
+
import 'destr';
|
|
18
|
+
import 'scule';
|
|
16
19
|
|
|
17
20
|
const PLUGIN_NAME$1 = "nuxt:vitest:mock-transform";
|
|
18
21
|
const HELPER_MOCK_IMPORT = "mockNuxtImport";
|
|
@@ -405,10 +408,10 @@ const module = defineNuxtModule({
|
|
|
405
408
|
promise2.catch(() => process.exit(1));
|
|
406
409
|
if (watchMode) {
|
|
407
410
|
logger.info(`Vitest UI starting on ${URL}`);
|
|
411
|
+
nuxt.hook("close", () => promise2.then((v) => v?.close()));
|
|
408
412
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
409
413
|
} else {
|
|
410
|
-
promise2.then((v) => v?.close()).then(() => process.exit());
|
|
411
|
-
promise2.catch(() => process.exit(1));
|
|
414
|
+
promise2.then((v) => nuxt.close().then(() => v?.close()).then(() => process.exit()));
|
|
412
415
|
}
|
|
413
416
|
loaded = true;
|
|
414
417
|
}
|
|
@@ -18,8 +18,7 @@ function createTestContext(options) {
|
|
|
18
18
|
server: true,
|
|
19
19
|
build: options.browser !== false || options.server !== false,
|
|
20
20
|
nuxtConfig: {},
|
|
21
|
-
|
|
22
|
-
runner: "vitest",
|
|
21
|
+
runner: process.env.VITEST === "true" ? "vitest" : "jest",
|
|
23
22
|
browserOptions: {
|
|
24
23
|
type: "chromium"
|
|
25
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/test-utils-nightly",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-1702910449.8cf01bd",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/test-utils.git"
|
|
@@ -40,8 +40,10 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@nuxt/kit": "^3.8.2",
|
|
42
42
|
"@nuxt/schema": "^3.8.2",
|
|
43
|
+
"c12": "^1.5.1",
|
|
43
44
|
"consola": "^3.2.3",
|
|
44
45
|
"defu": "^6.1.3",
|
|
46
|
+
"destr": "^2.0.2",
|
|
45
47
|
"estree-walker": "^3.0.3",
|
|
46
48
|
"execa": "^8.0.1",
|
|
47
49
|
"fake-indexeddb": "^5.0.1",
|
|
@@ -53,6 +55,7 @@
|
|
|
53
55
|
"pathe": "^1.1.1",
|
|
54
56
|
"perfect-debounce": "^1.0.0",
|
|
55
57
|
"radix3": "^1.1.0",
|
|
58
|
+
"scule": "^1.1.1",
|
|
56
59
|
"std-env": "^3.6.0",
|
|
57
60
|
"ufo": "^1.3.2",
|
|
58
61
|
"unenv": "^1.8.0",
|