@nuxt/test-utils 3.9.0 → 3.10.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/e2e.d.mts CHANGED
@@ -8,7 +8,7 @@ declare function createBrowser(): Promise<void>;
8
8
  declare function getBrowser(): Promise<Browser>;
9
9
  declare function createPage(path?: string, options?: BrowserContextOptions): Promise<playwright_core.Page>;
10
10
 
11
- type TestRunner = 'vitest' | 'jest';
11
+ type TestRunner = 'vitest' | 'jest' | 'cucumber';
12
12
  interface TestOptions {
13
13
  testDir: string;
14
14
  fixture: string;
@@ -46,8 +46,8 @@ interface TestContext {
46
46
  interface TestHooks {
47
47
  beforeEach: () => void;
48
48
  afterEach: () => void;
49
- afterAll: () => void;
50
- setup: () => void;
49
+ afterAll: () => Promise<void>;
50
+ setup: () => Promise<void>;
51
51
  ctx: TestContext;
52
52
  }
53
53
 
@@ -65,17 +65,23 @@ declare function mockLogger(): Record<string, Function>;
65
65
  declare function loadFixture(): Promise<void>;
66
66
  declare function buildFixture(): Promise<void>;
67
67
 
68
- declare function startServer(): Promise<void>;
68
+ interface StartServerOptions {
69
+ env?: Record<string, unknown>;
70
+ }
71
+ declare function startServer(options?: StartServerOptions): Promise<void>;
69
72
  declare function stopServer(): Promise<void>;
70
73
  declare function fetch(path: string, options?: any): Promise<Response>;
71
74
  declare function $fetch(path: string, options?: FetchOptions): Promise<any>;
72
75
  declare function url(path: string): string;
73
76
 
77
+ declare function setupCucumber(hooks: TestHooks): Promise<void>;
78
+
74
79
  declare function setupJest(hooks: TestHooks): Promise<void>;
75
80
 
76
81
  declare function setupVitest(hooks: TestHooks): Promise<void>;
77
82
 
78
83
  declare const setupMaps: {
84
+ cucumber: typeof setupCucumber;
79
85
  jest: typeof setupJest;
80
86
  vitest: typeof setupVitest;
81
87
  };
@@ -91,4 +97,4 @@ interface RunTestOptions {
91
97
  }
92
98
  declare function runTests(opts: RunTestOptions): Promise<void>;
93
99
 
94
- export { $fetch, type RunTestOptions, type TestContext, type TestHooks, type TestOptions, type TestRunner, buildFixture, createBrowser, createPage, createTest, createTestContext, exposeContextToEnv, fetch, getBrowser, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, startServer, stopServer, url, useTestContext };
100
+ export { $fetch, type RunTestOptions, type StartServerOptions, type TestContext, type TestHooks, type TestOptions, type TestRunner, buildFixture, createBrowser, createPage, createTest, createTestContext, exposeContextToEnv, fetch, getBrowser, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, startServer, stopServer, url, useTestContext };
package/dist/e2e.d.ts CHANGED
@@ -8,7 +8,7 @@ declare function createBrowser(): Promise<void>;
8
8
  declare function getBrowser(): Promise<Browser>;
9
9
  declare function createPage(path?: string, options?: BrowserContextOptions): Promise<playwright_core.Page>;
10
10
 
11
- type TestRunner = 'vitest' | 'jest';
11
+ type TestRunner = 'vitest' | 'jest' | 'cucumber';
12
12
  interface TestOptions {
13
13
  testDir: string;
14
14
  fixture: string;
@@ -46,8 +46,8 @@ interface TestContext {
46
46
  interface TestHooks {
47
47
  beforeEach: () => void;
48
48
  afterEach: () => void;
49
- afterAll: () => void;
50
- setup: () => void;
49
+ afterAll: () => Promise<void>;
50
+ setup: () => Promise<void>;
51
51
  ctx: TestContext;
52
52
  }
53
53
 
@@ -65,17 +65,23 @@ declare function mockLogger(): Record<string, Function>;
65
65
  declare function loadFixture(): Promise<void>;
66
66
  declare function buildFixture(): Promise<void>;
67
67
 
68
- declare function startServer(): Promise<void>;
68
+ interface StartServerOptions {
69
+ env?: Record<string, unknown>;
70
+ }
71
+ declare function startServer(options?: StartServerOptions): Promise<void>;
69
72
  declare function stopServer(): Promise<void>;
70
73
  declare function fetch(path: string, options?: any): Promise<Response>;
71
74
  declare function $fetch(path: string, options?: FetchOptions): Promise<any>;
72
75
  declare function url(path: string): string;
73
76
 
77
+ declare function setupCucumber(hooks: TestHooks): Promise<void>;
78
+
74
79
  declare function setupJest(hooks: TestHooks): Promise<void>;
75
80
 
76
81
  declare function setupVitest(hooks: TestHooks): Promise<void>;
77
82
 
78
83
  declare const setupMaps: {
84
+ cucumber: typeof setupCucumber;
79
85
  jest: typeof setupJest;
80
86
  vitest: typeof setupVitest;
81
87
  };
@@ -91,4 +97,4 @@ interface RunTestOptions {
91
97
  }
92
98
  declare function runTests(opts: RunTestOptions): Promise<void>;
93
99
 
94
- export { $fetch, type RunTestOptions, type TestContext, type TestHooks, type TestOptions, type TestRunner, buildFixture, createBrowser, createPage, createTest, createTestContext, exposeContextToEnv, fetch, getBrowser, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, startServer, stopServer, url, useTestContext };
100
+ export { $fetch, type RunTestOptions, type StartServerOptions, type TestContext, type TestHooks, type TestOptions, type TestRunner, buildFixture, createBrowser, createPage, createTest, createTestContext, exposeContextToEnv, fetch, getBrowser, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, startServer, stopServer, url, useTestContext };
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.B1uaYm8K.mjs';
2
- export { $ as $fetch, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv } from './shared/test-utils.B1uaYm8K.mjs';
1
+ import { u as useTestContext, a as url, c as createTestContext, s as setTestContext, b as stopServer, d as startServer } from './shared/test-utils.JYxxBhQl.mjs';
2
+ export { $ as $fetch, e as exposeContextToEnv, f as fetch, i as isDev, r as recoverContextFromEnv } from './shared/test-utils.JYxxBhQl.mjs';
3
3
  import { consola } from 'consola';
4
4
  import { existsSync, promises } from 'node:fs';
5
5
  import { resolve } from 'node:path';
@@ -114,6 +114,14 @@ async function buildFixture() {
114
114
  kit.logger.level = prevLevel;
115
115
  }
116
116
 
117
+ async function setupCucumber(hooks) {
118
+ const { After, AfterAll, Before, BeforeAll } = await import('@cucumber/cucumber');
119
+ BeforeAll({ timeout: hooks.ctx.options.setupTimeout }, hooks.setup);
120
+ Before(hooks.beforeEach);
121
+ After(hooks.afterEach);
122
+ AfterAll(hooks.afterAll);
123
+ }
124
+
117
125
  async function setupJest(hooks) {
118
126
  const { jest, test, beforeEach, afterAll, afterEach } = await import('@jest/globals');
119
127
  hooks.ctx.mockFn = jest.fn;
@@ -133,6 +141,7 @@ async function setupVitest(hooks) {
133
141
  }
134
142
 
135
143
  const setupMaps = {
144
+ cucumber: setupCucumber,
136
145
  jest: setupJest,
137
146
  vitest: setupVitest
138
147
  };
@@ -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.B1uaYm8K.mjs';
3
+ import { $ as $fetch, u as useTestContext } from './shared/test-utils.JYxxBhQl.mjs';
4
4
  import 'execa';
5
5
  import 'get-port-please';
6
6
  import 'ofetch';
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { pathToFileURL } from 'node:url';
2
- import { resolvePath, useNuxt, resolveIgnorePatterns, addVitePlugin, defineNuxtModule, createResolver, logger } from '@nuxt/kit';
2
+ import { useNuxt, resolveIgnorePatterns, addVitePlugin, defineNuxtModule, createResolver, resolvePath, logger } from '@nuxt/kit';
3
3
  import { mergeConfig } from 'vite';
4
4
  import { getPort } from 'get-port-please';
5
5
  import { h } from 'vue';
@@ -9,7 +9,6 @@ import { defu } from 'defu';
9
9
  import { getVitestConfigFromNuxt } from './config.mjs';
10
10
  import { walk } from 'estree-walker';
11
11
  import MagicString from 'magic-string';
12
- import { normalize, resolve } from 'node:path';
13
12
  import { createUnplugin } from 'unplugin';
14
13
  import { readFileSync } from 'node:fs';
15
14
  import { extname, join, dirname } from 'pathe';
@@ -23,10 +22,7 @@ const HELPER_MOCK_COMPONENT = "mockComponent";
23
22
  const HELPER_MOCK_HOIST = "__NUXT_VITEST_MOCKS";
24
23
  const HELPERS_NAME = [HELPER_MOCK_IMPORT, HELPER_MOCK_COMPONENT];
25
24
  const createMockPlugin = (ctx) => createUnplugin(() => {
26
- let resolvedFirstSetupFile = null;
27
25
  function transform(code, id) {
28
- const isFirstSetupFile = normalize(id) === resolvedFirstSetupFile;
29
- const shouldPrependMockHoist = resolvedFirstSetupFile ? isFirstSetupFile : true;
30
26
  if (!HELPERS_NAME.some((n) => code.includes(n)))
31
27
  return;
32
28
  if (id.includes("/node_modules/"))
@@ -205,12 +201,10 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
205
201
  s.prepend(`import {vi} from "vitest";
206
202
  `);
207
203
  s.appendLeft(insertionPoint, mockLines.join("\n") + "\n");
208
- if (shouldPrependMockHoist) {
209
- importPathsList.forEach((p) => {
210
- s.append(`
204
+ importPathsList.forEach((p) => {
205
+ s.append(`
211
206
  import ${JSON.stringify(p)};`);
212
- });
213
- }
207
+ });
214
208
  return {
215
209
  code: s.toString(),
216
210
  map: s.generateMap()
@@ -223,10 +217,6 @@ const createMockPlugin = (ctx) => createUnplugin(() => {
223
217
  transform,
224
218
  // Place Vitest's mock plugin after all Nuxt plugins
225
219
  async configResolved(config) {
226
- const firstSetupFile = Array.isArray(config.test?.setupFiles) ? config.test.setupFiles.find((p) => !p.includes("runtime/entry")) : config.test?.setupFiles;
227
- if (firstSetupFile) {
228
- resolvedFirstSetupFile = await resolvePath(normalize(resolve(firstSetupFile)));
229
- }
230
220
  const plugins = config.plugins || [];
231
221
  const vitestPlugins = plugins.filter((p) => (p.name === "vite:mocks" || p.name.startsWith("vitest:")) && (p.enforce || p.order) === "post");
232
222
  const lastNuxt = findLastIndex(
@@ -1,4 +1,4 @@
1
1
  declare const _default: import("vue").DefineComponent<{}, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
2
2
  [key: string]: any;
3
- }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
3
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
4
4
  export default _default;
@@ -34,7 +34,10 @@ function mockComponent(_path, _component) {
34
34
  const RouterLink = defineComponent({
35
35
  functional: true,
36
36
  props: {
37
- to: [String, Object],
37
+ to: {
38
+ type: [String, Object],
39
+ required: true
40
+ },
38
41
  custom: Boolean,
39
42
  replace: Boolean,
40
43
  // Not implemented
@@ -46,11 +49,11 @@ const RouterLink = defineComponent({
46
49
  const navigate = () => {
47
50
  };
48
51
  return () => {
49
- const route = props.to ? useRouter().resolve(props.to) : {};
50
- return props.custom ? slots.default?.({ href: props.to, navigate, route }) : h(
52
+ const route = useRouter().resolve(props.to);
53
+ return props.custom ? slots.default?.({ href: route.href, navigate, route }) : h(
51
54
  "a",
52
55
  {
53
- href: props.to,
56
+ href: route.href,
54
57
  onClick: (e) => {
55
58
  e.preventDefault();
56
59
  return navigate();
@@ -53,7 +53,7 @@ function exposeContextToEnv() {
53
53
  }
54
54
 
55
55
  const kit = _kit.default || _kit;
56
- async function startServer() {
56
+ async function startServer(options = {}) {
57
57
  const ctx = useTestContext();
58
58
  await stopServer();
59
59
  const host = "127.0.0.1";
@@ -70,7 +70,8 @@ async function startServer() {
70
70
  // Used by internal _dev command
71
71
  PORT: String(port),
72
72
  HOST: host,
73
- NODE_ENV: "development"
73
+ NODE_ENV: "development",
74
+ ...options.env
74
75
  }
75
76
  });
76
77
  await waitForPort(port, { retries: 32, host }).catch(() => {
@@ -98,7 +99,8 @@ async function startServer() {
98
99
  ...process.env,
99
100
  PORT: String(port),
100
101
  HOST: host,
101
- NODE_ENV: "test"
102
+ NODE_ENV: "test",
103
+ ...options.env
102
104
  }
103
105
  });
104
106
  await waitForPort(port, { retries: 20, host });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/test-utils",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/test-utils.git"
@@ -28,67 +28,69 @@
28
28
  "vitest-environment.d.ts"
29
29
  ],
30
30
  "dependencies": {
31
- "@nuxt/kit": "^3.8.2",
32
- "@nuxt/schema": "^3.8.2",
33
- "c12": "^1.5.1",
31
+ "@nuxt/kit": "^3.9.3",
32
+ "@nuxt/schema": "^3.9.3",
33
+ "c12": "^1.6.1",
34
34
  "consola": "^3.2.3",
35
- "defu": "^6.1.3",
35
+ "defu": "^6.1.4",
36
36
  "destr": "^2.0.2",
37
37
  "estree-walker": "^3.0.3",
38
38
  "execa": "^8.0.1",
39
- "fake-indexeddb": "^5.0.1",
40
- "get-port-please": "^3.1.1",
39
+ "fake-indexeddb": "^5.0.2",
40
+ "get-port-please": "^3.1.2",
41
41
  "local-pkg": "^0.5.0",
42
42
  "magic-string": "^0.30.5",
43
- "node-fetch-native": "^1.4.1",
43
+ "node-fetch-native": "^1.6.1",
44
44
  "ofetch": "^1.3.3",
45
- "pathe": "^1.1.1",
45
+ "pathe": "^1.1.2",
46
46
  "perfect-debounce": "^1.0.0",
47
47
  "radix3": "^1.1.0",
48
- "scule": "^1.1.1",
49
- "std-env": "^3.6.0",
48
+ "scule": "^1.2.0",
49
+ "std-env": "^3.7.0",
50
50
  "ufo": "^1.3.2",
51
- "unenv": "^1.8.0",
52
- "unplugin": "^1.5.1",
51
+ "unenv": "^1.9.0",
52
+ "unplugin": "^1.6.0",
53
53
  "vitest-environment-nuxt": "^1.0.0"
54
54
  },
55
55
  "devDependencies": {
56
+ "@cucumber/cucumber": "10.3.1",
56
57
  "@jest/globals": "29.7.0",
57
- "@nuxt/devtools": "1.0.6",
58
+ "@nuxt/devtools": "1.0.8",
58
59
  "@nuxt/eslint-config": "0.2.0",
59
- "@nuxt/module-builder": "0.5.4",
60
+ "@nuxt/module-builder": "0.5.5",
60
61
  "@testing-library/vue": "8.0.1",
61
62
  "@types/estree": "1.0.5",
62
63
  "@types/jsdom": "21.1.6",
63
64
  "@types/semver": "7.5.6",
64
- "@vitest/ui": "1.0.4",
65
+ "@vitest/ui": "1.1.1",
65
66
  "@vue/test-utils": "2.4.3",
66
67
  "changelogen": "0.5.5",
67
68
  "eslint": "8.56.0",
68
69
  "eslint-plugin-import": "2.29.1",
69
- "eslint-plugin-jsdoc": "46.9.1",
70
+ "eslint-plugin-jsdoc": "48.0.2",
70
71
  "eslint-plugin-no-only-tests": "3.1.0",
71
- "eslint-plugin-unicorn": "49.0.0",
72
- "h3": "1.9.0",
72
+ "eslint-plugin-unicorn": "50.0.1",
73
+ "h3": "1.10.0",
73
74
  "jiti": "1.21.0",
74
- "nuxt": "3.8.2",
75
- "playwright-core": "1.40.1",
76
- "rollup": "4.9.1",
75
+ "nuxt": "3.9.3",
76
+ "playwright-core": "1.41.0",
77
+ "rollup": "4.9.5",
77
78
  "semver": "7.5.4",
78
79
  "unbuild": "latest",
79
- "unimport": "3.6.1",
80
- "vite": "5.0.10",
81
- "vitest": "latest",
80
+ "unimport": "3.7.1",
81
+ "vite": "5.0.11",
82
+ "vitest": "1.1.1",
82
83
  "vue-router": "4.2.5",
83
- "vue-tsc": "1.8.25"
84
+ "vue-tsc": "1.8.27"
84
85
  },
85
86
  "peerDependencies": {
87
+ "@cucumber/cucumber": "^10.3.1",
86
88
  "@jest/globals": "^29.5.0",
87
89
  "@testing-library/vue": "^7.0.0 || ^8.0.1",
88
90
  "@vitest/ui": "^0.34.6 || ^1.0.0",
89
91
  "@vue/test-utils": "^2.4.2",
90
92
  "h3": "*",
91
- "happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0",
93
+ "happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
92
94
  "jsdom": "^22.0.0 || ^23.0.0",
93
95
  "playwright-core": "^1.34.3",
94
96
  "vite": "*",
@@ -97,6 +99,9 @@
97
99
  "vue-router": "^4.0.0"
98
100
  },
99
101
  "peerDependenciesMeta": {
102
+ "@cucumber/cucumber": {
103
+ "optional": true
104
+ },
100
105
  "@testing-library/vue": {
101
106
  "optional": true
102
107
  },
@@ -123,18 +128,21 @@
123
128
  }
124
129
  },
125
130
  "resolutions": {
131
+ "@nuxt/schema": "^3.9.3",
132
+ "@nuxt/kit": "^3.9.3",
126
133
  "@nuxt/test-utils": "workspace:*",
127
- "rollup": "4.9.1",
128
- "vite": "5.0.10"
134
+ "rollup": "4.9.5",
135
+ "vite": "5.0.11",
136
+ "vue": "^3.4.14"
129
137
  },
130
138
  "engines": {
131
139
  "node": "^14.18.0 || >=16.10.0"
132
140
  },
133
- "packageManager": "pnpm@8.12.1",
141
+ "packageManager": "pnpm@8.14.1",
134
142
  "scripts": {
135
143
  "lint": "eslint --ext .vue,.ts,.js,.mjs .",
136
144
  "lint:fix": "eslint --ext .vue,.ts,.js,.mjs . --fix",
137
- "test:examples": "pnpm -r test",
145
+ "test:examples": "pnpm -r test --filter !nuxt-app-cucumber && pnpm -r test --filter nuxt-app-cucumber",
138
146
  "test:types": "vue-tsc --noEmit",
139
147
  "test:unit": "vitest test/unit --run",
140
148
  "dev:prepare": "nuxi prepare && unbuild --stub && pnpm -r dev:prepare",