@nuxt/test-utils
Version:
Test utilities for Nuxt
59 lines (58 loc) • 1.66 kB
JavaScript
import { s as url } from "./server-CmohcsAP.mjs";
import { f as waitForHydration, n as createTest } from "./e2e-rZHdqLA-.mjs";
import defu from "defu";
import { isWindows } from "std-env";
import { expect, test as test$1 } from "@playwright/test";
//#region src/playwright.ts
const FIXTURE_TIMEOUT = isWindows ? 12e4 : 6e4;
/**
* Use a preconfigured Nuxt fixture.
*
* You can pass a `nuxt: {}` object in your device configuration, in the `use` key of your config file,
* or use the following syntax within your test file to configure your Nuxt fixture:
*
```ts
test.use({
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
}
})
```
*
* In `playwright.config.ts` you can pass `defaults: { nuxt: {} }` object for merging with test.use nuxt options
*/
const test = test$1.extend({
nuxt: [void 0, {
option: true,
scope: "worker"
}],
defaults: [{ nuxt: void 0 }, {
option: true,
scope: "worker"
}],
_nuxtHooks: [async ({ nuxt, defaults }, use) => {
const hooks = createTest(defu(nuxt || {}, defaults.nuxt || {}));
await hooks.beforeAll();
await use(hooks);
await hooks.afterAll();
}, {
scope: "worker",
timeout: FIXTURE_TIMEOUT
}],
baseURL: async ({ _nuxtHooks }, use) => {
_nuxtHooks.beforeEach();
await use(url("/"));
_nuxtHooks.afterEach();
},
goto: async ({ page }, use) => {
await use(async (url, options) => {
const waitUntil = options?.waitUntil;
if (waitUntil && ["hydration", "route"].includes(waitUntil)) delete options.waitUntil;
const response = await page.goto(url, options);
await waitForHydration(page, url, waitUntil);
return response;
});
}
});
//#endregion
export { expect, test };