@nuxt/test-utils 3.19.2 → 3.21.0
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 +3 -3
- package/dist/config.mjs +13 -39
- package/dist/e2e.d.mts +2 -2
- package/dist/e2e.mjs +8 -4
- package/dist/experimental.mjs +1 -1
- package/dist/module.mjs +25 -15
- package/dist/playwright.d.mts +1 -1
- package/dist/playwright.mjs +7 -3
- package/dist/runtime/global-setup.mjs +3 -4
- package/dist/runtime/shared/environment.mjs +34 -12
- package/dist/runtime-utils/index.d.mts +48 -12
- package/dist/runtime-utils/index.mjs +163 -155
- package/dist/shared/{test-utils.DtJCg4f3.d.mts → test-utils.20kU0tZa.d.mts} +11 -11
- package/dist/shared/{test-utils.CT3RJOY3.mjs → test-utils.3NR-so9-.mjs} +10 -9
- package/dist/shared/{test-utils.B8qEdk9k.mjs → test-utils.CtwoJP76.mjs} +1 -1
- package/dist/shared/test-utils.G1ew4kEe.mjs +67 -0
- package/dist/vitest-environment.mjs +54 -22
- package/package.json +54 -61
package/dist/config.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ interface NuxtEnvironmentOptions {
|
|
|
24
24
|
rootDir?: string;
|
|
25
25
|
/**
|
|
26
26
|
* The starting URL for your Nuxt window environment
|
|
27
|
-
* @default
|
|
27
|
+
* @default 'http://localhost:3000'
|
|
28
28
|
*/
|
|
29
29
|
url?: string;
|
|
30
30
|
/**
|
|
@@ -37,14 +37,14 @@ interface NuxtEnvironmentOptions {
|
|
|
37
37
|
overrides?: NuxtConfig;
|
|
38
38
|
/**
|
|
39
39
|
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
|
40
|
-
* @default
|
|
40
|
+
* @default 'nuxt-test'
|
|
41
41
|
*/
|
|
42
42
|
rootId?: string;
|
|
43
43
|
/**
|
|
44
44
|
* The name of the DOM environment to use.
|
|
45
45
|
*
|
|
46
46
|
* It also needs to be installed as a dev dependency in your project.
|
|
47
|
-
* @default
|
|
47
|
+
* @default 'happy-dom'
|
|
48
48
|
*/
|
|
49
49
|
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
50
50
|
mock?: {
|
package/dist/config.mjs
CHANGED
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
import process
|
|
1
|
+
import process from 'node:process';
|
|
2
2
|
import { defineConfig } from 'vite';
|
|
3
3
|
import { setupDotenv } from 'c12';
|
|
4
4
|
import { defu } from 'defu';
|
|
5
|
-
import { createResolver, findPath
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import { createResolver, findPath } from '@nuxt/kit';
|
|
6
|
+
import { a as applyEnv, l as loadKit } from './shared/test-utils.G1ew4kEe.mjs';
|
|
7
|
+
import 'destr';
|
|
8
|
+
import 'scule';
|
|
9
|
+
import 'node:url';
|
|
10
|
+
import 'exsolve';
|
|
8
11
|
|
|
9
|
-
function
|
|
10
|
-
const
|
|
11
|
-
const envKey = snakeCase(key).toUpperCase();
|
|
12
|
-
return destr(
|
|
13
|
-
env[opts.prefix + envKey] ?? env[opts.altPrefix + envKey]
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
function _isObject(input) {
|
|
17
|
-
return typeof input === "object" && !Array.isArray(input);
|
|
18
|
-
}
|
|
19
|
-
function applyEnv(obj, opts, parentKey = "") {
|
|
20
|
-
for (const key in obj) {
|
|
21
|
-
const subKey = parentKey ? `${parentKey}_${key}` : key;
|
|
22
|
-
const envValue = getEnv(subKey, opts);
|
|
23
|
-
if (_isObject(obj[key])) {
|
|
24
|
-
if (_isObject(envValue)) {
|
|
25
|
-
obj[key] = { ...obj[key], ...envValue };
|
|
26
|
-
applyEnv(obj[key], opts, subKey);
|
|
27
|
-
} else if (envValue === void 0) {
|
|
28
|
-
applyEnv(obj[key], opts, subKey);
|
|
29
|
-
} else {
|
|
30
|
-
obj[key] = envValue ?? obj[key];
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
obj[key] = envValue ?? obj[key];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return obj;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function startNuxtAndGetViteConfig(rootDir = process$1.cwd(), options = {}) {
|
|
12
|
+
async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {}) {
|
|
13
|
+
const { buildNuxt, loadNuxt } = await loadKit(rootDir);
|
|
40
14
|
const nuxt = await loadNuxt({
|
|
41
15
|
cwd: rootDir,
|
|
42
16
|
dev: false,
|
|
@@ -89,7 +63,7 @@ const excludedPlugins = [
|
|
|
89
63
|
"vite-plugin-vue-tracer"
|
|
90
64
|
];
|
|
91
65
|
async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
|
|
92
|
-
const { rootDir = process
|
|
66
|
+
const { rootDir = process.cwd(), ..._overrides } = loadNuxtOptions.overrides || {};
|
|
93
67
|
if (!options) {
|
|
94
68
|
options = await startNuxtAndGetViteConfig(rootDir, {
|
|
95
69
|
dotenv: loadNuxtOptions.dotenv,
|
|
@@ -117,7 +91,7 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
|
|
|
117
91
|
noDiscovery: true
|
|
118
92
|
},
|
|
119
93
|
test: {
|
|
120
|
-
dir: process
|
|
94
|
+
dir: process.cwd(),
|
|
121
95
|
environmentOptions: {
|
|
122
96
|
nuxtRuntimeConfig: applyEnv(structuredClone(options.nuxt.options.runtimeConfig), {
|
|
123
97
|
prefix: "NUXT_",
|
|
@@ -214,14 +188,14 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
|
|
|
214
188
|
return resolvedConfig;
|
|
215
189
|
}
|
|
216
190
|
async function defineVitestProject(config) {
|
|
217
|
-
if (process
|
|
191
|
+
if (process.env.__NUXT_VITEST_RESOLVED__) return config;
|
|
218
192
|
const resolvedConfig = await resolveConfig(config);
|
|
219
193
|
resolvedConfig.test.environment = "nuxt";
|
|
220
194
|
return resolvedConfig;
|
|
221
195
|
}
|
|
222
196
|
function defineVitestConfig(config = {}) {
|
|
223
197
|
return defineConfig(async () => {
|
|
224
|
-
if (process
|
|
198
|
+
if (process.env.__NUXT_VITEST_RESOLVED__) return config;
|
|
225
199
|
const resolvedConfig = await resolveConfig(config);
|
|
226
200
|
if (resolvedConfig.test.browser?.enabled) {
|
|
227
201
|
return resolvedConfig;
|
package/dist/e2e.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.
|
|
2
|
-
export { $ as $fetch, G as GotoOptions, N as NuxtPage, S as StartServerOptions, h as TestRunner, c as createBrowser, d as createPage, f as fetch, g as getBrowser, s as startServer, e as stopServer, u as url, w as waitForHydration } from './shared/test-utils.
|
|
1
|
+
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.20kU0tZa.mjs';
|
|
2
|
+
export { $ as $fetch, G as GotoOptions, N as NuxtPage, S as StartServerOptions, h as TestRunner, c as createBrowser, d as createPage, f as fetch, g as getBrowser, s as startServer, e as stopServer, u as url, w as waitForHydration } from './shared/test-utils.20kU0tZa.mjs';
|
|
3
3
|
import { LogType } from 'consola';
|
|
4
4
|
import 'playwright-core';
|
|
5
5
|
import '@nuxt/schema';
|
package/dist/e2e.mjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
export { b as buildFixture, c as createBrowser, a as createPage, d as createTest, g as getBrowser, l as loadFixture, e as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.
|
|
2
|
-
import { u as useTestContext } from './shared/test-utils.
|
|
3
|
-
export { $ as $fetch, c as createTestContext, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv, s as setTestContext, a as startServer, b as stopServer, d as url } from './shared/test-utils.
|
|
1
|
+
export { b as buildFixture, c as createBrowser, a as createPage, d as createTest, g as getBrowser, l as loadFixture, e as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.3NR-so9-.mjs';
|
|
2
|
+
import { u as useTestContext } from './shared/test-utils.CtwoJP76.mjs';
|
|
3
|
+
export { $ as $fetch, c as createTestContext, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv, s as setTestContext, a as startServer, b as stopServer, d as url } from './shared/test-utils.CtwoJP76.mjs';
|
|
4
4
|
import { consola } from 'consola';
|
|
5
5
|
import { resolve } from 'pathe';
|
|
6
6
|
import { distDir } from '#dirs';
|
|
7
7
|
import 'node:fs';
|
|
8
8
|
import 'node:path';
|
|
9
9
|
import 'defu';
|
|
10
|
-
import '
|
|
10
|
+
import './shared/test-utils.G1ew4kEe.mjs';
|
|
11
|
+
import 'destr';
|
|
12
|
+
import 'scule';
|
|
13
|
+
import 'node:url';
|
|
14
|
+
import 'exsolve';
|
|
11
15
|
import 'tinyexec';
|
|
12
16
|
import 'get-port-please';
|
|
13
17
|
import 'ofetch';
|
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.
|
|
3
|
+
import { $ as $fetch, u as useTestContext } from './shared/test-utils.CtwoJP76.mjs';
|
|
4
4
|
import 'tinyexec';
|
|
5
5
|
import 'get-port-please';
|
|
6
6
|
import 'ofetch';
|
package/dist/module.mjs
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
|
-
import {
|
|
2
|
+
import { resolveIgnorePatterns, defineNuxtModule, createResolver, resolvePath, importModule, logger } from '@nuxt/kit';
|
|
3
3
|
import { getPort } from 'get-port-please';
|
|
4
4
|
import { h } from 'vue';
|
|
5
5
|
import { debounce } from 'perfect-debounce';
|
|
6
6
|
import { isCI } from 'std-env';
|
|
7
7
|
import { defu } from 'defu';
|
|
8
|
+
import { extname, join, dirname, relative } from 'pathe';
|
|
8
9
|
import { getVitestConfigFromNuxt } from './config.mjs';
|
|
9
10
|
import { walk } from 'estree-walker';
|
|
10
11
|
import MagicString from 'magic-string';
|
|
11
12
|
import { createUnplugin } from 'unplugin';
|
|
13
|
+
import { l as loadKit } from './shared/test-utils.G1ew4kEe.mjs';
|
|
12
14
|
import { readFileSync } from 'node:fs';
|
|
13
|
-
import { extname, join, dirname } from 'pathe';
|
|
14
15
|
import 'node:process';
|
|
15
16
|
import 'vite';
|
|
16
17
|
import 'c12';
|
|
17
18
|
import 'destr';
|
|
18
19
|
import 'scule';
|
|
20
|
+
import 'exsolve';
|
|
19
21
|
|
|
20
22
|
const PLUGIN_NAME$1 = "nuxt:vitest:mock-transform";
|
|
21
23
|
const HELPER_MOCK_IMPORT = "mockNuxtImport";
|
|
@@ -67,16 +69,16 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
|
67
69
|
startOf(node)
|
|
68
70
|
);
|
|
69
71
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
+
const importTarget = node.arguments[0];
|
|
73
|
+
const name = isLiteral(importTarget) ? importTarget.value : isIdentifier(importTarget) ? importTarget.name : void 0;
|
|
74
|
+
if (typeof name !== "string") {
|
|
72
75
|
return this.error(
|
|
73
76
|
new Error(
|
|
74
|
-
`The first argument of ${HELPER_MOCK_IMPORT}() must be a string literal`
|
|
77
|
+
`The first argument of ${HELPER_MOCK_IMPORT}() must be a string literal or mocked target`
|
|
75
78
|
),
|
|
76
|
-
startOf(
|
|
79
|
+
startOf(importTarget)
|
|
77
80
|
);
|
|
78
81
|
}
|
|
79
|
-
const name = importName.value;
|
|
80
82
|
const importItem = ctx.imports.find((_) => name === (_.as || _.name));
|
|
81
83
|
if (!importItem) {
|
|
82
84
|
console.log({ imports: ctx.imports });
|
|
@@ -262,8 +264,8 @@ function endOf(node) {
|
|
|
262
264
|
return "range" in node && node.range ? node.range[1] : "end" in node ? node.end : void 0;
|
|
263
265
|
}
|
|
264
266
|
|
|
265
|
-
function setupImportMocking() {
|
|
266
|
-
const
|
|
267
|
+
async function setupImportMocking(nuxt) {
|
|
268
|
+
const { addVitePlugin } = await loadKit(nuxt.options.rootDir);
|
|
267
269
|
const ctx = {
|
|
268
270
|
components: [],
|
|
269
271
|
imports: []
|
|
@@ -279,7 +281,7 @@ function setupImportMocking() {
|
|
|
279
281
|
ctx.components = _;
|
|
280
282
|
});
|
|
281
283
|
nuxt.hook("imports:sources", (presets) => {
|
|
282
|
-
const idx = presets.findIndex((p) => p.imports
|
|
284
|
+
const idx = presets.findIndex((p) => p.imports?.includes("setInterval"));
|
|
283
285
|
if (idx !== -1) {
|
|
284
286
|
presets.splice(idx, 1);
|
|
285
287
|
}
|
|
@@ -317,7 +319,7 @@ const NuxtRootStubPlugin = createUnplugin((options) => {
|
|
|
317
319
|
});
|
|
318
320
|
|
|
319
321
|
const vitePluginBlocklist = ["vite-plugin-vue-inspector", "vite-plugin-vue-inspector:post", "vite-plugin-inspect", "nuxt:type-check"];
|
|
320
|
-
const module = defineNuxtModule({
|
|
322
|
+
const module$1 = defineNuxtModule({
|
|
321
323
|
meta: {
|
|
322
324
|
name: "@nuxt/test-utils",
|
|
323
325
|
configKey: "testUtils"
|
|
@@ -328,8 +330,9 @@ const module = defineNuxtModule({
|
|
|
328
330
|
},
|
|
329
331
|
async setup(options, nuxt) {
|
|
330
332
|
if (nuxt.options.test || nuxt.options.dev) {
|
|
331
|
-
setupImportMocking();
|
|
333
|
+
await setupImportMocking(nuxt);
|
|
332
334
|
}
|
|
335
|
+
const { addVitePlugin } = await loadKit(nuxt.options.rootDir);
|
|
333
336
|
const resolver = createResolver(import.meta.url);
|
|
334
337
|
addVitePlugin(NuxtRootStubPlugin.vite({
|
|
335
338
|
entry: await resolvePath("#app/entry", { alias: nuxt.options.alias }),
|
|
@@ -339,8 +342,15 @@ const module = defineNuxtModule({
|
|
|
339
342
|
nuxt.options.vite.define ||= {};
|
|
340
343
|
nuxt.options.vite.define["import.meta.vitest"] = "undefined";
|
|
341
344
|
}
|
|
342
|
-
nuxt.hook("prepare:types", (
|
|
343
|
-
references.push({ types: "vitest/import-meta" });
|
|
345
|
+
nuxt.hook("prepare:types", (ctx2) => {
|
|
346
|
+
ctx2.references.push({ types: "vitest/import-meta" });
|
|
347
|
+
if (ctx2.nodeTsConfig) {
|
|
348
|
+
ctx2.nodeTsConfig.include ||= [];
|
|
349
|
+
ctx2.nodeTsConfig.include.push(relative(nuxt.options.buildDir, join(nuxt.options.rootDir, "vitest.config.*")));
|
|
350
|
+
if (nuxt.options.workspaceDir !== nuxt.options.rootDir) {
|
|
351
|
+
ctx2.nodeTsConfig.include.push(relative(nuxt.options.buildDir, join(nuxt.options.workspaceDir, "vitest.config.*")));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
344
354
|
});
|
|
345
355
|
if (!nuxt.options.dev) return;
|
|
346
356
|
if (process.env.TEST || process.env.VITE_TEST) return;
|
|
@@ -461,4 +471,4 @@ function toArray(value) {
|
|
|
461
471
|
return Array.isArray(value) ? value : [value];
|
|
462
472
|
}
|
|
463
473
|
|
|
464
|
-
export { module as default };
|
|
474
|
+
export { module$1 as default };
|
package/dist/playwright.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _playwright_test from '@playwright/test';
|
|
2
2
|
export { expect } from '@playwright/test';
|
|
3
3
|
import { Response } from 'playwright-core';
|
|
4
|
-
import { T as TestOptions$1, G as GotoOptions, b as TestHooks } from './shared/test-utils.
|
|
4
|
+
import { T as TestOptions$1, G as GotoOptions, b as TestHooks } from './shared/test-utils.20kU0tZa.mjs';
|
|
5
5
|
import '@nuxt/schema';
|
|
6
6
|
import 'tinyexec';
|
|
7
7
|
|
package/dist/playwright.mjs
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import defu from 'defu';
|
|
2
2
|
import { test as test$1 } from '@playwright/test';
|
|
3
3
|
export { expect } from '@playwright/test';
|
|
4
|
-
import { w as waitForHydration, d as createTest } from './shared/test-utils.
|
|
4
|
+
import { w as waitForHydration, d as createTest } from './shared/test-utils.3NR-so9-.mjs';
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'ufo';
|
|
7
7
|
import 'std-env';
|
|
8
8
|
import 'consola';
|
|
9
9
|
import 'node:fs';
|
|
10
|
-
import '
|
|
11
|
-
import
|
|
10
|
+
import 'destr';
|
|
11
|
+
import 'scule';
|
|
12
|
+
import 'node:url';
|
|
13
|
+
import 'exsolve';
|
|
14
|
+
import { d as url } from './shared/test-utils.CtwoJP76.mjs';
|
|
12
15
|
import 'pathe';
|
|
13
16
|
import '#dirs';
|
|
17
|
+
import './shared/test-utils.G1ew4kEe.mjs';
|
|
14
18
|
import 'tinyexec';
|
|
15
19
|
import 'get-port-please';
|
|
16
20
|
import 'ofetch';
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { consola } from "consola";
|
|
2
2
|
import { createTest, exposeContextToEnv } from "@nuxt/test-utils/e2e";
|
|
3
|
-
const kit = _kit.default || _kit;
|
|
4
3
|
const options = JSON.parse(process.env.NUXT_TEST_OPTIONS || "{}");
|
|
5
4
|
const hooks = createTest(options);
|
|
6
5
|
export const setup = async () => {
|
|
7
|
-
|
|
6
|
+
consola.info("Building Nuxt app...");
|
|
8
7
|
await hooks.beforeAll();
|
|
9
8
|
exposeContextToEnv();
|
|
10
|
-
|
|
9
|
+
consola.info("Running tests...");
|
|
11
10
|
};
|
|
12
11
|
export const teardown = async () => {
|
|
13
12
|
await hooks.afterAll();
|
|
@@ -36,24 +36,46 @@ export async function setupWindow(win, environmentOptions) {
|
|
|
36
36
|
app.id = rootId;
|
|
37
37
|
win.document.body.appendChild(app);
|
|
38
38
|
const h3App = createApp();
|
|
39
|
-
if (!win.fetch) {
|
|
39
|
+
if (!win.fetch || !("Request" in win)) {
|
|
40
40
|
await import("node-fetch-native/polyfill");
|
|
41
41
|
win.URLSearchParams = globalThis.URLSearchParams;
|
|
42
|
+
win.Request ??= class Request extends globalThis.Request {
|
|
43
|
+
constructor(input, init) {
|
|
44
|
+
if (typeof input === "string") {
|
|
45
|
+
super(new URL(input, win.location.origin), init);
|
|
46
|
+
} else {
|
|
47
|
+
super(input, init);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
42
51
|
}
|
|
43
52
|
const nodeHandler = toNodeListener(h3App);
|
|
44
53
|
const registry = /* @__PURE__ */ new Set();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
const _fetch = fetch;
|
|
55
|
+
win.fetch = async (input, _init) => {
|
|
56
|
+
let url;
|
|
57
|
+
let init = _init;
|
|
58
|
+
if (typeof input === "string") {
|
|
59
|
+
url = input;
|
|
60
|
+
} else if (input instanceof URL) {
|
|
61
|
+
url = input.toString();
|
|
62
|
+
} else {
|
|
63
|
+
url = input.url;
|
|
64
|
+
init = {
|
|
65
|
+
method: init?.method ?? input.method,
|
|
66
|
+
body: init?.body ?? input.body,
|
|
67
|
+
headers: init?.headers ?? input.headers
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const base = url.split("?")[0];
|
|
71
|
+
if (registry.has(base) || registry.has(url)) {
|
|
72
|
+
url = "/_" + url;
|
|
73
|
+
}
|
|
74
|
+
if (url.startsWith("/")) {
|
|
75
|
+
const response = await fetchNodeRequestHandler(nodeHandler, url, init);
|
|
76
|
+
return normalizeFetchResponse(response);
|
|
55
77
|
}
|
|
56
|
-
return
|
|
78
|
+
return _fetch(input, _init);
|
|
57
79
|
};
|
|
58
80
|
win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers });
|
|
59
81
|
win.__registry = registry;
|
|
@@ -2,18 +2,41 @@ import { EventHandler, HTTPMethod } from 'h3';
|
|
|
2
2
|
import { SetupContext, RenderFunction, ComputedOptions, MethodOptions, ComponentOptionsMixin, EmitsOptions, ComponentInjectOptions, ComponentOptionsWithoutProps, ComponentOptionsWithArrayProps, ComponentPropsOptions, ComponentOptionsWithObjectProps } from 'vue';
|
|
3
3
|
import { ComponentMountingOptions, mount } from '@vue/test-utils';
|
|
4
4
|
import { RouteLocationRaw } from 'vue-router';
|
|
5
|
-
import
|
|
6
|
-
import { RenderOptions as RenderOptions$1 } from '@testing-library/vue';
|
|
5
|
+
import { RenderOptions, RenderResult } from '@testing-library/vue';
|
|
7
6
|
|
|
8
7
|
type Awaitable<T> = T | Promise<T>;
|
|
9
8
|
type OptionalFunction<T> = T | (() => Awaitable<T>);
|
|
9
|
+
/**
|
|
10
|
+
* `registerEndpoint` allows you create Nitro endpoint that returns mocked data. It can come in handy if you want to test a component that makes requests to API to display some data.
|
|
11
|
+
* @param url - endpoint name (e.g. `/test/`).
|
|
12
|
+
* @param options - factory function that returns the mocked data or an object containing the `handler`, `method`, and `once` properties.
|
|
13
|
+
* - `handler`: the event handler function
|
|
14
|
+
* - `method`: (optional) HTTP method to match (e.g., 'GET', 'POST')
|
|
15
|
+
* - `once`: (optional) if true, the handler will only be used for the first matching request and then automatically removed
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { registerEndpoint } from '@nuxt/test-utils/runtime'
|
|
19
|
+
*
|
|
20
|
+
* registerEndpoint("/test/", () => ({
|
|
21
|
+
* test: "test-field"
|
|
22
|
+
* }))
|
|
23
|
+
*
|
|
24
|
+
* // With once option
|
|
25
|
+
* registerEndpoint("/api/user", {
|
|
26
|
+
* handler: () => ({ name: "Alice" }),
|
|
27
|
+
* once: true
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
* @see https://nuxt.com/docs/getting-started/testing#registerendpoint
|
|
31
|
+
*/
|
|
10
32
|
declare function registerEndpoint(url: string, options: EventHandler | {
|
|
11
33
|
handler: EventHandler;
|
|
12
|
-
method
|
|
34
|
+
method?: HTTPMethod;
|
|
35
|
+
once?: boolean;
|
|
13
36
|
}): () => void;
|
|
14
37
|
/**
|
|
15
38
|
* `mockNuxtImport` allows you to mock Nuxt's auto import functionality.
|
|
16
|
-
* @param
|
|
39
|
+
* @param _target - name of an import to mock or mocked target.
|
|
17
40
|
* @param _factory - factory function that returns mocked import.
|
|
18
41
|
* @example
|
|
19
42
|
* ```ts
|
|
@@ -24,10 +47,17 @@ declare function registerEndpoint(url: string, options: EventHandler | {
|
|
|
24
47
|
* return { value: 'mocked storage' }
|
|
25
48
|
* }
|
|
26
49
|
* })
|
|
50
|
+
*
|
|
51
|
+
* // With mocked target
|
|
52
|
+
* mockNuxtImport(useStorage, () => {
|
|
53
|
+
* return () => {
|
|
54
|
+
* return { value: 'mocked storage' }
|
|
55
|
+
* }
|
|
56
|
+
* })
|
|
27
57
|
* ```
|
|
28
58
|
* @see https://nuxt.com/docs/getting-started/testing#mocknuxtimport
|
|
29
59
|
*/
|
|
30
|
-
declare function mockNuxtImport<T = unknown>(
|
|
60
|
+
declare function mockNuxtImport<T = unknown>(_target: string | T, _factory: () => T | Promise<T>): void;
|
|
31
61
|
/**
|
|
32
62
|
* `mockComponent` allows you to mock Nuxt's component.
|
|
33
63
|
* @param path - component name in PascalCase, or the relative path of the component.
|
|
@@ -67,6 +97,10 @@ declare function mockComponent<PropsOptions extends Readonly<ComponentPropsOptio
|
|
|
67
97
|
|
|
68
98
|
type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
|
|
69
99
|
route?: RouteLocationRaw;
|
|
100
|
+
scoped?: boolean;
|
|
101
|
+
};
|
|
102
|
+
type MountSuspendedResult<T> = ReturnType<typeof mount<T>> & {
|
|
103
|
+
setupState: SetupState$1;
|
|
70
104
|
};
|
|
71
105
|
type SetupState$1 = Record<string, any>;
|
|
72
106
|
/**
|
|
@@ -95,13 +129,17 @@ type SetupState$1 = Record<string, any>;
|
|
|
95
129
|
* @param component the component to be tested
|
|
96
130
|
* @param options optional options to set up your component
|
|
97
131
|
*/
|
|
98
|
-
declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<
|
|
99
|
-
|
|
100
|
-
|
|
132
|
+
declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<MountSuspendedResult<T>>;
|
|
133
|
+
declare global {
|
|
134
|
+
var __cleanup: Array<() => void> | undefined;
|
|
135
|
+
}
|
|
101
136
|
|
|
102
|
-
type
|
|
137
|
+
type RenderSuspendeOptions<T> = RenderOptions<T> & {
|
|
103
138
|
route?: RouteLocationRaw;
|
|
104
139
|
};
|
|
140
|
+
type RenderSuspendeResult = RenderResult & {
|
|
141
|
+
setupState: SetupState;
|
|
142
|
+
};
|
|
105
143
|
type SetupState = Record<string, any>;
|
|
106
144
|
/**
|
|
107
145
|
* `renderSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins.
|
|
@@ -133,9 +171,7 @@ type SetupState = Record<string, any>;
|
|
|
133
171
|
* @param component the component to be tested
|
|
134
172
|
* @param options optional options to set up your component
|
|
135
173
|
*/
|
|
136
|
-
declare function renderSuspended<T>(component: T, options?:
|
|
137
|
-
setupState: SetupState;
|
|
138
|
-
}>;
|
|
174
|
+
declare function renderSuspended<T>(component: T, options?: RenderSuspendeOptions<T>): Promise<RenderSuspendeResult>;
|
|
139
175
|
declare global {
|
|
140
176
|
interface Window {
|
|
141
177
|
__cleanup?: Array<() => void>;
|