@nuxt/test-utils 3.13.1 → 3.14.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/dist/config.d.mts +38 -32
- package/dist/config.d.ts +38 -32
- package/dist/config.mjs +4 -0
- package/dist/e2e.d.mts +3 -13
- package/dist/e2e.d.ts +3 -13
- package/dist/e2e.mjs +5 -4
- package/dist/experimental.mjs +1 -1
- package/dist/module.mjs +2 -2
- package/dist/playwright.d.mts +1 -1
- package/dist/playwright.d.ts +1 -1
- package/dist/playwright.mjs +3 -2
- package/dist/runtime-utils/index.d.mts +6 -3
- package/dist/runtime-utils/index.d.ts +6 -3
- package/dist/runtime-utils/index.mjs +41 -8
- package/dist/shared/{test-utils.C7cWLW4C.mjs → test-utils.BZS9cHDP.mjs} +18 -16
- package/dist/shared/{test-utils.D8NWZeqn.mjs → test-utils.BumFEtZ8.mjs} +17 -6
- package/dist/shared/test-utils.CyoO8zI7.d.mts +109 -0
- package/dist/shared/test-utils.CyoO8zI7.d.ts +109 -0
- package/package.json +43 -43
- package/dist/shared/test-utils.TBc-WRBw.d.mts +0 -60
- package/dist/shared/test-utils.TBc-WRBw.d.ts +0 -60
package/dist/config.d.mts
CHANGED
|
@@ -18,40 +18,46 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
|
|
|
18
18
|
declare function defineVitestConfig(config?: InlineConfig & {
|
|
19
19
|
test?: InlineConfig$1;
|
|
20
20
|
}): vite.UserConfig & Promise<vite.UserConfig> & (vite.UserConfigFnObject & vite.UserConfigExport);
|
|
21
|
+
interface NuxtEnvironmentOptions {
|
|
22
|
+
rootDir?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The starting URL for your Nuxt window environment
|
|
25
|
+
* @default {http://localhost:3000}
|
|
26
|
+
*/
|
|
27
|
+
url?: string;
|
|
28
|
+
/**
|
|
29
|
+
* You can define how environment options are read when loading the Nuxt configuration.
|
|
30
|
+
*/
|
|
31
|
+
dotenv?: Partial<DotenvOptions>;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration that will override the values in your `nuxt.config` file.
|
|
34
|
+
*/
|
|
35
|
+
overrides?: NuxtConfig;
|
|
36
|
+
/**
|
|
37
|
+
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
|
38
|
+
* @default {nuxt-test}
|
|
39
|
+
*/
|
|
40
|
+
rootId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The name of the DOM environment to use.
|
|
43
|
+
*
|
|
44
|
+
* It also needs to be installed as a dev dependency in your project.
|
|
45
|
+
* @default {happy-dom}
|
|
46
|
+
*/
|
|
47
|
+
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
48
|
+
mock?: {
|
|
49
|
+
intersectionObserver?: boolean;
|
|
50
|
+
indexedDb?: boolean;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
declare module 'vitest/node' {
|
|
54
|
+
interface EnvironmentOptions {
|
|
55
|
+
nuxt?: NuxtEnvironmentOptions;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
21
58
|
declare module 'vitest' {
|
|
22
59
|
interface EnvironmentOptions {
|
|
23
|
-
nuxt?:
|
|
24
|
-
rootDir?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The starting URL for your Nuxt window environment
|
|
27
|
-
* @default {http://localhost:3000}
|
|
28
|
-
*/
|
|
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
|
-
*/
|
|
37
|
-
overrides?: NuxtConfig;
|
|
38
|
-
/**
|
|
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 {nuxt-test}
|
|
41
|
-
*/
|
|
42
|
-
rootId?: string;
|
|
43
|
-
/**
|
|
44
|
-
* The name of the DOM environment to use.
|
|
45
|
-
*
|
|
46
|
-
* It also needs to be installed as a dev dependency in your project.
|
|
47
|
-
* @default {happy-dom}
|
|
48
|
-
*/
|
|
49
|
-
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
50
|
-
mock?: {
|
|
51
|
-
intersectionObserver?: boolean;
|
|
52
|
-
indexedDb?: boolean;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
60
|
+
nuxt?: NuxtEnvironmentOptions;
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
|
package/dist/config.d.ts
CHANGED
|
@@ -18,40 +18,46 @@ declare function getVitestConfigFromNuxt(options?: GetVitestConfigOptions, loadN
|
|
|
18
18
|
declare function defineVitestConfig(config?: InlineConfig & {
|
|
19
19
|
test?: InlineConfig$1;
|
|
20
20
|
}): vite.UserConfig & Promise<vite.UserConfig> & (vite.UserConfigFnObject & vite.UserConfigExport);
|
|
21
|
+
interface NuxtEnvironmentOptions {
|
|
22
|
+
rootDir?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The starting URL for your Nuxt window environment
|
|
25
|
+
* @default {http://localhost:3000}
|
|
26
|
+
*/
|
|
27
|
+
url?: string;
|
|
28
|
+
/**
|
|
29
|
+
* You can define how environment options are read when loading the Nuxt configuration.
|
|
30
|
+
*/
|
|
31
|
+
dotenv?: Partial<DotenvOptions>;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration that will override the values in your `nuxt.config` file.
|
|
34
|
+
*/
|
|
35
|
+
overrides?: NuxtConfig;
|
|
36
|
+
/**
|
|
37
|
+
* The id of the root div to which the app should be mounted. You should also set `app.rootId` to the same value.
|
|
38
|
+
* @default {nuxt-test}
|
|
39
|
+
*/
|
|
40
|
+
rootId?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The name of the DOM environment to use.
|
|
43
|
+
*
|
|
44
|
+
* It also needs to be installed as a dev dependency in your project.
|
|
45
|
+
* @default {happy-dom}
|
|
46
|
+
*/
|
|
47
|
+
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
48
|
+
mock?: {
|
|
49
|
+
intersectionObserver?: boolean;
|
|
50
|
+
indexedDb?: boolean;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
declare module 'vitest/node' {
|
|
54
|
+
interface EnvironmentOptions {
|
|
55
|
+
nuxt?: NuxtEnvironmentOptions;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
21
58
|
declare module 'vitest' {
|
|
22
59
|
interface EnvironmentOptions {
|
|
23
|
-
nuxt?:
|
|
24
|
-
rootDir?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The starting URL for your Nuxt window environment
|
|
27
|
-
* @default {http://localhost:3000}
|
|
28
|
-
*/
|
|
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
|
-
*/
|
|
37
|
-
overrides?: NuxtConfig;
|
|
38
|
-
/**
|
|
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 {nuxt-test}
|
|
41
|
-
*/
|
|
42
|
-
rootId?: string;
|
|
43
|
-
/**
|
|
44
|
-
* The name of the DOM environment to use.
|
|
45
|
-
*
|
|
46
|
-
* It also needs to be installed as a dev dependency in your project.
|
|
47
|
-
* @default {happy-dom}
|
|
48
|
-
*/
|
|
49
|
-
domEnvironment?: 'happy-dom' | 'jsdom';
|
|
50
|
-
mock?: {
|
|
51
|
-
intersectionObserver?: boolean;
|
|
52
|
-
indexedDb?: boolean;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
60
|
+
nuxt?: NuxtEnvironmentOptions;
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
|
package/dist/config.mjs
CHANGED
|
@@ -44,6 +44,10 @@ async function startNuxtAndGetViteConfig(rootDir = process.cwd(), options = {})
|
|
|
44
44
|
cwd: rootDir,
|
|
45
45
|
fileName: ".env.test"
|
|
46
46
|
}),
|
|
47
|
+
defaults: {
|
|
48
|
+
// suppress compatibility date warning for runtime environment tests
|
|
49
|
+
compatibilityDate: "2024-04-03"
|
|
50
|
+
},
|
|
47
51
|
overrides: defu(
|
|
48
52
|
{
|
|
49
53
|
appId: "nuxt-app",
|
package/dist/e2e.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.
|
|
2
|
-
export { G as GotoOptions,
|
|
1
|
+
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.CyoO8zI7.mjs';
|
|
2
|
+
export { $ as $fetch, G as GotoOptions, 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.CyoO8zI7.mjs';
|
|
3
3
|
import { LogType } from 'consola';
|
|
4
|
-
import * as nitropack from 'nitropack';
|
|
5
4
|
import 'playwright-core';
|
|
6
5
|
import '@nuxt/schema';
|
|
7
6
|
import 'execa';
|
|
@@ -20,15 +19,6 @@ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
|
|
|
20
19
|
declare function loadFixture(): Promise<void>;
|
|
21
20
|
declare function buildFixture(): Promise<void>;
|
|
22
21
|
|
|
23
|
-
interface StartServerOptions {
|
|
24
|
-
env?: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
27
|
-
declare function stopServer(): Promise<void>;
|
|
28
|
-
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
29
|
-
declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
|
|
30
|
-
declare function url(path: string): string;
|
|
31
|
-
|
|
32
22
|
declare function setupCucumber(hooks: TestHooks): Promise<void>;
|
|
33
23
|
|
|
34
24
|
declare function setupJest(hooks: TestHooks): Promise<void>;
|
|
@@ -52,4 +42,4 @@ interface RunTestOptions {
|
|
|
52
42
|
}
|
|
53
43
|
declare function runTests(opts: RunTestOptions): Promise<void>;
|
|
54
44
|
|
|
55
|
-
export {
|
|
45
|
+
export { type RunTestOptions, TestContext, TestHooks, TestOptions, buildFixture, createTest, createTestContext, exposeContextToEnv, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, useTestContext };
|
package/dist/e2e.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.
|
|
2
|
-
export { G as GotoOptions,
|
|
1
|
+
import { T as TestOptions, a as TestContext, b as TestHooks } from './shared/test-utils.CyoO8zI7.js';
|
|
2
|
+
export { $ as $fetch, G as GotoOptions, 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.CyoO8zI7.js';
|
|
3
3
|
import { LogType } from 'consola';
|
|
4
|
-
import * as nitropack from 'nitropack';
|
|
5
4
|
import 'playwright-core';
|
|
6
5
|
import '@nuxt/schema';
|
|
7
6
|
import 'execa';
|
|
@@ -20,15 +19,6 @@ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
|
|
|
20
19
|
declare function loadFixture(): Promise<void>;
|
|
21
20
|
declare function buildFixture(): Promise<void>;
|
|
22
21
|
|
|
23
|
-
interface StartServerOptions {
|
|
24
|
-
env?: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
27
|
-
declare function stopServer(): Promise<void>;
|
|
28
|
-
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
29
|
-
declare const $fetch: nitropack.$Fetch<unknown, nitropack.NitroFetchRequest>;
|
|
30
|
-
declare function url(path: string): string;
|
|
31
|
-
|
|
32
22
|
declare function setupCucumber(hooks: TestHooks): Promise<void>;
|
|
33
23
|
|
|
34
24
|
declare function setupJest(hooks: TestHooks): Promise<void>;
|
|
@@ -52,4 +42,4 @@ interface RunTestOptions {
|
|
|
52
42
|
}
|
|
53
43
|
declare function runTests(opts: RunTestOptions): Promise<void>;
|
|
54
44
|
|
|
55
|
-
export {
|
|
45
|
+
export { type RunTestOptions, TestContext, TestHooks, TestOptions, buildFixture, createTest, createTestContext, exposeContextToEnv, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, useTestContext };
|
package/dist/e2e.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { d as distDir } from './shared/test-utils.
|
|
2
|
-
export { b as buildFixture, c as createBrowser, a as createPage, e as createTest, g as getBrowser, l as loadFixture, f as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.
|
|
3
|
-
import { u as useTestContext } from './shared/test-utils.
|
|
4
|
-
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
|
+
import { d as distDir } from './shared/test-utils.BZS9cHDP.mjs';
|
|
2
|
+
export { b as buildFixture, c as createBrowser, a as createPage, e as createTest, g as getBrowser, l as loadFixture, f as setup, s as setupMaps, w as waitForHydration } from './shared/test-utils.BZS9cHDP.mjs';
|
|
3
|
+
import { u as useTestContext } from './shared/test-utils.BumFEtZ8.mjs';
|
|
4
|
+
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.BumFEtZ8.mjs';
|
|
5
5
|
import { consola } from 'consola';
|
|
6
6
|
import { resolve } from 'pathe';
|
|
7
7
|
import 'node:fs';
|
|
@@ -12,6 +12,7 @@ import 'node:url';
|
|
|
12
12
|
import 'execa';
|
|
13
13
|
import 'get-port-please';
|
|
14
14
|
import 'ofetch';
|
|
15
|
+
import 'ufo';
|
|
15
16
|
|
|
16
17
|
function mockFn() {
|
|
17
18
|
const ctx = useTestContext();
|
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.BumFEtZ8.mjs';
|
|
4
4
|
import 'execa';
|
|
5
5
|
import 'get-port-please';
|
|
6
6
|
import 'ofetch';
|
package/dist/module.mjs
CHANGED
|
@@ -35,7 +35,7 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
|
|
|
35
35
|
ecmaVersion: "latest",
|
|
36
36
|
ranges: true
|
|
37
37
|
});
|
|
38
|
-
} catch
|
|
38
|
+
} catch {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
let insertionPoint = 0;
|
|
@@ -316,7 +316,7 @@ const NuxtRootStubPlugin = createUnplugin((options) => {
|
|
|
316
316
|
};
|
|
317
317
|
});
|
|
318
318
|
|
|
319
|
-
const vitePluginBlocklist = ["vite-plugin-vue-inspector", "vite-plugin-vue-inspector:post", "vite-plugin-inspect"];
|
|
319
|
+
const vitePluginBlocklist = ["vite-plugin-vue-inspector", "vite-plugin-vue-inspector:post", "vite-plugin-inspect", "nuxt:type-check"];
|
|
320
320
|
const module = defineNuxtModule({
|
|
321
321
|
meta: {
|
|
322
322
|
name: "@nuxt/test-utils",
|
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, b as TestHooks, G as GotoOptions } from './shared/test-utils.
|
|
4
|
+
import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.CyoO8zI7.mjs';
|
|
5
5
|
import '@nuxt/schema';
|
|
6
6
|
import 'execa';
|
|
7
7
|
|
package/dist/playwright.d.ts
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, b as TestHooks, G as GotoOptions } from './shared/test-utils.
|
|
4
|
+
import { T as TestOptions$1, b as TestHooks, G as GotoOptions } from './shared/test-utils.CyoO8zI7.js';
|
|
5
5
|
import '@nuxt/schema';
|
|
6
6
|
import 'execa';
|
|
7
7
|
|
package/dist/playwright.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { test as test$1 } from '@playwright/test';
|
|
2
2
|
export { expect } from '@playwright/test';
|
|
3
|
-
import { e as createTest, w as waitForHydration } from './shared/test-utils.
|
|
3
|
+
import { e as createTest, w as waitForHydration } from './shared/test-utils.BZS9cHDP.mjs';
|
|
4
4
|
import 'node:path';
|
|
5
5
|
import 'defu';
|
|
6
|
+
import 'ufo';
|
|
6
7
|
import 'consola';
|
|
7
8
|
import 'node:fs';
|
|
8
9
|
import '@nuxt/kit';
|
|
9
|
-
import { d as url } from './shared/test-utils.
|
|
10
|
+
import { d as url } from './shared/test-utils.BumFEtZ8.mjs';
|
|
10
11
|
import 'pathe';
|
|
11
12
|
import 'node:url';
|
|
12
13
|
import 'execa';
|
|
@@ -82,7 +82,7 @@ declare function mockComponent<PropsOptions extends Readonly<ComponentPropsOptio
|
|
|
82
82
|
type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
|
|
83
83
|
route?: RouteLocationRaw;
|
|
84
84
|
};
|
|
85
|
-
type SetupState = Record<string, any>;
|
|
85
|
+
type SetupState$1 = Record<string, any>;
|
|
86
86
|
/**
|
|
87
87
|
* `mountSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins. For example:
|
|
88
88
|
*
|
|
@@ -110,12 +110,13 @@ type SetupState = Record<string, any>;
|
|
|
110
110
|
* @param options optional options to set up your component
|
|
111
111
|
*/
|
|
112
112
|
declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<ReturnType<typeof mount<T>> & {
|
|
113
|
-
setupState: SetupState;
|
|
113
|
+
setupState: SetupState$1;
|
|
114
114
|
}>;
|
|
115
115
|
|
|
116
116
|
type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
117
117
|
route?: RouteLocationRaw;
|
|
118
118
|
};
|
|
119
|
+
type SetupState = Record<string, any>;
|
|
119
120
|
/**
|
|
120
121
|
* `renderSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins.
|
|
121
122
|
*
|
|
@@ -146,7 +147,9 @@ type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
|
146
147
|
* @param component the component to be tested
|
|
147
148
|
* @param options optional options to set up your component
|
|
148
149
|
*/
|
|
149
|
-
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult
|
|
150
|
+
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult & {
|
|
151
|
+
setupState: SetupState;
|
|
152
|
+
}>;
|
|
150
153
|
declare global {
|
|
151
154
|
interface Window {
|
|
152
155
|
__cleanup?: Array<() => void>;
|
|
@@ -82,7 +82,7 @@ declare function mockComponent<PropsOptions extends Readonly<ComponentPropsOptio
|
|
|
82
82
|
type MountSuspendedOptions<T> = ComponentMountingOptions<T> & {
|
|
83
83
|
route?: RouteLocationRaw;
|
|
84
84
|
};
|
|
85
|
-
type SetupState = Record<string, any>;
|
|
85
|
+
type SetupState$1 = Record<string, any>;
|
|
86
86
|
/**
|
|
87
87
|
* `mountSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins. For example:
|
|
88
88
|
*
|
|
@@ -110,12 +110,13 @@ type SetupState = Record<string, any>;
|
|
|
110
110
|
* @param options optional options to set up your component
|
|
111
111
|
*/
|
|
112
112
|
declare function mountSuspended<T>(component: T, options?: MountSuspendedOptions<T>): Promise<ReturnType<typeof mount<T>> & {
|
|
113
|
-
setupState: SetupState;
|
|
113
|
+
setupState: SetupState$1;
|
|
114
114
|
}>;
|
|
115
115
|
|
|
116
116
|
type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
117
117
|
route?: RouteLocationRaw;
|
|
118
118
|
};
|
|
119
|
+
type SetupState = Record<string, any>;
|
|
119
120
|
/**
|
|
120
121
|
* `renderSuspended` allows you to mount any vue component within the Nuxt environment, allowing async setup and access to injections from your Nuxt plugins.
|
|
121
122
|
*
|
|
@@ -146,7 +147,9 @@ type RenderOptions<C = unknown> = RenderOptions$1<C> & {
|
|
|
146
147
|
* @param component the component to be tested
|
|
147
148
|
* @param options optional options to set up your component
|
|
148
149
|
*/
|
|
149
|
-
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult
|
|
150
|
+
declare function renderSuspended<T>(component: T, options?: RenderOptions<T>): Promise<_testing_library_vue.RenderResult & {
|
|
151
|
+
setupState: SetupState;
|
|
152
|
+
}>;
|
|
150
153
|
declare global {
|
|
151
154
|
interface Window {
|
|
152
155
|
__cleanup?: Array<() => void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler } from 'h3';
|
|
2
2
|
import { mount } from '@vue/test-utils';
|
|
3
3
|
import { reactive, h as h$1, Suspense, nextTick, isReadonly, unref, effectScope } from 'vue';
|
|
4
|
-
import { defu } from 'defu';
|
|
4
|
+
import { createDefu, defu } from 'defu';
|
|
5
5
|
import { defineComponent, useRouter, h, tryUseNuxtApp } from '#imports';
|
|
6
6
|
import NuxtRoot from '#build/root-component.mjs';
|
|
7
7
|
|
|
@@ -133,7 +133,7 @@ async function mountSuspended(component, options) {
|
|
|
133
133
|
} : void 0,
|
|
134
134
|
setup: setup ? (props2) => wrappedSetup(props2, setupContext) : void 0
|
|
135
135
|
};
|
|
136
|
-
return () => h$1(clonedComponent, { ...
|
|
136
|
+
return () => h$1(clonedComponent, { ...defuReplaceArray(setProps, props), ...attrs }, slots);
|
|
137
137
|
}
|
|
138
138
|
})
|
|
139
139
|
}
|
|
@@ -161,6 +161,12 @@ async function mountSuspended(component, options) {
|
|
|
161
161
|
}
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
|
+
const defuReplaceArray = createDefu((obj, key, value) => {
|
|
165
|
+
if (Array.isArray(obj[key])) {
|
|
166
|
+
obj[key] = value;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
164
170
|
|
|
165
171
|
const WRAPPER_EL_ID = "test-wrapper";
|
|
166
172
|
async function renderSuspended(component, options) {
|
|
@@ -174,11 +180,21 @@ async function renderSuspended(component, options) {
|
|
|
174
180
|
const { render: renderFromTestingLibrary } = await import('@testing-library/vue');
|
|
175
181
|
const vueApp = tryUseNuxtApp()?.vueApp || globalThis.__unctx__.get("nuxt-app").tryUse().vueApp;
|
|
176
182
|
const { render, setup } = component;
|
|
183
|
+
let setupContext;
|
|
184
|
+
let setupState;
|
|
177
185
|
for (const fn of window.__cleanup || []) {
|
|
178
186
|
fn();
|
|
179
187
|
}
|
|
180
188
|
document.querySelector(`#${WRAPPER_EL_ID}`)?.remove();
|
|
181
|
-
let
|
|
189
|
+
let passedProps;
|
|
190
|
+
const wrappedSetup = async (props2, setupContext2) => {
|
|
191
|
+
passedProps = props2;
|
|
192
|
+
if (setup) {
|
|
193
|
+
const result = await setup(props2, setupContext2);
|
|
194
|
+
setupState = result && typeof result === "object" ? result : {};
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
182
198
|
return new Promise((resolve) => {
|
|
183
199
|
const utils = renderFromTestingLibrary(
|
|
184
200
|
{
|
|
@@ -191,8 +207,7 @@ async function renderSuspended(component, options) {
|
|
|
191
207
|
});
|
|
192
208
|
return scope.run(() => NuxtRoot.setup(props2, {
|
|
193
209
|
...ctx,
|
|
194
|
-
expose: () => {
|
|
195
|
-
}
|
|
210
|
+
expose: () => ({})
|
|
196
211
|
}));
|
|
197
212
|
},
|
|
198
213
|
render: (renderContext) => (
|
|
@@ -204,16 +219,34 @@ async function renderSuspended(component, options) {
|
|
|
204
219
|
{ id: WRAPPER_EL_ID },
|
|
205
220
|
h$1(
|
|
206
221
|
Suspense,
|
|
207
|
-
{
|
|
222
|
+
{
|
|
223
|
+
onResolve: () => nextTick().then(() => {
|
|
224
|
+
utils.setupState = setupState;
|
|
225
|
+
resolve(utils);
|
|
226
|
+
})
|
|
227
|
+
},
|
|
208
228
|
{
|
|
209
229
|
default: () => h$1({
|
|
230
|
+
name: "RenderHelper",
|
|
210
231
|
async setup() {
|
|
211
232
|
const router = useRouter();
|
|
212
233
|
await router.replace(route);
|
|
213
234
|
const clonedComponent = {
|
|
235
|
+
name: "RenderSuspendedComponent",
|
|
214
236
|
...component,
|
|
215
|
-
render: render ? (_ctx, ...args)
|
|
216
|
-
|
|
237
|
+
render: render ? function(_ctx, ...args) {
|
|
238
|
+
for (const key in setupState || {}) {
|
|
239
|
+
renderContext[key] = isReadonly(setupState[key]) ? unref(setupState[key]) : setupState[key];
|
|
240
|
+
}
|
|
241
|
+
for (const key in props || {}) {
|
|
242
|
+
renderContext[key] = _ctx[key];
|
|
243
|
+
}
|
|
244
|
+
for (const key in passedProps || {}) {
|
|
245
|
+
renderContext[key] = passedProps[key];
|
|
246
|
+
}
|
|
247
|
+
return render.call(this, renderContext, ...args);
|
|
248
|
+
} : void 0,
|
|
249
|
+
setup: setup ? (props2) => wrappedSetup(props2, setupContext) : void 0
|
|
217
250
|
};
|
|
218
251
|
return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...attrs }, slots);
|
|
219
252
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { u as useTestContext, d as url, c as createTestContext, s as setTestContext, b as stopServer, a as startServer } from './test-utils.
|
|
1
|
+
import { u as useTestContext, d as url, c as createTestContext, s as setTestContext, b as stopServer, a as startServer } from './test-utils.BumFEtZ8.mjs';
|
|
2
2
|
import { existsSync, promises } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { defu } from 'defu';
|
|
@@ -82,27 +82,29 @@ async function loadFixture() {
|
|
|
82
82
|
ctx.options.rootDir = resolveRootDir();
|
|
83
83
|
if (!ctx.options.dev) {
|
|
84
84
|
const randomId = Math.random().toString(36).slice(2, 8);
|
|
85
|
-
const
|
|
85
|
+
const buildDir = ctx.options.buildDir || resolve(ctx.options.rootDir, ".nuxt", "test", randomId);
|
|
86
86
|
ctx.options.nuxtConfig = defu(ctx.options.nuxtConfig, {
|
|
87
|
-
buildDir
|
|
87
|
+
buildDir,
|
|
88
88
|
nitro: {
|
|
89
89
|
output: {
|
|
90
|
-
dir: resolve(
|
|
90
|
+
dir: resolve(buildDir, "output")
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
ctx.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
if (ctx.options.build) {
|
|
96
|
+
ctx.nuxt = await kit.loadNuxt({
|
|
97
|
+
cwd: ctx.options.rootDir,
|
|
98
|
+
dev: ctx.options.dev,
|
|
99
|
+
overrides: ctx.options.nuxtConfig,
|
|
100
|
+
configFile: ctx.options.configFile
|
|
101
|
+
});
|
|
102
|
+
const buildDir = ctx.nuxt.options.buildDir;
|
|
103
|
+
if (!existsSync(buildDir)) {
|
|
104
|
+
await promises.mkdir(buildDir, { recursive: true });
|
|
105
|
+
ctx.teardown = ctx.teardown || [];
|
|
106
|
+
ctx.teardown.push(() => promises.rm(buildDir, { recursive: true, force: true }));
|
|
107
|
+
}
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
async function buildFixture() {
|
|
@@ -174,7 +176,7 @@ function createTest(options) {
|
|
|
174
176
|
await buildFixture();
|
|
175
177
|
}
|
|
176
178
|
if (ctx.options.server) {
|
|
177
|
-
await startServer();
|
|
179
|
+
await startServer(ctx.options.env);
|
|
178
180
|
}
|
|
179
181
|
if (ctx.options.waitFor) {
|
|
180
182
|
await new Promise((resolve) => setTimeout(resolve, ctx.options.waitFor));
|
|
@@ -3,6 +3,7 @@ import { getRandomPort, waitForPort } from 'get-port-please';
|
|
|
3
3
|
import { fetch as fetch$1, $fetch as $fetch$1 } from 'ofetch';
|
|
4
4
|
import * as _kit from '@nuxt/kit';
|
|
5
5
|
import { resolve as resolve$1 } from 'pathe';
|
|
6
|
+
import { withTrailingSlash, joinURL } from 'ufo';
|
|
6
7
|
import { resolve } from 'node:path';
|
|
7
8
|
import { defu } from 'defu';
|
|
8
9
|
|
|
@@ -17,18 +18,26 @@ function createTestContext(options) {
|
|
|
17
18
|
logLevel: 1,
|
|
18
19
|
server: true,
|
|
19
20
|
build: options.browser !== false || options.server !== false,
|
|
20
|
-
nuxtConfig: {
|
|
21
|
+
nuxtConfig: {
|
|
22
|
+
// suppress compatibility date warning for runtime environment tests
|
|
23
|
+
compatibilityDate: "2024-04-03"
|
|
24
|
+
},
|
|
21
25
|
browserOptions: {
|
|
22
26
|
type: "chromium"
|
|
23
27
|
}
|
|
24
28
|
});
|
|
29
|
+
if (_options.host) {
|
|
30
|
+
_options.build = false;
|
|
31
|
+
_options.server = false;
|
|
32
|
+
}
|
|
25
33
|
if (process.env.VITEST === "true") {
|
|
26
34
|
_options.runner || (_options.runner = "vitest");
|
|
27
35
|
} else if (process.env.JEST_WORKER_ID) {
|
|
28
36
|
_options.runner || (_options.runner = "jest");
|
|
29
37
|
}
|
|
30
38
|
return setTestContext({
|
|
31
|
-
options: _options
|
|
39
|
+
options: _options,
|
|
40
|
+
url: withTrailingSlash(_options.host)
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
43
|
function useTestContext() {
|
|
@@ -62,7 +71,7 @@ async function startServer(options = {}) {
|
|
|
62
71
|
await stopServer();
|
|
63
72
|
const host = "127.0.0.1";
|
|
64
73
|
const port = ctx.options.port || await getRandomPort(host);
|
|
65
|
-
ctx.url = `http://${host}:${port}
|
|
74
|
+
ctx.url = `http://${host}:${port}/`;
|
|
66
75
|
if (ctx.options.dev) {
|
|
67
76
|
const nuxiCLI = await kit.resolvePath("nuxi/cli");
|
|
68
77
|
ctx.serverProcess = execa(nuxiCLI, ["_dev"], {
|
|
@@ -75,7 +84,8 @@ async function startServer(options = {}) {
|
|
|
75
84
|
PORT: String(port),
|
|
76
85
|
HOST: host,
|
|
77
86
|
NODE_ENV: "development",
|
|
78
|
-
...options.env
|
|
87
|
+
...options.env,
|
|
88
|
+
...ctx.options.env
|
|
79
89
|
}
|
|
80
90
|
});
|
|
81
91
|
await waitForPort(port, { retries: 32, host }).catch(() => {
|
|
@@ -104,7 +114,8 @@ async function startServer(options = {}) {
|
|
|
104
114
|
PORT: String(port),
|
|
105
115
|
HOST: host,
|
|
106
116
|
NODE_ENV: "test",
|
|
107
|
-
...options.env
|
|
117
|
+
...options.env,
|
|
118
|
+
...ctx.options.env
|
|
108
119
|
}
|
|
109
120
|
});
|
|
110
121
|
await waitForPort(port, { retries: 20, host });
|
|
@@ -130,7 +141,7 @@ function url(path) {
|
|
|
130
141
|
if (path.startsWith(ctx.url)) {
|
|
131
142
|
return path;
|
|
132
143
|
}
|
|
133
|
-
return ctx.url
|
|
144
|
+
return joinURL(ctx.url, path);
|
|
134
145
|
}
|
|
135
146
|
|
|
136
147
|
export { $fetch as $, startServer as a, stopServer as b, createTestContext as c, url as d, exposeContextToEnv as e, fetch as f, isDev as i, recoverContextFromEnv as r, setTestContext as s, useTestContext as u };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Browser, BrowserContextOptions, Page, Response as Response$1, LaunchOptions } from 'playwright-core';
|
|
2
|
+
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
3
|
+
import { ExecaChildProcess } from 'execa';
|
|
4
|
+
|
|
5
|
+
declare function createBrowser(): Promise<void>;
|
|
6
|
+
declare function getBrowser(): Promise<Browser>;
|
|
7
|
+
type _GotoOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
8
|
+
interface GotoOptions extends Omit<_GotoOptions, 'waitUntil'> {
|
|
9
|
+
waitUntil?: 'hydration' | 'route' | _GotoOptions['waitUntil'];
|
|
10
|
+
}
|
|
11
|
+
interface NuxtPage extends Omit<Page, 'goto'> {
|
|
12
|
+
goto: (url: string, options?: GotoOptions) => Promise<Response$1 | null>;
|
|
13
|
+
}
|
|
14
|
+
declare function createPage(path?: string, options?: BrowserContextOptions): Promise<NuxtPage>;
|
|
15
|
+
declare function waitForHydration(page: Page, url: string, waitUntil?: GotoOptions['waitUntil']): Promise<void>;
|
|
16
|
+
|
|
17
|
+
interface StartServerOptions {
|
|
18
|
+
env?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
21
|
+
declare function stopServer(): Promise<void>;
|
|
22
|
+
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
23
|
+
declare const $fetch: (typeof globalThis)["$fetch"];
|
|
24
|
+
declare function url(path: string): string;
|
|
25
|
+
|
|
26
|
+
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
27
|
+
interface TestOptions {
|
|
28
|
+
testDir: string;
|
|
29
|
+
fixture: string;
|
|
30
|
+
/**
|
|
31
|
+
* Name of the configuration file.
|
|
32
|
+
* @default `'nuxt.config`
|
|
33
|
+
*/
|
|
34
|
+
configFile: string;
|
|
35
|
+
/**
|
|
36
|
+
* Path to a directory with a Nuxt app to be put under test.
|
|
37
|
+
* @default `'.'`
|
|
38
|
+
*/
|
|
39
|
+
rootDir: string;
|
|
40
|
+
buildDir: string;
|
|
41
|
+
nuxtConfig: NuxtConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to run a separate build step.
|
|
44
|
+
* @default `true` (`false` if `browser` or `server` is disabled, or if a `host` is provided)
|
|
45
|
+
*/
|
|
46
|
+
build: boolean;
|
|
47
|
+
dev: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The amount of time (in milliseconds) to allow for `setupTest` to complete its work (which could include building or generating files for a Nuxt application, depending on the options that are passed).
|
|
50
|
+
* @default `60000`
|
|
51
|
+
*/
|
|
52
|
+
setupTimeout: number;
|
|
53
|
+
waitFor: number;
|
|
54
|
+
/**
|
|
55
|
+
* Under the hood, Nuxt test utils uses [`playwright`](https://playwright.dev) to carry out browser testing. If this option is set, a browser will be launched and can be controlled in the subsequent test suite.
|
|
56
|
+
* @default `false`
|
|
57
|
+
*/
|
|
58
|
+
browser: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber'`.
|
|
61
|
+
* @default `vitest`
|
|
62
|
+
*/
|
|
63
|
+
runner: TestRunner;
|
|
64
|
+
logLevel: number;
|
|
65
|
+
browserOptions: {
|
|
66
|
+
/** The type of browser to launch - either `chromium`, `firefox` or `webkit` */
|
|
67
|
+
type: 'chromium' | 'firefox' | 'webkit';
|
|
68
|
+
/** `object` of options that will be passed to playwright when launching the browser. See [full API reference](https://playwright.dev/docs/api/class-browsertype#browser-type-launch). */
|
|
69
|
+
launch?: LaunchOptions;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Whether to launch a server to respond to requests in the test suite.
|
|
73
|
+
* @default `true` (`false` if a `host` is provided)
|
|
74
|
+
*/
|
|
75
|
+
server: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* If provided, a URL to use as the test target instead of building and running a new server. Useful for running "real" end-to-end tests against a deployed version of your application, or against an already running local server.
|
|
78
|
+
* @default `undefined`
|
|
79
|
+
*/
|
|
80
|
+
host?: string;
|
|
81
|
+
/**
|
|
82
|
+
* If provided, set the launched test server port to the value.
|
|
83
|
+
* @default `undefined`
|
|
84
|
+
*/
|
|
85
|
+
port?: number;
|
|
86
|
+
env?: StartServerOptions['env'];
|
|
87
|
+
}
|
|
88
|
+
interface TestContext {
|
|
89
|
+
options: TestOptions;
|
|
90
|
+
nuxt?: Nuxt;
|
|
91
|
+
browser?: Browser;
|
|
92
|
+
url?: string;
|
|
93
|
+
serverProcess?: ExecaChildProcess;
|
|
94
|
+
mockFn?: (...args: unknown[]) => unknown;
|
|
95
|
+
/**
|
|
96
|
+
* Functions to run on the vitest `afterAll` hook.
|
|
97
|
+
* Useful for removing anything created during the test.
|
|
98
|
+
*/
|
|
99
|
+
teardown?: (() => void)[];
|
|
100
|
+
}
|
|
101
|
+
interface TestHooks {
|
|
102
|
+
beforeEach: () => void;
|
|
103
|
+
afterEach: () => void;
|
|
104
|
+
afterAll: () => Promise<void>;
|
|
105
|
+
setup: () => Promise<void>;
|
|
106
|
+
ctx: TestContext;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { $fetch as $, type GotoOptions as G, type StartServerOptions as S, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d, stopServer as e, fetch as f, getBrowser as g, type TestRunner as h, startServer as s, url as u, waitForHydration as w };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Browser, BrowserContextOptions, Page, Response as Response$1, LaunchOptions } from 'playwright-core';
|
|
2
|
+
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
3
|
+
import { ExecaChildProcess } from 'execa';
|
|
4
|
+
|
|
5
|
+
declare function createBrowser(): Promise<void>;
|
|
6
|
+
declare function getBrowser(): Promise<Browser>;
|
|
7
|
+
type _GotoOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
8
|
+
interface GotoOptions extends Omit<_GotoOptions, 'waitUntil'> {
|
|
9
|
+
waitUntil?: 'hydration' | 'route' | _GotoOptions['waitUntil'];
|
|
10
|
+
}
|
|
11
|
+
interface NuxtPage extends Omit<Page, 'goto'> {
|
|
12
|
+
goto: (url: string, options?: GotoOptions) => Promise<Response$1 | null>;
|
|
13
|
+
}
|
|
14
|
+
declare function createPage(path?: string, options?: BrowserContextOptions): Promise<NuxtPage>;
|
|
15
|
+
declare function waitForHydration(page: Page, url: string, waitUntil?: GotoOptions['waitUntil']): Promise<void>;
|
|
16
|
+
|
|
17
|
+
interface StartServerOptions {
|
|
18
|
+
env?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
declare function startServer(options?: StartServerOptions): Promise<void>;
|
|
21
|
+
declare function stopServer(): Promise<void>;
|
|
22
|
+
declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
23
|
+
declare const $fetch: (typeof globalThis)["$fetch"];
|
|
24
|
+
declare function url(path: string): string;
|
|
25
|
+
|
|
26
|
+
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
27
|
+
interface TestOptions {
|
|
28
|
+
testDir: string;
|
|
29
|
+
fixture: string;
|
|
30
|
+
/**
|
|
31
|
+
* Name of the configuration file.
|
|
32
|
+
* @default `'nuxt.config`
|
|
33
|
+
*/
|
|
34
|
+
configFile: string;
|
|
35
|
+
/**
|
|
36
|
+
* Path to a directory with a Nuxt app to be put under test.
|
|
37
|
+
* @default `'.'`
|
|
38
|
+
*/
|
|
39
|
+
rootDir: string;
|
|
40
|
+
buildDir: string;
|
|
41
|
+
nuxtConfig: NuxtConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Whether to run a separate build step.
|
|
44
|
+
* @default `true` (`false` if `browser` or `server` is disabled, or if a `host` is provided)
|
|
45
|
+
*/
|
|
46
|
+
build: boolean;
|
|
47
|
+
dev: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The amount of time (in milliseconds) to allow for `setupTest` to complete its work (which could include building or generating files for a Nuxt application, depending on the options that are passed).
|
|
50
|
+
* @default `60000`
|
|
51
|
+
*/
|
|
52
|
+
setupTimeout: number;
|
|
53
|
+
waitFor: number;
|
|
54
|
+
/**
|
|
55
|
+
* Under the hood, Nuxt test utils uses [`playwright`](https://playwright.dev) to carry out browser testing. If this option is set, a browser will be launched and can be controlled in the subsequent test suite.
|
|
56
|
+
* @default `false`
|
|
57
|
+
*/
|
|
58
|
+
browser: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber'`.
|
|
61
|
+
* @default `vitest`
|
|
62
|
+
*/
|
|
63
|
+
runner: TestRunner;
|
|
64
|
+
logLevel: number;
|
|
65
|
+
browserOptions: {
|
|
66
|
+
/** The type of browser to launch - either `chromium`, `firefox` or `webkit` */
|
|
67
|
+
type: 'chromium' | 'firefox' | 'webkit';
|
|
68
|
+
/** `object` of options that will be passed to playwright when launching the browser. See [full API reference](https://playwright.dev/docs/api/class-browsertype#browser-type-launch). */
|
|
69
|
+
launch?: LaunchOptions;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Whether to launch a server to respond to requests in the test suite.
|
|
73
|
+
* @default `true` (`false` if a `host` is provided)
|
|
74
|
+
*/
|
|
75
|
+
server: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* If provided, a URL to use as the test target instead of building and running a new server. Useful for running "real" end-to-end tests against a deployed version of your application, or against an already running local server.
|
|
78
|
+
* @default `undefined`
|
|
79
|
+
*/
|
|
80
|
+
host?: string;
|
|
81
|
+
/**
|
|
82
|
+
* If provided, set the launched test server port to the value.
|
|
83
|
+
* @default `undefined`
|
|
84
|
+
*/
|
|
85
|
+
port?: number;
|
|
86
|
+
env?: StartServerOptions['env'];
|
|
87
|
+
}
|
|
88
|
+
interface TestContext {
|
|
89
|
+
options: TestOptions;
|
|
90
|
+
nuxt?: Nuxt;
|
|
91
|
+
browser?: Browser;
|
|
92
|
+
url?: string;
|
|
93
|
+
serverProcess?: ExecaChildProcess;
|
|
94
|
+
mockFn?: (...args: unknown[]) => unknown;
|
|
95
|
+
/**
|
|
96
|
+
* Functions to run on the vitest `afterAll` hook.
|
|
97
|
+
* Useful for removing anything created during the test.
|
|
98
|
+
*/
|
|
99
|
+
teardown?: (() => void)[];
|
|
100
|
+
}
|
|
101
|
+
interface TestHooks {
|
|
102
|
+
beforeEach: () => void;
|
|
103
|
+
afterEach: () => void;
|
|
104
|
+
afterAll: () => Promise<void>;
|
|
105
|
+
setup: () => Promise<void>;
|
|
106
|
+
ctx: TestContext;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { $fetch as $, type GotoOptions as G, type StartServerOptions as S, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d, stopServer as e, fetch as f, getBrowser as g, type TestRunner as h, startServer as s, url as u, waitForHydration as w };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/test-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/test-utils.git"
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"release": "pnpm prepack && pnpm test:examples && changelogen --release --push"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@nuxt/kit": "^3.
|
|
44
|
-
"@nuxt/schema": "^3.
|
|
45
|
-
"c12": "^1.
|
|
43
|
+
"@nuxt/kit": "^3.12.4",
|
|
44
|
+
"@nuxt/schema": "^3.12.4",
|
|
45
|
+
"c12": "^1.11.1",
|
|
46
46
|
"consola": "^3.2.3",
|
|
47
47
|
"defu": "^6.1.4",
|
|
48
48
|
"destr": "^2.0.3",
|
|
49
49
|
"estree-walker": "^3.0.3",
|
|
50
50
|
"execa": "^8.0.1",
|
|
51
|
-
"fake-indexeddb": "^
|
|
51
|
+
"fake-indexeddb": "^6.0.0",
|
|
52
52
|
"get-port-please": "^3.1.2",
|
|
53
53
|
"local-pkg": "^0.5.0",
|
|
54
|
-
"magic-string": "^0.30.
|
|
54
|
+
"magic-string": "^0.30.11",
|
|
55
55
|
"node-fetch-native": "^1.6.4",
|
|
56
56
|
"ofetch": "^1.3.4",
|
|
57
57
|
"pathe": "^1.1.2",
|
|
@@ -59,46 +59,48 @@
|
|
|
59
59
|
"radix3": "^1.1.2",
|
|
60
60
|
"scule": "^1.3.0",
|
|
61
61
|
"std-env": "^3.7.0",
|
|
62
|
-
"ufo": "^1.5.
|
|
63
|
-
"unenv": "^1.
|
|
64
|
-
"unplugin": "^1.
|
|
62
|
+
"ufo": "^1.5.4",
|
|
63
|
+
"unenv": "^1.10.0",
|
|
64
|
+
"unplugin": "^1.12.1",
|
|
65
65
|
"vitest-environment-nuxt": "^1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@cucumber/cucumber": "10.
|
|
68
|
+
"@cucumber/cucumber": "10.8.0",
|
|
69
69
|
"@jest/globals": "29.7.0",
|
|
70
70
|
"@nuxt/devtools": "1.0.8",
|
|
71
|
-
"@nuxt/eslint-config": "0.
|
|
72
|
-
"@nuxt/module-builder": "0.
|
|
73
|
-
"@playwright/test": "1.
|
|
71
|
+
"@nuxt/eslint-config": "0.5.0",
|
|
72
|
+
"@nuxt/module-builder": "0.8.2",
|
|
73
|
+
"@playwright/test": "1.46.0",
|
|
74
74
|
"@testing-library/vue": "8.1.0",
|
|
75
75
|
"@types/estree": "1.0.5",
|
|
76
|
-
"@types/jsdom": "21.1.
|
|
76
|
+
"@types/jsdom": "21.1.7",
|
|
77
77
|
"@types/semver": "7.5.8",
|
|
78
|
-
"@vitest/ui": "
|
|
78
|
+
"@vitest/ui": "2.0.5",
|
|
79
79
|
"@vue/test-utils": "2.4.6",
|
|
80
80
|
"changelogen": "0.5.5",
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
81
|
+
"compatx": "0.1.8",
|
|
82
|
+
"eslint": "9.9.0",
|
|
83
|
+
"h3": "1.12.0",
|
|
84
|
+
"jiti": "1.21.6",
|
|
85
|
+
"nitropack": "2.9.7",
|
|
86
|
+
"nuxt": "3.12.4",
|
|
87
|
+
"playwright-core": "1.46.0",
|
|
88
|
+
"rollup": "4.20.0",
|
|
89
|
+
"semver": "7.6.3",
|
|
90
|
+
"typescript": "5.5.4",
|
|
89
91
|
"unbuild": "latest",
|
|
90
|
-
"unimport": "3.
|
|
91
|
-
"vite": "5.
|
|
92
|
-
"vitest": "
|
|
93
|
-
"vue-router": "4.3
|
|
94
|
-
"vue-tsc": "2.0.
|
|
92
|
+
"unimport": "3.10.0",
|
|
93
|
+
"vite": "5.4.0",
|
|
94
|
+
"vitest": "2.0.5",
|
|
95
|
+
"vue-router": "4.4.3",
|
|
96
|
+
"vue-tsc": "2.0.29"
|
|
95
97
|
},
|
|
96
98
|
"peerDependencies": {
|
|
97
99
|
"@cucumber/cucumber": "^10.3.1",
|
|
98
100
|
"@jest/globals": "^29.5.0",
|
|
99
101
|
"@playwright/test": "^1.43.1",
|
|
100
102
|
"@testing-library/vue": "^7.0.0 || ^8.0.1",
|
|
101
|
-
"@vitest/ui": "^0.34.6 || ^1.0.0",
|
|
103
|
+
"@vitest/ui": "^0.34.6 || ^1.0.0 || ^2.0.0",
|
|
102
104
|
"@vue/test-utils": "^2.4.2",
|
|
103
105
|
"h3": "*",
|
|
104
106
|
"happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -106,7 +108,7 @@
|
|
|
106
108
|
"nitropack": "*",
|
|
107
109
|
"playwright-core": "^1.43.1",
|
|
108
110
|
"vite": "*",
|
|
109
|
-
"vitest": "^0.34.6 || ^1.0.0",
|
|
111
|
+
"vitest": "^0.34.6 || ^1.0.0 || ^2.0.0",
|
|
110
112
|
"vue": "^3.3.4",
|
|
111
113
|
"vue-router": "^4.0.0"
|
|
112
114
|
},
|
|
@@ -143,21 +145,19 @@
|
|
|
143
145
|
}
|
|
144
146
|
},
|
|
145
147
|
"resolutions": {
|
|
146
|
-
"@cucumber/cucumber": "10.
|
|
147
|
-
"@nuxt/
|
|
148
|
-
"@nuxt/
|
|
148
|
+
"@cucumber/cucumber": "10.8.0",
|
|
149
|
+
"@nuxt/devtools": "1.0.8",
|
|
150
|
+
"@nuxt/kit": "^3.12.4",
|
|
151
|
+
"@nuxt/schema": "^3.12.4",
|
|
149
152
|
"@nuxt/test-utils": "workspace:*",
|
|
150
|
-
"rollup": "4.
|
|
151
|
-
"vite": "5.
|
|
152
|
-
"
|
|
153
|
+
"rollup": "4.20.0",
|
|
154
|
+
"vite": "5.4.0",
|
|
155
|
+
"vite-node": "2.0.5",
|
|
156
|
+
"vitest": "2.0.5",
|
|
157
|
+
"vue": "^3.4.37"
|
|
153
158
|
},
|
|
154
159
|
"engines": {
|
|
155
|
-
"node": ">=18.20.
|
|
160
|
+
"node": ">=18.20.4"
|
|
156
161
|
},
|
|
157
|
-
"packageManager": "pnpm@9.
|
|
158
|
-
"pnpm": {
|
|
159
|
-
"patchedDependencies": {
|
|
160
|
-
"nuxt@3.11.2": "patches/nuxt@3.11.2.patch"
|
|
161
|
-
}
|
|
162
|
-
}
|
|
162
|
+
"packageManager": "pnpm@9.7.0"
|
|
163
163
|
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Browser, BrowserContextOptions, Page, Response, LaunchOptions } from 'playwright-core';
|
|
2
|
-
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
3
|
-
import { ExecaChildProcess } from 'execa';
|
|
4
|
-
|
|
5
|
-
declare function createBrowser(): Promise<void>;
|
|
6
|
-
declare function getBrowser(): Promise<Browser>;
|
|
7
|
-
type _GotoOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
8
|
-
interface GotoOptions extends Omit<_GotoOptions, 'waitUntil'> {
|
|
9
|
-
waitUntil?: 'hydration' | 'route' | _GotoOptions['waitUntil'];
|
|
10
|
-
}
|
|
11
|
-
interface NuxtPage extends Omit<Page, 'goto'> {
|
|
12
|
-
goto: (url: string, options?: GotoOptions) => Promise<Response | null>;
|
|
13
|
-
}
|
|
14
|
-
declare function createPage(path?: string, options?: BrowserContextOptions): Promise<NuxtPage>;
|
|
15
|
-
declare function waitForHydration(page: Page, url: string, waitUntil?: GotoOptions['waitUntil']): Promise<void>;
|
|
16
|
-
|
|
17
|
-
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
18
|
-
interface TestOptions {
|
|
19
|
-
testDir: string;
|
|
20
|
-
fixture: string;
|
|
21
|
-
configFile: string;
|
|
22
|
-
rootDir: string;
|
|
23
|
-
buildDir: string;
|
|
24
|
-
nuxtConfig: NuxtConfig;
|
|
25
|
-
build: boolean;
|
|
26
|
-
dev: boolean;
|
|
27
|
-
setupTimeout: number;
|
|
28
|
-
waitFor: number;
|
|
29
|
-
browser: boolean;
|
|
30
|
-
runner: TestRunner;
|
|
31
|
-
logLevel: number;
|
|
32
|
-
browserOptions: {
|
|
33
|
-
type: 'chromium' | 'firefox' | 'webkit';
|
|
34
|
-
launch?: LaunchOptions;
|
|
35
|
-
};
|
|
36
|
-
server: boolean;
|
|
37
|
-
port?: number;
|
|
38
|
-
}
|
|
39
|
-
interface TestContext {
|
|
40
|
-
options: TestOptions;
|
|
41
|
-
nuxt?: Nuxt;
|
|
42
|
-
browser?: Browser;
|
|
43
|
-
url?: string;
|
|
44
|
-
serverProcess?: ExecaChildProcess;
|
|
45
|
-
mockFn?: (...args: unknown[]) => unknown;
|
|
46
|
-
/**
|
|
47
|
-
* Functions to run on the vitest `afterAll` hook.
|
|
48
|
-
* Useful for removing anything created during the test.
|
|
49
|
-
*/
|
|
50
|
-
teardown?: (() => void)[];
|
|
51
|
-
}
|
|
52
|
-
interface TestHooks {
|
|
53
|
-
beforeEach: () => void;
|
|
54
|
-
afterEach: () => void;
|
|
55
|
-
afterAll: () => Promise<void>;
|
|
56
|
-
setup: () => Promise<void>;
|
|
57
|
-
ctx: TestContext;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { type GotoOptions as G, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d, type TestRunner as e, getBrowser as g, waitForHydration as w };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Browser, BrowserContextOptions, Page, Response, LaunchOptions } from 'playwright-core';
|
|
2
|
-
import { NuxtConfig, Nuxt } from '@nuxt/schema';
|
|
3
|
-
import { ExecaChildProcess } from 'execa';
|
|
4
|
-
|
|
5
|
-
declare function createBrowser(): Promise<void>;
|
|
6
|
-
declare function getBrowser(): Promise<Browser>;
|
|
7
|
-
type _GotoOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
8
|
-
interface GotoOptions extends Omit<_GotoOptions, 'waitUntil'> {
|
|
9
|
-
waitUntil?: 'hydration' | 'route' | _GotoOptions['waitUntil'];
|
|
10
|
-
}
|
|
11
|
-
interface NuxtPage extends Omit<Page, 'goto'> {
|
|
12
|
-
goto: (url: string, options?: GotoOptions) => Promise<Response | null>;
|
|
13
|
-
}
|
|
14
|
-
declare function createPage(path?: string, options?: BrowserContextOptions): Promise<NuxtPage>;
|
|
15
|
-
declare function waitForHydration(page: Page, url: string, waitUntil?: GotoOptions['waitUntil']): Promise<void>;
|
|
16
|
-
|
|
17
|
-
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
18
|
-
interface TestOptions {
|
|
19
|
-
testDir: string;
|
|
20
|
-
fixture: string;
|
|
21
|
-
configFile: string;
|
|
22
|
-
rootDir: string;
|
|
23
|
-
buildDir: string;
|
|
24
|
-
nuxtConfig: NuxtConfig;
|
|
25
|
-
build: boolean;
|
|
26
|
-
dev: boolean;
|
|
27
|
-
setupTimeout: number;
|
|
28
|
-
waitFor: number;
|
|
29
|
-
browser: boolean;
|
|
30
|
-
runner: TestRunner;
|
|
31
|
-
logLevel: number;
|
|
32
|
-
browserOptions: {
|
|
33
|
-
type: 'chromium' | 'firefox' | 'webkit';
|
|
34
|
-
launch?: LaunchOptions;
|
|
35
|
-
};
|
|
36
|
-
server: boolean;
|
|
37
|
-
port?: number;
|
|
38
|
-
}
|
|
39
|
-
interface TestContext {
|
|
40
|
-
options: TestOptions;
|
|
41
|
-
nuxt?: Nuxt;
|
|
42
|
-
browser?: Browser;
|
|
43
|
-
url?: string;
|
|
44
|
-
serverProcess?: ExecaChildProcess;
|
|
45
|
-
mockFn?: (...args: unknown[]) => unknown;
|
|
46
|
-
/**
|
|
47
|
-
* Functions to run on the vitest `afterAll` hook.
|
|
48
|
-
* Useful for removing anything created during the test.
|
|
49
|
-
*/
|
|
50
|
-
teardown?: (() => void)[];
|
|
51
|
-
}
|
|
52
|
-
interface TestHooks {
|
|
53
|
-
beforeEach: () => void;
|
|
54
|
-
afterEach: () => void;
|
|
55
|
-
afterAll: () => Promise<void>;
|
|
56
|
-
setup: () => Promise<void>;
|
|
57
|
-
ctx: TestContext;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { type GotoOptions as G, type TestOptions as T, type TestContext as a, type TestHooks as b, createBrowser as c, createPage as d, type TestRunner as e, getBrowser as g, waitForHydration as w };
|