UNPKG

@nuxt/test-utils

Version:
70 lines (69 loc) 2.34 kB
import { s as url } from "./server-CgIHV0e5.mjs"; import { f as waitForHydration, n as createTest } from "./e2e-C3WWXFwG.mjs"; import defu from "defu"; import { expect, test as test$1 } from "@playwright/test"; //#region src/playwright.ts const FIXTURE_TIMEOUT_BACKSTOP = 18e5; const ABANDONED_SETUP_GRACE = 3e4; /** * 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 || {})); const { setupTimeout } = hooks.ctx.options; const setup = hooks.beforeAll(); let timer; if (await Promise.race([setup.then(() => false), new Promise((resolve) => { timer = setTimeout(() => resolve(true), setupTimeout); })]).finally(() => clearTimeout(timer))) { await hooks.afterAll(); await Promise.race([setup.catch(() => {}), new Promise((resolve) => setTimeout(resolve, ABANDONED_SETUP_GRACE))]); await hooks.afterAll(); const logs = hooks.ctx.serverLogs.slice(-50).join("\n"); throw new Error(`Nuxt test setup timed out after ${setupTimeout}ms. Increase \`setupTimeout\` in your \`nuxt\` fixture options if this is expected.${logs ? `\n\nServer output:\n${logs}` : ""}`); } await use(hooks); await hooks.afterAll(); }, { scope: "worker", timeout: FIXTURE_TIMEOUT_BACKSTOP }], 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 };