@nuxt/test-utils-nightly 4.0.0-1699284348.a89cc29 โ 4.0.0-1701501480.7490334
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 +18 -0
- package/config.d.ts +1 -0
- package/dist/config.d.mts +46 -0
- package/dist/config.d.ts +46 -0
- package/dist/config.mjs +144 -0
- package/dist/experimental.mjs +1 -1
- package/dist/index.mjs +8 -4
- package/dist/module.d.mts +11 -0
- package/dist/module.d.ts +11 -0
- package/dist/module.mjs +459 -0
- package/dist/runtime/entry.d.ts +1 -0
- package/dist/runtime/entry.mjs +8 -0
- package/dist/runtime/nuxt-root.d.ts +4 -0
- package/dist/runtime/nuxt-root.mjs +21 -0
- package/dist/runtime-utils.d.mts +150 -0
- package/dist/runtime-utils.d.ts +150 -0
- package/dist/runtime-utils.mjs +212 -0
- package/dist/vitest-environment.d.mts +22 -0
- package/dist/vitest-environment.d.ts +22 -0
- package/dist/vitest-environment.mjs +175 -0
- package/module.d.ts +1 -0
- package/package.json +87 -28
- package/runtime-utils.d.ts +1 -0
- package/vitest-environment.d.ts +1 -0
- /package/dist/shared/{test-utils-nightly.8f432eb9.mjs โ test-utils-nightly.ddf5bsCK.mjs} +0 -0
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Nuxt Test Utils
|
|
2
|
+
|
|
3
|
+
๐งช [Nuxt](https://nuxt.com/) Test Utils
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Nuxt offers first-class support for e2e and unit testing of your Nuxt applications. `@nuxt/test-utils` currently contains e2e test utilities allowing you to test your app in production/development environments, and [`nuxt-vitest`](https://github.com/danielroe/nuxt-vitest) is planned to be merged to provide unit testing capabilities.
|
|
8
|
+
|
|
9
|
+
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.
|
|
10
|
+
|
|
11
|
+
You can find out more about how to use Nuxt Test Utils:
|
|
12
|
+
|
|
13
|
+
- in [a general overview](https://nuxt.com/docs/getting-started/testing)
|
|
14
|
+
- in [an in-depth guide for module authors](https://nuxt.com/docs/guide/going-further/modules/#testing)
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
[MIT](./LICENSE)
|
package/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/config'
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { InlineConfig } from 'vite';
|
|
3
|
+
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
4
|
+
import { InlineConfig as InlineConfig$1 } from 'vitest';
|
|
5
|
+
|
|
6
|
+
interface GetVitestConfigOptions {
|
|
7
|
+
nuxt: Nuxt;
|
|
8
|
+
viteConfig: InlineConfig;
|
|
9
|
+
}
|
|
10
|
+
declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, overrides?: NuxtConfig): Promise<InlineConfig & {
|
|
11
|
+
test: InlineConfig$1;
|
|
12
|
+
}>;
|
|
13
|
+
declare function defineVitestConfig(config?: InlineConfig & {
|
|
14
|
+
test?: InlineConfig$1;
|
|
15
|
+
}): vite.UserConfig & Promise<vite.UserConfig> & vite.UserConfigFnObject & vite.UserConfigExport;
|
|
16
|
+
declare module 'vitest' {
|
|
17
|
+
interface EnvironmentOptions {
|
|
18
|
+
nuxt?: {
|
|
19
|
+
rootDir?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The starting URL for your Nuxt window environment
|
|
22
|
+
* @default {http://localhost:3000}
|
|
23
|
+
*/
|
|
24
|
+
url?: string;
|
|
25
|
+
overrides?: NuxtConfig;
|
|
26
|
+
/**
|
|
27
|
+
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
|
28
|
+
* @default {nuxt-test}
|
|
29
|
+
*/
|
|
30
|
+
rootId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The name of the DOM environment to use.
|
|
33
|
+
*
|
|
34
|
+
* It also needs to be installed as a dev dependency in your project.
|
|
35
|
+
* @default {happy-dom}
|
|
36
|
+
*/
|
|
37
|
+
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
38
|
+
mock?: {
|
|
39
|
+
intersectionObserver?: boolean;
|
|
40
|
+
indexedDb?: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { defineVitestConfig, getVitestConfigFromNuxt };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
import { InlineConfig } from 'vite';
|
|
3
|
+
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
4
|
+
import { InlineConfig as InlineConfig$1 } from 'vitest';
|
|
5
|
+
|
|
6
|
+
interface GetVitestConfigOptions {
|
|
7
|
+
nuxt: Nuxt;
|
|
8
|
+
viteConfig: InlineConfig;
|
|
9
|
+
}
|
|
10
|
+
declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, overrides?: NuxtConfig): Promise<InlineConfig & {
|
|
11
|
+
test: InlineConfig$1;
|
|
12
|
+
}>;
|
|
13
|
+
declare function defineVitestConfig(config?: InlineConfig & {
|
|
14
|
+
test?: InlineConfig$1;
|
|
15
|
+
}): vite.UserConfig & Promise<vite.UserConfig> & vite.UserConfigFnObject & vite.UserConfigExport;
|
|
16
|
+
declare module 'vitest' {
|
|
17
|
+
interface EnvironmentOptions {
|
|
18
|
+
nuxt?: {
|
|
19
|
+
rootDir?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The starting URL for your Nuxt window environment
|
|
22
|
+
* @default {http://localhost:3000}
|
|
23
|
+
*/
|
|
24
|
+
url?: string;
|
|
25
|
+
overrides?: NuxtConfig;
|
|
26
|
+
/**
|
|
27
|
+
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
|
28
|
+
* @default {nuxt-test}
|
|
29
|
+
*/
|
|
30
|
+
rootId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The name of the DOM environment to use.
|
|
33
|
+
*
|
|
34
|
+
* It also needs to be installed as a dev dependency in your project.
|
|
35
|
+
* @default {happy-dom}
|
|
36
|
+
*/
|
|
37
|
+
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
38
|
+
mock?: {
|
|
39
|
+
intersectionObserver?: boolean;
|
|
40
|
+
indexedDb?: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { defineVitestConfig, getVitestConfigFromNuxt };
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import { defu } from 'defu';
|
|
3
|
+
import { createResolver } from '@nuxt/kit';
|
|
4
|
+
|
|
5
|
+
async function startNuxtAndGetViteConfig(rootDir = process.cwd(), overrides) {
|
|
6
|
+
const { loadNuxt, buildNuxt } = await import('@nuxt/kit');
|
|
7
|
+
const nuxt = await loadNuxt({
|
|
8
|
+
cwd: rootDir,
|
|
9
|
+
dev: false,
|
|
10
|
+
overrides: defu(
|
|
11
|
+
{
|
|
12
|
+
ssr: false,
|
|
13
|
+
test: true,
|
|
14
|
+
modules: ["@nuxt/test-utils/module"]
|
|
15
|
+
},
|
|
16
|
+
overrides
|
|
17
|
+
)
|
|
18
|
+
});
|
|
19
|
+
if (!nuxt.options._installedModules.find((i) => i?.meta?.name === "@nuxt/test-utils")) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"Failed to load nuxt-vitest module. You may need to add it to your nuxt.config."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
const promise = new Promise((resolve, reject) => {
|
|
25
|
+
nuxt.hook("vite:configResolved", (viteConfig, { isClient }) => {
|
|
26
|
+
if (isClient) {
|
|
27
|
+
resolve({ nuxt, viteConfig });
|
|
28
|
+
throw new Error("_stop_");
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
buildNuxt(nuxt).catch((err) => {
|
|
32
|
+
if (!err.toString().includes("_stop_")) {
|
|
33
|
+
reject(err);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}).finally(() => nuxt.close());
|
|
37
|
+
return promise;
|
|
38
|
+
}
|
|
39
|
+
async function getVitestConfigFromNuxt(options, overrides) {
|
|
40
|
+
var _a;
|
|
41
|
+
const { rootDir = process.cwd(), ..._overrides } = overrides || {};
|
|
42
|
+
if (!options) {
|
|
43
|
+
options = await startNuxtAndGetViteConfig(rootDir, {
|
|
44
|
+
test: true,
|
|
45
|
+
..._overrides
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
(_a = options.viteConfig).plugins || (_a.plugins = []);
|
|
49
|
+
options.viteConfig.plugins = options.viteConfig.plugins?.filter(
|
|
50
|
+
(p) => p?.name !== "nuxt:import-protection"
|
|
51
|
+
);
|
|
52
|
+
const resolvedConfig = defu(
|
|
53
|
+
// overrides
|
|
54
|
+
{
|
|
55
|
+
define: {
|
|
56
|
+
["process.env.NODE_ENV"]: "process.env.NODE_ENV"
|
|
57
|
+
},
|
|
58
|
+
test: {
|
|
59
|
+
dir: process.cwd(),
|
|
60
|
+
environmentOptions: {
|
|
61
|
+
nuxtRuntimeConfig: options.nuxt.options.runtimeConfig,
|
|
62
|
+
nuxtRouteRules: defu(
|
|
63
|
+
{},
|
|
64
|
+
options.nuxt.options.routeRules,
|
|
65
|
+
options.nuxt.options.nitro?.routeRules
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
environmentMatchGlobs: [
|
|
69
|
+
["**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}", "nuxt"],
|
|
70
|
+
["{test,tests}/nuxt/**.*", "nuxt"]
|
|
71
|
+
],
|
|
72
|
+
deps: {
|
|
73
|
+
inline: [
|
|
74
|
+
// vite-node defaults
|
|
75
|
+
/\/node_modules\/(.*\/)?(nuxt|nuxt3|nuxt-nightly)\//,
|
|
76
|
+
/^#/,
|
|
77
|
+
// additional deps
|
|
78
|
+
"@nuxt/test-utils",
|
|
79
|
+
"@nuxt/test-utils-nightly",
|
|
80
|
+
"@nuxt/test-utils-edge",
|
|
81
|
+
"vitest-environment-nuxt",
|
|
82
|
+
...options.nuxt.options.build.transpile.filter(
|
|
83
|
+
(r) => typeof r === "string" || r instanceof RegExp
|
|
84
|
+
)
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
server: { middlewareMode: false },
|
|
91
|
+
plugins: [
|
|
92
|
+
{
|
|
93
|
+
name: "disable-auto-execute",
|
|
94
|
+
enforce: "pre",
|
|
95
|
+
transform(code, id) {
|
|
96
|
+
if (id.match(/nuxt(3|-nightly)?\/.*\/entry\./)) {
|
|
97
|
+
return code.replace(
|
|
98
|
+
/(?<!vueAppPromise = )entry\(\)\.catch/,
|
|
99
|
+
"Promise.resolve().catch"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
// resolved vite config
|
|
107
|
+
options.viteConfig,
|
|
108
|
+
// (overrideable) defaults
|
|
109
|
+
{
|
|
110
|
+
test: {
|
|
111
|
+
environmentOptions: {
|
|
112
|
+
nuxt: {
|
|
113
|
+
rootId: options.nuxt.options.app.rootId || void 0,
|
|
114
|
+
mock: {
|
|
115
|
+
intersectionObserver: true,
|
|
116
|
+
indexedDb: false
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
delete resolvedConfig.define["process.browser"];
|
|
124
|
+
if (!Array.isArray(resolvedConfig.test.setupFiles)) {
|
|
125
|
+
resolvedConfig.test.setupFiles = [resolvedConfig.test.setupFiles].filter(Boolean);
|
|
126
|
+
}
|
|
127
|
+
const resolver = createResolver(import.meta.url);
|
|
128
|
+
resolvedConfig.test.setupFiles.unshift(resolver.resolve("./runtime/entry"));
|
|
129
|
+
return resolvedConfig;
|
|
130
|
+
}
|
|
131
|
+
function defineVitestConfig(config = {}) {
|
|
132
|
+
return defineConfig(async () => {
|
|
133
|
+
if (process.env.__NUXT_VITEST_RESOLVED__)
|
|
134
|
+
return config;
|
|
135
|
+
const overrides = config.test?.environmentOptions?.nuxt?.overrides || {};
|
|
136
|
+
overrides.rootDir = config.test?.environmentOptions?.nuxt?.rootDir;
|
|
137
|
+
return defu(
|
|
138
|
+
config,
|
|
139
|
+
await getVitestConfigFromNuxt(void 0, overrides)
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { defineVitestConfig, getVitestConfigFromNuxt };
|
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.ddf5bsCK.mjs';
|
|
4
4
|
import 'execa';
|
|
5
5
|
import 'get-port-please';
|
|
6
6
|
import 'ofetch';
|
package/dist/index.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.ddf5bsCK.mjs';
|
|
2
|
+
export { $ as $fetch, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv } from './shared/test-utils-nightly.ddf5bsCK.mjs';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
4
|
import { promises, existsSync } from 'node:fs';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
@@ -15,7 +15,10 @@ async function createBrowser() {
|
|
|
15
15
|
const ctx = useTestContext();
|
|
16
16
|
let playwright;
|
|
17
17
|
try {
|
|
18
|
-
playwright = await import(
|
|
18
|
+
playwright = await import(
|
|
19
|
+
/* vite-ignore */
|
|
20
|
+
'playwright-core'
|
|
21
|
+
);
|
|
19
22
|
} catch {
|
|
20
23
|
throw new Error(`
|
|
21
24
|
The dependency 'playwright-core' not found.
|
|
@@ -80,7 +83,7 @@ async function loadFixture() {
|
|
|
80
83
|
ctx.options.rootDir = resolveRootDir();
|
|
81
84
|
if (!ctx.options.dev) {
|
|
82
85
|
const randomId = Math.random().toString(36).slice(2, 8);
|
|
83
|
-
const buildDir = resolve(ctx.options.rootDir, ".nuxt", randomId);
|
|
86
|
+
const buildDir = ctx.options.buildDir || resolve(ctx.options.rootDir, ".nuxt", randomId);
|
|
84
87
|
ctx.options.nuxtConfig = defu(ctx.options.nuxtConfig, {
|
|
85
88
|
buildDir,
|
|
86
89
|
nitro: {
|
|
@@ -218,6 +221,7 @@ async function runTests(opts) {
|
|
|
218
221
|
inline: [
|
|
219
222
|
distDir,
|
|
220
223
|
"@nuxt/test-utils",
|
|
224
|
+
"@nuxt/test-utils-nightly",
|
|
221
225
|
"@nuxt/test-utils-edge"
|
|
222
226
|
]
|
|
223
227
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { UserConfig } from 'vitest';
|
|
3
|
+
|
|
4
|
+
interface NuxtVitestOptions {
|
|
5
|
+
startOnBoot?: boolean;
|
|
6
|
+
logToConsole?: boolean;
|
|
7
|
+
vitestConfig?: UserConfig;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions>;
|
|
10
|
+
|
|
11
|
+
export { type NuxtVitestOptions, _default as default };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { UserConfig } from 'vitest';
|
|
3
|
+
|
|
4
|
+
interface NuxtVitestOptions {
|
|
5
|
+
startOnBoot?: boolean;
|
|
6
|
+
logToConsole?: boolean;
|
|
7
|
+
vitestConfig?: UserConfig;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: _nuxt_schema.NuxtModule<NuxtVitestOptions>;
|
|
10
|
+
|
|
11
|
+
export { type NuxtVitestOptions, _default as default };
|