@nuxt/test-utils 3.17.1 → 3.18.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/README.md +1 -1
- package/dist/config.mjs +4 -3
- package/dist/e2e.d.mts +7 -3
- package/dist/e2e.mjs +3 -3
- package/dist/experimental.mjs +1 -1
- package/dist/module.d.mts +2 -1
- package/dist/playwright.d.mts +3 -2
- package/dist/playwright.mjs +3 -3
- package/dist/runtime/global-setup.mjs +1 -1
- package/dist/runtime-utils/index.mjs +62 -59
- package/dist/shared/{test-utils.CHPAu7TP.mjs → test-utils.B8qEdk9k.mjs} +3 -1
- package/dist/shared/{test-utils.BIDY1MqP.mjs → test-utils.CT3RJOY3.mjs} +17 -6
- package/dist/shared/{test-utils.DgnIK8xl.d.mts → test-utils.DtJCg4f3.d.mts} +8 -3
- package/dist/vitest-environment.d.mts +2 -1
- package/dist/vitest-environment.mjs +45 -16
- package/package.json +45 -41
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Nuxt Test Utils is currently powering [the tests we use on Nuxt itself](https://
|
|
|
11
11
|
You can find out more about how to use Nuxt Test Utils:
|
|
12
12
|
|
|
13
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
|
|
14
|
+
- in [an in-depth guide for module authors](https://nuxt.com/docs/guide/going-further/modules#testing)
|
|
15
15
|
|
|
16
16
|
## License
|
|
17
17
|
|
package/dist/config.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
2
|
import { setupDotenv } from 'c12';
|
|
3
3
|
import { defu } from 'defu';
|
|
4
|
-
import { createResolver } from '@nuxt/kit';
|
|
4
|
+
import { createResolver, findPath } from '@nuxt/kit';
|
|
5
5
|
import destr from 'destr';
|
|
6
6
|
import { snakeCase } from 'scule';
|
|
7
7
|
|
|
@@ -100,7 +100,7 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
|
|
|
100
100
|
// overrides
|
|
101
101
|
{
|
|
102
102
|
define: {
|
|
103
|
-
|
|
103
|
+
"process.env.NODE_ENV": '"test"'
|
|
104
104
|
},
|
|
105
105
|
test: {
|
|
106
106
|
dir: process.cwd(),
|
|
@@ -188,7 +188,8 @@ async function getVitestConfigFromNuxt(options, loadNuxtOptions = {}) {
|
|
|
188
188
|
resolvedConfig.test.setupFiles = [resolvedConfig.test.setupFiles].filter(Boolean);
|
|
189
189
|
}
|
|
190
190
|
const resolver = createResolver(import.meta.url);
|
|
191
|
-
|
|
191
|
+
const entryPath = resolver.resolve("./runtime/entry");
|
|
192
|
+
resolvedConfig.test.setupFiles.unshift(await findPath(entryPath) ?? entryPath);
|
|
192
193
|
return resolvedConfig;
|
|
193
194
|
}
|
|
194
195
|
function defineVitestConfig(config = {}) {
|
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.DtJCg4f3.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.DtJCg4f3.mjs';
|
|
3
3
|
import { LogType } from 'consola';
|
|
4
4
|
import 'playwright-core';
|
|
5
5
|
import '@nuxt/schema';
|
|
@@ -19,6 +19,8 @@ declare function mockLogger(): Record<LogType, (...args: unknown[]) => void>;
|
|
|
19
19
|
declare function loadFixture(): Promise<void>;
|
|
20
20
|
declare function buildFixture(): Promise<void>;
|
|
21
21
|
|
|
22
|
+
declare function setupBun(hooks: TestHooks): Promise<void>;
|
|
23
|
+
|
|
22
24
|
declare function setupCucumber(hooks: TestHooks): Promise<void>;
|
|
23
25
|
|
|
24
26
|
declare function setupJest(hooks: TestHooks): Promise<void>;
|
|
@@ -26,6 +28,7 @@ declare function setupJest(hooks: TestHooks): Promise<void>;
|
|
|
26
28
|
declare function setupVitest(hooks: TestHooks): Promise<void>;
|
|
27
29
|
|
|
28
30
|
declare const setupMaps: {
|
|
31
|
+
bun: typeof setupBun;
|
|
29
32
|
cucumber: typeof setupCucumber;
|
|
30
33
|
jest: typeof setupJest;
|
|
31
34
|
vitest: typeof setupVitest;
|
|
@@ -42,4 +45,5 @@ interface RunTestOptions {
|
|
|
42
45
|
}
|
|
43
46
|
declare function runTests(opts: RunTestOptions): Promise<void>;
|
|
44
47
|
|
|
45
|
-
export {
|
|
48
|
+
export { TestContext, TestHooks, TestOptions, buildFixture, createTest, createTestContext, exposeContextToEnv, isDev, loadFixture, mockFn, mockLogger, recoverContextFromEnv, runTests, setTestContext, setup, setupMaps, useTestContext };
|
|
49
|
+
export type { RunTestOptions };
|
package/dist/e2e.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.CT3RJOY3.mjs';
|
|
2
|
+
import { u as useTestContext } from './shared/test-utils.B8qEdk9k.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.B8qEdk9k.mjs';
|
|
4
4
|
import { consola } from 'consola';
|
|
5
5
|
import { resolve } from 'pathe';
|
|
6
6
|
import { distDir } from '#dirs';
|
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.B8qEdk9k.mjs';
|
|
4
4
|
import 'tinyexec';
|
|
5
5
|
import 'get-port-please';
|
|
6
6
|
import 'ofetch';
|
package/dist/module.d.mts
CHANGED
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.DtJCg4f3.mjs';
|
|
5
5
|
import '@nuxt/schema';
|
|
6
6
|
import 'tinyexec';
|
|
7
7
|
|
|
@@ -35,4 +35,5 @@ type TestOptions = {
|
|
|
35
35
|
*/
|
|
36
36
|
declare const test: _playwright_test.TestType<_playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & TestOptions, _playwright_test.PlaywrightWorkerArgs & _playwright_test.PlaywrightWorkerOptions & WorkerOptions & ConfigOptions>;
|
|
37
37
|
|
|
38
|
-
export {
|
|
38
|
+
export { test };
|
|
39
|
+
export type { ConfigOptions };
|
package/dist/playwright.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.CT3RJOY3.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
10
|
import '@nuxt/kit';
|
|
11
|
-
import { d as url } from './shared/test-utils.
|
|
11
|
+
import { d as url } from './shared/test-utils.B8qEdk9k.mjs';
|
|
12
12
|
import 'pathe';
|
|
13
13
|
import '#dirs';
|
|
14
14
|
import 'tinyexec';
|
|
@@ -21,7 +21,7 @@ const test = test$1.extend({
|
|
|
21
21
|
_nuxtHooks: [
|
|
22
22
|
async ({ nuxt, defaults }, use) => {
|
|
23
23
|
const hooks = createTest(defu(nuxt || {}, defaults.nuxt || {}));
|
|
24
|
-
await hooks.
|
|
24
|
+
await hooks.beforeAll();
|
|
25
25
|
await use(hooks);
|
|
26
26
|
await hooks.afterAll();
|
|
27
27
|
},
|
|
@@ -5,7 +5,7 @@ const options = JSON.parse(process.env.NUXT_TEST_OPTIONS || "{}");
|
|
|
5
5
|
const hooks = createTest(options);
|
|
6
6
|
export const setup = async () => {
|
|
7
7
|
kit.logger.info("Building Nuxt app...");
|
|
8
|
-
await hooks.
|
|
8
|
+
await hooks.beforeAll();
|
|
9
9
|
exposeContextToEnv();
|
|
10
10
|
kit.logger.info("Running tests...");
|
|
11
11
|
};
|
|
@@ -296,70 +296,73 @@ async function renderSuspended(component, options) {
|
|
|
296
296
|
// because there's no root element while Suspense is resolving
|
|
297
297
|
h$1(
|
|
298
298
|
WrapperComponent,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
299
|
+
{},
|
|
300
|
+
{
|
|
301
|
+
default: () => h$1(
|
|
302
|
+
Suspense,
|
|
303
|
+
{
|
|
304
|
+
onResolve: () => nextTick().then(() => {
|
|
305
|
+
utils.setupState = setupState;
|
|
306
|
+
resolve(utils);
|
|
307
|
+
})
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
default: () => h$1({
|
|
311
|
+
name: "RenderHelper",
|
|
312
|
+
async setup() {
|
|
313
|
+
const router = useRouter();
|
|
314
|
+
await router.replace(route);
|
|
315
|
+
const clonedComponent = {
|
|
316
|
+
name: "RenderSuspendedComponent",
|
|
317
|
+
...component,
|
|
318
|
+
render: render ? function(_ctx, ...args) {
|
|
319
|
+
if (data && typeof data === "function") {
|
|
320
|
+
const dataObject = data();
|
|
321
|
+
for (const key in dataObject) {
|
|
322
|
+
renderContext[key] = dataObject[key];
|
|
323
|
+
}
|
|
321
324
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
325
|
+
for (const key in setupState || {}) {
|
|
326
|
+
const warn = console.warn;
|
|
327
|
+
console.warn = () => {
|
|
328
|
+
};
|
|
329
|
+
try {
|
|
330
|
+
renderContext[key] = isReadonly(setupState[key]) ? unref(setupState[key]) : setupState[key];
|
|
331
|
+
} catch {
|
|
332
|
+
} finally {
|
|
333
|
+
console.warn = warn;
|
|
334
|
+
}
|
|
335
|
+
if (key === "props") {
|
|
336
|
+
renderContext[key] = cloneProps(renderContext[key]);
|
|
337
|
+
}
|
|
332
338
|
}
|
|
333
|
-
|
|
334
|
-
|
|
339
|
+
const propsContext = "props" in renderContext ? renderContext.props : renderContext;
|
|
340
|
+
for (const key in props || {}) {
|
|
341
|
+
propsContext[key] = _ctx[key];
|
|
335
342
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
for (const key in props || {}) {
|
|
339
|
-
propsContext[key] = _ctx[key];
|
|
340
|
-
}
|
|
341
|
-
for (const key in passedProps || {}) {
|
|
342
|
-
propsContext[key] = passedProps[key];
|
|
343
|
-
}
|
|
344
|
-
if (methods && typeof methods === "object") {
|
|
345
|
-
for (const key in methods) {
|
|
346
|
-
renderContext[key] = methods[key].bind(renderContext);
|
|
343
|
+
for (const key in passedProps || {}) {
|
|
344
|
+
propsContext[key] = passedProps[key];
|
|
347
345
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
346
|
+
if (methods && typeof methods === "object") {
|
|
347
|
+
for (const key in methods) {
|
|
348
|
+
renderContext[key] = methods[key].bind(renderContext);
|
|
349
|
+
}
|
|
352
350
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
351
|
+
if (computed && typeof computed === "object") {
|
|
352
|
+
for (const key in computed) {
|
|
353
|
+
renderContext[key] = computed[key].call(renderContext);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return render.call(this, renderContext, ...args);
|
|
357
|
+
} : void 0,
|
|
358
|
+
setup: setup ? (props2) => wrappedSetup(props2, setupContext) : void 0
|
|
359
|
+
};
|
|
360
|
+
return () => h$1(clonedComponent, { ...props && typeof props === "object" ? props : {}, ...attrs }, slots);
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
}
|
|
363
366
|
)
|
|
364
367
|
)
|
|
365
368
|
},
|
|
@@ -5,7 +5,7 @@ import { resolve as resolve$1 } from 'pathe';
|
|
|
5
5
|
import { withTrailingSlash, joinURL } from 'ufo';
|
|
6
6
|
import { resolve } from 'node:path';
|
|
7
7
|
import { defu } from 'defu';
|
|
8
|
-
import { isWindows } from 'std-env';
|
|
8
|
+
import { isWindows, isBun } from 'std-env';
|
|
9
9
|
|
|
10
10
|
let currentContext;
|
|
11
11
|
function createTestContext(options) {
|
|
@@ -39,6 +39,8 @@ function createTestContext(options) {
|
|
|
39
39
|
_options.runner ||= "vitest";
|
|
40
40
|
} else if (process.env.JEST_WORKER_ID) {
|
|
41
41
|
_options.runner ||= "jest";
|
|
42
|
+
} else if (isBun) {
|
|
43
|
+
_options.runner ||= "bun";
|
|
42
44
|
}
|
|
43
45
|
return setTestContext({
|
|
44
46
|
options: _options,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { u as useTestContext, d as url, c as createTestContext, a as startServer, b as stopServer, s as setTestContext } from './test-utils.
|
|
1
|
+
import { u as useTestContext, d as url, c as createTestContext, a as startServer, b as stopServer, s as setTestContext } from './test-utils.B8qEdk9k.mjs';
|
|
2
2
|
import { existsSync, promises } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { defu } from 'defu';
|
|
@@ -113,9 +113,18 @@ async function buildFixture() {
|
|
|
113
113
|
kit.logger.level = prevLevel;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
async function setupBun(hooks) {
|
|
117
|
+
const bunTest = await import('bun:test');
|
|
118
|
+
hooks.ctx.mockFn = bunTest.mock;
|
|
119
|
+
bunTest.beforeAll(hooks.beforeAll);
|
|
120
|
+
bunTest.beforeEach(hooks.beforeEach);
|
|
121
|
+
bunTest.afterEach(hooks.afterEach);
|
|
122
|
+
bunTest.afterAll(hooks.afterAll);
|
|
123
|
+
}
|
|
124
|
+
|
|
116
125
|
async function setupCucumber(hooks) {
|
|
117
126
|
const { After, AfterAll, Before, BeforeAll } = await import('@cucumber/cucumber');
|
|
118
|
-
BeforeAll({ timeout: hooks.ctx.options.setupTimeout }, hooks.
|
|
127
|
+
BeforeAll({ timeout: hooks.ctx.options.setupTimeout }, hooks.beforeAll);
|
|
119
128
|
Before(hooks.beforeEach);
|
|
120
129
|
After(hooks.afterEach);
|
|
121
130
|
AfterAll(hooks.afterAll);
|
|
@@ -124,7 +133,7 @@ async function setupCucumber(hooks) {
|
|
|
124
133
|
async function setupJest(hooks) {
|
|
125
134
|
const { jest, test, beforeEach, afterAll, afterEach } = await import('@jest/globals');
|
|
126
135
|
hooks.ctx.mockFn = jest.fn;
|
|
127
|
-
test("setup", hooks.
|
|
136
|
+
test("setup", hooks.beforeAll, hooks.ctx.options.setupTimeout);
|
|
128
137
|
beforeEach(hooks.beforeEach);
|
|
129
138
|
afterEach(hooks.afterEach);
|
|
130
139
|
afterAll(hooks.afterAll, hooks.ctx.options.teardownTimeout);
|
|
@@ -133,13 +142,14 @@ async function setupJest(hooks) {
|
|
|
133
142
|
async function setupVitest(hooks) {
|
|
134
143
|
const vitest = await import('vitest');
|
|
135
144
|
hooks.ctx.mockFn = vitest.vi.fn;
|
|
136
|
-
vitest.beforeAll(hooks.
|
|
145
|
+
vitest.beforeAll(hooks.beforeAll, hooks.ctx.options.setupTimeout);
|
|
137
146
|
vitest.beforeEach(hooks.beforeEach);
|
|
138
147
|
vitest.afterEach(hooks.afterEach);
|
|
139
148
|
vitest.afterAll(hooks.afterAll, hooks.ctx.options.teardownTimeout);
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
const setupMaps = {
|
|
152
|
+
bun: setupBun,
|
|
143
153
|
cucumber: setupCucumber,
|
|
144
154
|
jest: setupJest,
|
|
145
155
|
vitest: setupVitest
|
|
@@ -166,7 +176,7 @@ function createTest(options) {
|
|
|
166
176
|
}
|
|
167
177
|
await Promise.all(!ctx.teardown ? [] : ctx.teardown.map((fn) => fn()));
|
|
168
178
|
};
|
|
169
|
-
const
|
|
179
|
+
const beforeAll = async () => {
|
|
170
180
|
if (ctx.options.fixture) {
|
|
171
181
|
await loadFixture();
|
|
172
182
|
}
|
|
@@ -187,7 +197,8 @@ function createTest(options) {
|
|
|
187
197
|
beforeEach,
|
|
188
198
|
afterEach,
|
|
189
199
|
afterAll,
|
|
190
|
-
|
|
200
|
+
beforeAll,
|
|
201
|
+
setup: beforeAll,
|
|
191
202
|
ctx
|
|
192
203
|
};
|
|
193
204
|
}
|
|
@@ -23,7 +23,7 @@ declare function fetch(path: string, options?: RequestInit): Promise<Response>;
|
|
|
23
23
|
declare const $fetch: (typeof globalThis)["$fetch"];
|
|
24
24
|
declare function url(path: string): string;
|
|
25
25
|
|
|
26
|
-
type TestRunner = 'vitest' | 'jest' | 'cucumber';
|
|
26
|
+
type TestRunner = 'vitest' | 'jest' | 'cucumber' | 'bun';
|
|
27
27
|
interface TestOptions {
|
|
28
28
|
testDir: string;
|
|
29
29
|
fixture: string;
|
|
@@ -62,7 +62,7 @@ interface TestOptions {
|
|
|
62
62
|
*/
|
|
63
63
|
browser: boolean;
|
|
64
64
|
/**
|
|
65
|
-
* Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber'`.
|
|
65
|
+
* Specify the runner for the test suite. One of `'vitest' | 'jest' | 'cucumber' | 'bun'`.
|
|
66
66
|
* @default `vitest`
|
|
67
67
|
*/
|
|
68
68
|
runner: TestRunner;
|
|
@@ -107,8 +107,13 @@ interface TestHooks {
|
|
|
107
107
|
beforeEach: () => void;
|
|
108
108
|
afterEach: () => void;
|
|
109
109
|
afterAll: () => Promise<void>;
|
|
110
|
+
beforeAll: () => Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated use `beforeAll` intead
|
|
113
|
+
*/
|
|
110
114
|
setup: () => Promise<void>;
|
|
111
115
|
ctx: TestContext;
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
export { $fetch as $,
|
|
118
|
+
export { $fetch as $, createBrowser as c, createPage as d, stopServer as e, fetch as f, getBrowser as g, startServer as s, url as u, waitForHydration as w };
|
|
119
|
+
export type { GotoOptions as G, NuxtPage as N, StartServerOptions as S, TestOptions as T, TestContext as a, TestHooks as b, TestRunner as h };
|
|
@@ -25,4 +25,5 @@ type EnvironmentNuxt = (global: typeof globalThis, options: EnvironmentNuxtOptio
|
|
|
25
25
|
teardown(): void;
|
|
26
26
|
}>;
|
|
27
27
|
|
|
28
|
-
export {
|
|
28
|
+
export { _default as default };
|
|
29
|
+
export type { EnvironmentNuxt, EnvironmentNuxtOptions, NuxtBuiltinEnvironment, NuxtWindow };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createFetch
|
|
1
|
+
import { createFetch } from 'ofetch';
|
|
2
2
|
import { indexedDB } from 'fake-indexeddb';
|
|
3
3
|
import { joinURL } from 'ufo';
|
|
4
|
-
import { createApp, toNodeListener, defineEventHandler } from 'h3';
|
|
4
|
+
import { createApp, toNodeListener, defineEventHandler, splitCookiesString } from 'h3';
|
|
5
5
|
import defu from 'defu';
|
|
6
6
|
import { toRouteMatcher, createRouter, exportMatcher } from 'radix3';
|
|
7
7
|
import { populateGlobal } from 'vitest/environments';
|
|
8
|
-
import {
|
|
8
|
+
import { fetchNodeRequestHandler } from 'node-mock-http';
|
|
9
9
|
import { importModule } from 'local-pkg';
|
|
10
10
|
|
|
11
11
|
const happyDom = (async function(_, { happyDom = {} }) {
|
|
@@ -103,22 +103,22 @@ const index = {
|
|
|
103
103
|
await import('node-fetch-native/polyfill');
|
|
104
104
|
win.URLSearchParams = globalThis.URLSearchParams;
|
|
105
105
|
}
|
|
106
|
-
const
|
|
107
|
-
const localFetch = createFetch(localCall, win.fetch);
|
|
106
|
+
const nodeHandler = toNodeListener(h3App);
|
|
108
107
|
const registry = /* @__PURE__ */ new Set();
|
|
109
|
-
win.fetch = (
|
|
110
|
-
if (typeof
|
|
111
|
-
const base =
|
|
112
|
-
if (registry.has(base) || registry.has(
|
|
113
|
-
|
|
108
|
+
win.fetch = async (url2, init) => {
|
|
109
|
+
if (typeof url2 === "string") {
|
|
110
|
+
const base = url2.split("?")[0];
|
|
111
|
+
if (registry.has(base) || registry.has(url2)) {
|
|
112
|
+
url2 = "/_" + url2;
|
|
113
|
+
}
|
|
114
|
+
if (url2.startsWith("/")) {
|
|
115
|
+
const response = await fetchNodeRequestHandler(nodeHandler, url2, init);
|
|
116
|
+
return normalizeFetchResponse(response);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
|
-
return
|
|
117
|
-
...options,
|
|
118
|
-
headers: Array.isArray(options?.headers) ? new Headers(options?.headers) : options?.headers
|
|
119
|
-
});
|
|
119
|
+
return fetch(url2, init);
|
|
120
120
|
};
|
|
121
|
-
win.$fetch = createFetch
|
|
121
|
+
win.$fetch = createFetch({ fetch: win.fetch, Headers: win.Headers });
|
|
122
122
|
win.__registry = registry;
|
|
123
123
|
win.__app = h3App;
|
|
124
124
|
const { keys, originals } = populateGlobal(global, win, {
|
|
@@ -130,7 +130,7 @@ const index = {
|
|
|
130
130
|
);
|
|
131
131
|
const matcher = exportMatcher(routeRulesMatcher);
|
|
132
132
|
const manifestOutputPath = joinURL(
|
|
133
|
-
"/",
|
|
133
|
+
environmentOptions?.nuxtRuntimeConfig.app?.baseURL || "/",
|
|
134
134
|
environmentOptions?.nuxtRuntimeConfig.app?.buildAssetsDir || "_nuxt",
|
|
135
135
|
"builds"
|
|
136
136
|
);
|
|
@@ -165,5 +165,34 @@ const index = {
|
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
+
function normalizeFetchResponse(response) {
|
|
169
|
+
if (!response.headers.has("set-cookie")) {
|
|
170
|
+
return response;
|
|
171
|
+
}
|
|
172
|
+
return new Response(response.body, {
|
|
173
|
+
status: response.status,
|
|
174
|
+
statusText: response.statusText,
|
|
175
|
+
headers: normalizeCookieHeaders(response.headers)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function normalizeCookieHeader(header = "") {
|
|
179
|
+
return splitCookiesString(joinHeaders(header));
|
|
180
|
+
}
|
|
181
|
+
function normalizeCookieHeaders(headers) {
|
|
182
|
+
const outgoingHeaders = new Headers();
|
|
183
|
+
for (const [name, header] of headers) {
|
|
184
|
+
if (name === "set-cookie") {
|
|
185
|
+
for (const cookie of normalizeCookieHeader(header)) {
|
|
186
|
+
outgoingHeaders.append("set-cookie", cookie);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
outgoingHeaders.set(name, joinHeaders(header));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return outgoingHeaders;
|
|
193
|
+
}
|
|
194
|
+
function joinHeaders(value) {
|
|
195
|
+
return Array.isArray(value) ? value.join(", ") : String(value);
|
|
196
|
+
}
|
|
168
197
|
|
|
169
198
|
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/test-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/nuxt/test-utils.git"
|
|
@@ -63,62 +63,63 @@
|
|
|
63
63
|
"dev:prepare": "nuxi prepare && unbuild --stub && pnpm -r dev:prepare"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@nuxt/kit": "^3.
|
|
67
|
-
"@nuxt/schema": "^3.
|
|
68
|
-
"c12": "^3.0.
|
|
69
|
-
"consola": "^3.4.
|
|
66
|
+
"@nuxt/kit": "^3.17.1",
|
|
67
|
+
"@nuxt/schema": "^3.17.1",
|
|
68
|
+
"c12": "^3.0.3",
|
|
69
|
+
"consola": "^3.4.2",
|
|
70
70
|
"defu": "^6.1.4",
|
|
71
|
-
"destr": "^2.0.
|
|
71
|
+
"destr": "^2.0.5",
|
|
72
72
|
"estree-walker": "^3.0.3",
|
|
73
73
|
"fake-indexeddb": "^6.0.0",
|
|
74
74
|
"get-port-please": "^3.1.2",
|
|
75
|
-
"h3": "^1.15.
|
|
76
|
-
"local-pkg": "^1.1.
|
|
75
|
+
"h3": "^1.15.3",
|
|
76
|
+
"local-pkg": "^1.1.1",
|
|
77
77
|
"magic-string": "^0.30.17",
|
|
78
78
|
"node-fetch-native": "^1.6.5",
|
|
79
|
+
"node-mock-http": "^1.0.0",
|
|
79
80
|
"ofetch": "^1.4.1",
|
|
80
81
|
"pathe": "^2.0.3",
|
|
81
82
|
"perfect-debounce": "^1.0.0",
|
|
82
83
|
"radix3": "^1.1.2",
|
|
83
84
|
"scule": "^1.3.0",
|
|
84
|
-
"std-env": "^3.
|
|
85
|
-
"tinyexec": "^0.
|
|
86
|
-
"ufo": "^1.
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"vite": "^6.2.0",
|
|
85
|
+
"std-env": "^3.9.0",
|
|
86
|
+
"tinyexec": "^1.0.1",
|
|
87
|
+
"ufo": "^1.6.1",
|
|
88
|
+
"unplugin": "^2.3.2",
|
|
89
|
+
"vite": "^6.3.4",
|
|
90
90
|
"vitest-environment-nuxt": "^1.0.1",
|
|
91
91
|
"vue": "^3.5.13"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@cucumber/cucumber": "11.2.0",
|
|
95
95
|
"@jest/globals": "29.7.0",
|
|
96
|
-
"@nuxt/devtools-kit": "2.
|
|
97
|
-
"@nuxt/eslint-config": "1.
|
|
98
|
-
"@playwright/test": "1.
|
|
96
|
+
"@nuxt/devtools-kit": "2.4.0",
|
|
97
|
+
"@nuxt/eslint-config": "1.3.0",
|
|
98
|
+
"@playwright/test": "1.52.0",
|
|
99
99
|
"@testing-library/vue": "8.1.0",
|
|
100
|
-
"@types/
|
|
100
|
+
"@types/bun": "1.2.11",
|
|
101
|
+
"@types/estree": "1.0.7",
|
|
101
102
|
"@types/jsdom": "21.1.7",
|
|
102
|
-
"@types/node": "22.
|
|
103
|
-
"@types/semver": "7.
|
|
103
|
+
"@types/node": "22.15.3",
|
|
104
|
+
"@types/semver": "7.7.0",
|
|
104
105
|
"@vue/test-utils": "2.4.6",
|
|
105
|
-
"changelogen": "0.6.
|
|
106
|
-
"compatx": "0.
|
|
107
|
-
"eslint": "9.
|
|
106
|
+
"changelogen": "0.6.1",
|
|
107
|
+
"compatx": "0.2.0",
|
|
108
|
+
"eslint": "9.26.0",
|
|
108
109
|
"installed-check": "9.3.0",
|
|
109
|
-
"knip": "5.
|
|
110
|
-
"nitropack": "2.
|
|
111
|
-
"nuxt": "3.
|
|
112
|
-
"pkg-pr-new": "0.0.
|
|
113
|
-
"playwright-core": "1.
|
|
114
|
-
"rollup": "4.
|
|
110
|
+
"knip": "5.53.0",
|
|
111
|
+
"nitropack": "2.11.11",
|
|
112
|
+
"nuxt": "3.17.1",
|
|
113
|
+
"pkg-pr-new": "0.0.43",
|
|
114
|
+
"playwright-core": "1.52.0",
|
|
115
|
+
"rollup": "4.40.1",
|
|
115
116
|
"semver": "7.7.1",
|
|
116
|
-
"typescript": "5.8.
|
|
117
|
+
"typescript": "5.8.3",
|
|
117
118
|
"unbuild": "latest",
|
|
118
|
-
"unimport": "
|
|
119
|
-
"vitest": "3.
|
|
120
|
-
"vue-router": "4.5.
|
|
121
|
-
"vue-tsc": "2.2.
|
|
119
|
+
"unimport": "5.0.0",
|
|
120
|
+
"vitest": "3.1.2",
|
|
121
|
+
"vue-router": "4.5.1",
|
|
122
|
+
"vue-tsc": "2.2.10"
|
|
122
123
|
},
|
|
123
124
|
"peerDependencies": {
|
|
124
125
|
"@cucumber/cucumber": "^10.3.1 || ^11.0.0",
|
|
@@ -166,22 +167,25 @@
|
|
|
166
167
|
"resolutions": {
|
|
167
168
|
"@cucumber/cucumber": "11.2.0",
|
|
168
169
|
"@nuxt/devtools": "1.0.8",
|
|
169
|
-
"@nuxt/kit": "^3.
|
|
170
|
-
"@nuxt/schema": "^3.
|
|
170
|
+
"@nuxt/kit": "^3.17.1",
|
|
171
|
+
"@nuxt/schema": "^3.17.1",
|
|
171
172
|
"@nuxt/test-utils": "workspace:*",
|
|
172
|
-
"rollup": "4.
|
|
173
|
-
"vite": "^6.
|
|
174
|
-
"vite-node": "3.
|
|
175
|
-
"vitest": "3.
|
|
173
|
+
"rollup": "4.40.1",
|
|
174
|
+
"vite": "^6.3.4",
|
|
175
|
+
"vite-node": "3.1.2",
|
|
176
|
+
"vitest": "3.1.2",
|
|
176
177
|
"vue": "^3.5.13"
|
|
177
178
|
},
|
|
178
179
|
"engines": {
|
|
179
180
|
"node": "^18.20.5 || ^20.9.0 || ^22.0.0 || >=23.0.0"
|
|
180
181
|
},
|
|
181
|
-
"packageManager": "pnpm@10.
|
|
182
|
+
"packageManager": "pnpm@10.10.0",
|
|
182
183
|
"pnpm": {
|
|
183
184
|
"onlyBuiltDependencies": [
|
|
184
185
|
"better-sqlite3"
|
|
186
|
+
],
|
|
187
|
+
"ignoredBuiltDependencies": [
|
|
188
|
+
"esbuild"
|
|
185
189
|
]
|
|
186
190
|
}
|
|
187
191
|
}
|