diff --git a/packages/astro/e2e/actions-blog.test.js b/packages/astro/e2e/actions-blog.test.js index 1631f7dfece7..d9c1bc1dfd68 100644 --- a/packages/astro/e2e/actions-blog.test.js +++ b/packages/astro/e2e/actions-blog.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; -import { testFactory } from './test-utils.js'; +import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/actions-blog/' }); +const test = testFactory(import.meta.url, { root: './fixtures/actions-blog/' }); let devServer; @@ -23,11 +23,10 @@ test.describe('Astro Actions - Blog', () => { await page.goto(astro.resolveUrl('/blog/first-post/')); const likeButton = page.getByLabel('Like'); + await waitForHydrate(page, likeButton); await expect(likeButton, 'like button starts with 10 likes').toContainText('10'); await likeButton.click(); - await expect(likeButton, 'like button should increment likes').toContainText('11', { - timeout: 6_000, - }); + await expect(likeButton, 'like button should increment likes').toContainText('11'); }); test('Like action - server-side', async ({ page, astro }) => { @@ -38,9 +37,7 @@ test.describe('Astro Actions - Blog', () => { await expect(likeCount, 'like button starts with 10 likes').toContainText('10'); await likeButton.click(); - await expect(likeCount, 'like button should increment likes').toContainText('11', { - timeout: 6_000, - }); + await expect(likeCount, 'like button should increment likes').toContainText('11'); }); test('Comment action - validation error', async ({ page, astro }) => { @@ -134,7 +131,8 @@ test.describe('Astro Actions - Blog', () => { await page.goto(astro.resolveUrl('/blog/first-post/')); const logoutButton = page.getByTestId('logout-button'); + await waitForHydrate(page, logoutButton); await logoutButton.click(); - await expect(page).toHaveURL(astro.resolveUrl('/blog/'), { timeout: 6_000 }); + await expect(page).toHaveURL(astro.resolveUrl('/blog/')); }); }); diff --git a/packages/astro/e2e/actions-react-19.test.js b/packages/astro/e2e/actions-react-19.test.js index 5ce72a419acb..3298db1e334c 100644 --- a/packages/astro/e2e/actions-react-19.test.js +++ b/packages/astro/e2e/actions-react-19.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; -import { testFactory } from './test-utils.js'; +import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/actions-react-19/' }); +const test = testFactory(import.meta.url, { root: './fixtures/actions-react-19/' }); let devServer; @@ -23,10 +23,12 @@ test.describe('Astro Actions - React 19', () => { await page.goto(astro.resolveUrl('/blog/first-post/')); const likeButton = page.getByLabel('likes-client'); + await waitForHydrate(page, likeButton); + await expect(likeButton).toBeVisible(); await likeButton.click(); await expect(likeButton, 'like button should be disabled when pending').toBeDisabled(); - await expect(likeButton).not.toBeDisabled({ timeout: 5000 }); + await expect(likeButton).not.toBeDisabled(); }); test('Like action - server progressive enhancement', async ({ page, astro }) => { @@ -43,6 +45,8 @@ test.describe('Astro Actions - React 19', () => { await page.goto(astro.resolveUrl('/blog/first-post/')); const likeButton = page.getByLabel('likes-action-client'); + await waitForHydrate(page, likeButton); + await expect(likeButton).toBeVisible(); await likeButton.click(); diff --git a/packages/astro/e2e/astro-component.test.js b/packages/astro/e2e/astro-component.test.js index 0e9c1eaed4d4..d8fd4a2be5b9 100644 --- a/packages/astro/e2e/astro-component.test.js +++ b/packages/astro/e2e/astro-component.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/astro-component/' }); +const test = testFactory(import.meta.url, { root: './fixtures/astro-component/' }); let devServer; diff --git a/packages/astro/e2e/astro-envs.test.js b/packages/astro/e2e/astro-envs.test.js index f6f3c5031a4b..60baa65a0087 100644 --- a/packages/astro/e2e/astro-envs.test.js +++ b/packages/astro/e2e/astro-envs.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/astro-envs/', devToolbar: { enabled: false, diff --git a/packages/astro/e2e/client-only.test.js b/packages/astro/e2e/client-only.test.js index 08c5fb3ac575..62a05f8dc1d9 100644 --- a/packages/astro/e2e/client-only.test.js +++ b/packages/astro/e2e/client-only.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/client-only/' }); +const test = testFactory(import.meta.url, { root: './fixtures/client-only/' }); let devServer; diff --git a/packages/astro/e2e/content-collections.test.js b/packages/astro/e2e/content-collections.test.js index 63c5077c9b75..fdb8d5e00733 100644 --- a/packages/astro/e2e/content-collections.test.js +++ b/packages/astro/e2e/content-collections.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/content-collections/' }); +const test = testFactory(import.meta.url, { root: './fixtures/content-collections/' }); let devServer; diff --git a/packages/astro/e2e/css.test.js b/packages/astro/e2e/css.test.js index fd4de700e96d..f865969f7388 100644 --- a/packages/astro/e2e/css.test.js +++ b/packages/astro/e2e/css.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/css/', devToolbar: { enabled: false, diff --git a/packages/astro/e2e/custom-client-directives.test.js b/packages/astro/e2e/custom-client-directives.test.js index ef9de808a12c..8f90916f2626 100644 --- a/packages/astro/e2e/custom-client-directives.test.js +++ b/packages/astro/e2e/custom-client-directives.test.js @@ -2,7 +2,7 @@ import { expect } from '@playwright/test'; import testAdapter from '../test/test-adapter.js'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/custom-client-directives/', }); diff --git a/packages/astro/e2e/dev-toolbar-audits.test.js b/packages/astro/e2e/dev-toolbar-audits.test.js index 6ef63cc1e2d0..d0c5da847fa3 100644 --- a/packages/astro/e2e/dev-toolbar-audits.test.js +++ b/packages/astro/e2e/dev-toolbar-audits.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/dev-toolbar/', }); diff --git a/packages/astro/e2e/dev-toolbar.test.js b/packages/astro/e2e/dev-toolbar.test.js index ae8b6ef5c096..628b3af3aa80 100644 --- a/packages/astro/e2e/dev-toolbar.test.js +++ b/packages/astro/e2e/dev-toolbar.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/dev-toolbar/', }); diff --git a/packages/astro/e2e/error-cyclic.test.js b/packages/astro/e2e/error-cyclic.test.js index 84f4d1d1dce3..62b502fab95c 100644 --- a/packages/astro/e2e/error-cyclic.test.js +++ b/packages/astro/e2e/error-cyclic.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { getErrorOverlayContent, testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/error-cyclic/', }); diff --git a/packages/astro/e2e/error-sass.test.js b/packages/astro/e2e/error-sass.test.js index 11862fb86e65..05774220e37d 100644 --- a/packages/astro/e2e/error-sass.test.js +++ b/packages/astro/e2e/error-sass.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { getErrorOverlayContent, testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/error-sass/', }); diff --git a/packages/astro/e2e/errors.test.js b/packages/astro/e2e/errors.test.js index 34cecd816f56..f64a22b5cfc9 100644 --- a/packages/astro/e2e/errors.test.js +++ b/packages/astro/e2e/errors.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { getErrorOverlayContent, testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/errors/', // Only test the error overlay, don't print to console vite: { diff --git a/packages/astro/e2e/hmr.test.js b/packages/astro/e2e/hmr.test.js index 72eaf837511e..1f0cda2c4687 100644 --- a/packages/astro/e2e/hmr.test.js +++ b/packages/astro/e2e/hmr.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/hmr/', devToolbar: { enabled: false, diff --git a/packages/astro/e2e/hydration-race.test.js b/packages/astro/e2e/hydration-race.test.js index 0ee578243060..95469fe738f4 100644 --- a/packages/astro/e2e/hydration-race.test.js +++ b/packages/astro/e2e/hydration-race.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/hydration-race/', }); diff --git a/packages/astro/e2e/i18n.test.js b/packages/astro/e2e/i18n.test.js index e7d74a55184f..88d3a0b08c64 100644 --- a/packages/astro/e2e/i18n.test.js +++ b/packages/astro/e2e/i18n.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/i18n/', devToolbar: { enabled: false, diff --git a/packages/astro/e2e/lit-component.test.js b/packages/astro/e2e/lit-component.test.js index d68f5f7b8069..75cdbe1474f1 100644 --- a/packages/astro/e2e/lit-component.test.js +++ b/packages/astro/e2e/lit-component.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/lit-component/', }); diff --git a/packages/astro/e2e/multiple-frameworks.test.js b/packages/astro/e2e/multiple-frameworks.test.js index 08a2fb648694..4b52dfd4c7e0 100644 --- a/packages/astro/e2e/multiple-frameworks.test.js +++ b/packages/astro/e2e/multiple-frameworks.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/multiple-frameworks/' }); +const test = testFactory(import.meta.url, { root: './fixtures/multiple-frameworks/' }); let devServer; diff --git a/packages/astro/e2e/namespaced-component.test.js b/packages/astro/e2e/namespaced-component.test.js index 58c00713a4fb..1212e0ce151f 100644 --- a/packages/astro/e2e/namespaced-component.test.js +++ b/packages/astro/e2e/namespaced-component.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/namespaced-component/', }); diff --git a/packages/astro/e2e/nested-in-preact.test.js b/packages/astro/e2e/nested-in-preact.test.js index f2bc4d7283f1..2ad62e95f9c5 100644 --- a/packages/astro/e2e/nested-in-preact.test.js +++ b/packages/astro/e2e/nested-in-preact.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/nested-in-preact/' }); +const test = testFactory(import.meta.url, { root: './fixtures/nested-in-preact/' }); let devServer; diff --git a/packages/astro/e2e/nested-in-react.test.js b/packages/astro/e2e/nested-in-react.test.js index db9eeb0dd5aa..7dee699370eb 100644 --- a/packages/astro/e2e/nested-in-react.test.js +++ b/packages/astro/e2e/nested-in-react.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/nested-in-react/' }); +const test = testFactory(import.meta.url, { root: './fixtures/nested-in-react/' }); let devServer; diff --git a/packages/astro/e2e/nested-in-solid.test.js b/packages/astro/e2e/nested-in-solid.test.js index 0fab174688ee..2d9deade153b 100644 --- a/packages/astro/e2e/nested-in-solid.test.js +++ b/packages/astro/e2e/nested-in-solid.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/nested-in-solid/' }); +const test = testFactory(import.meta.url, { root: './fixtures/nested-in-solid/' }); let devServer; diff --git a/packages/astro/e2e/nested-in-svelte.test.js b/packages/astro/e2e/nested-in-svelte.test.js index 88aa826a87c7..eeecb0442593 100644 --- a/packages/astro/e2e/nested-in-svelte.test.js +++ b/packages/astro/e2e/nested-in-svelte.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/nested-in-svelte/' }); +const test = testFactory(import.meta.url, { root: './fixtures/nested-in-svelte/' }); let devServer; diff --git a/packages/astro/e2e/nested-in-vue.test.js b/packages/astro/e2e/nested-in-vue.test.js index deed309c7fd9..7e25e474783d 100644 --- a/packages/astro/e2e/nested-in-vue.test.js +++ b/packages/astro/e2e/nested-in-vue.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/nested-in-vue/' }); +const test = testFactory(import.meta.url, { root: './fixtures/nested-in-vue/' }); let devServer; diff --git a/packages/astro/e2e/nested-recursive.test.js b/packages/astro/e2e/nested-recursive.test.js index 262cd67723e9..d9f612642f63 100644 --- a/packages/astro/e2e/nested-recursive.test.js +++ b/packages/astro/e2e/nested-recursive.test.js @@ -3,7 +3,7 @@ import { loadFixture, waitForHydrate } from './test-utils.js'; const test = base.extend({ astro: async ({}, use) => { - const fixture = await loadFixture({ root: './fixtures/nested-recursive/' }); + const fixture = await loadFixture(import.meta.url, { root: './fixtures/nested-recursive/' }); await use(fixture); }, }); diff --git a/packages/astro/e2e/nested-styles.test.js b/packages/astro/e2e/nested-styles.test.js index c482570f09f7..1a3aeb0e0b48 100644 --- a/packages/astro/e2e/nested-styles.test.js +++ b/packages/astro/e2e/nested-styles.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/nested-styles/', devToolbar: { enabled: false, diff --git a/packages/astro/e2e/pass-js.test.js b/packages/astro/e2e/pass-js.test.js index 0db9895d1b4a..91e3b5c5e752 100644 --- a/packages/astro/e2e/pass-js.test.js +++ b/packages/astro/e2e/pass-js.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/pass-js/', }); diff --git a/packages/astro/e2e/preact-compat-component.test.js b/packages/astro/e2e/preact-compat-component.test.js index e1b603e7fb39..83831c9e77b6 100644 --- a/packages/astro/e2e/preact-compat-component.test.js +++ b/packages/astro/e2e/preact-compat-component.test.js @@ -1,6 +1,8 @@ import { prepareTestFactory } from './shared-component-tests.js'; -const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-compat-component/' }); +const { test, createTests } = prepareTestFactory(import.meta.url, { + root: './fixtures/preact-compat-component/', +}); const config = { counterComponentFilePath: './src/components/Counter.jsx', diff --git a/packages/astro/e2e/preact-component.test.js b/packages/astro/e2e/preact-component.test.js index d808b489003c..3beb14da34da 100644 --- a/packages/astro/e2e/preact-component.test.js +++ b/packages/astro/e2e/preact-component.test.js @@ -1,6 +1,8 @@ import { prepareTestFactory } from './shared-component-tests.js'; -const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-component/' }); +const { test, createTests } = prepareTestFactory(import.meta.url, { + root: './fixtures/preact-component/', +}); const config = { counterComponentFilePath: './src/components/Counter.jsx', diff --git a/packages/astro/e2e/preact-lazy-component.test.js b/packages/astro/e2e/preact-lazy-component.test.js index 585d2d347345..ce0e3afec9fe 100644 --- a/packages/astro/e2e/preact-lazy-component.test.js +++ b/packages/astro/e2e/preact-lazy-component.test.js @@ -1,6 +1,8 @@ import { prepareTestFactory } from './shared-component-tests.js'; -const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-lazy-component/' }); +const { test, createTests } = prepareTestFactory(import.meta.url, { + root: './fixtures/preact-lazy-component/', +}); const config = { counterComponentFilePath: './src/components/Counter.jsx', diff --git a/packages/astro/e2e/prefetch.test.js b/packages/astro/e2e/prefetch.test.js index 84ead590cb82..2da44189a305 100644 --- a/packages/astro/e2e/prefetch.test.js +++ b/packages/astro/e2e/prefetch.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ +const test = testFactory(import.meta.url, { root: './fixtures/prefetch/', }); diff --git a/packages/astro/e2e/react-component.test.js b/packages/astro/e2e/react-component.test.js index 361ee8d69a2a..4585887adbc6 100644 --- a/packages/astro/e2e/react-component.test.js +++ b/packages/astro/e2e/react-component.test.js @@ -1,7 +1,9 @@ import { expect } from '@playwright/test'; import { prepareTestFactory } from './shared-component-tests.js'; -const { test, createTests } = prepareTestFactory({ root: './fixtures/react-component/' }); +const { test, createTests } = prepareTestFactory(import.meta.url, { + root: './fixtures/react-component/', +}); const config = { counterComponentFilePath: './src/components/Counter.jsx', diff --git a/packages/astro/e2e/server-islands.test.js b/packages/astro/e2e/server-islands.test.js index 496cf229cc50..ae8f95b86779 100644 --- a/packages/astro/e2e/server-islands.test.js +++ b/packages/astro/e2e/server-islands.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/server-islands/' }); +const test = testFactory(import.meta.url, { root: './fixtures/server-islands/' }); test.describe('Server islands', () => { test.describe('Development', () => { diff --git a/packages/astro/e2e/shared-component-tests.js b/packages/astro/e2e/shared-component-tests.js index 024f1aade832..ea45da13b6d9 100644 --- a/packages/astro/e2e/shared-component-tests.js +++ b/packages/astro/e2e/shared-component-tests.js @@ -1,8 +1,8 @@ import { expect } from '@playwright/test'; import { scrollToElement, testFactory, waitForHydrate } from './test-utils.js'; -export function prepareTestFactory(opts, { canReplayClicks = false } = {}) { - const test = testFactory(opts); +export function prepareTestFactory(testFile, opts, { canReplayClicks = false } = {}) { + const test = testFactory(testFile, opts); let devServer; @@ -120,6 +120,7 @@ export function prepareTestFactory(opts, { canReplayClicks = false } = {}) { await page.goto(astro.resolveUrl(pageUrl)); const label = page.locator('#client-only'); + await waitForHydrate(page, label); await expect(label, 'component is visible').toBeVisible(); await expect(label, 'slot text is visible').toHaveText('Framework client:only component'); diff --git a/packages/astro/e2e/solid-circular.test.js b/packages/astro/e2e/solid-circular.test.js index 5dd0e8b80cca..796800a211e8 100644 --- a/packages/astro/e2e/solid-circular.test.js +++ b/packages/astro/e2e/solid-circular.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/solid-circular/' }); +const test = testFactory(import.meta.url, { root: './fixtures/solid-circular/' }); let devServer; diff --git a/packages/astro/e2e/solid-component.test.js b/packages/astro/e2e/solid-component.test.js index b998d1873236..6a934b1c4fc8 100644 --- a/packages/astro/e2e/solid-component.test.js +++ b/packages/astro/e2e/solid-component.test.js @@ -1,6 +1,7 @@ import { prepareTestFactory } from './shared-component-tests.js'; const { test, createTests } = prepareTestFactory( + import.meta.url, { root: './fixtures/solid-component/' }, { canReplayClicks: true, diff --git a/packages/astro/e2e/solid-recurse.test.js b/packages/astro/e2e/solid-recurse.test.js index de3759e9856b..eb0fa3770747 100644 --- a/packages/astro/e2e/solid-recurse.test.js +++ b/packages/astro/e2e/solid-recurse.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/solid-recurse/' }); +const test = testFactory(import.meta.url, { root: './fixtures/solid-recurse/' }); let devServer; diff --git a/packages/astro/e2e/svelte-component.test.js b/packages/astro/e2e/svelte-component.test.js index 01c7aa41dafc..d72235797c82 100644 --- a/packages/astro/e2e/svelte-component.test.js +++ b/packages/astro/e2e/svelte-component.test.js @@ -2,7 +2,9 @@ import { expect } from '@playwright/test'; import { prepareTestFactory } from './shared-component-tests.js'; import { waitForHydrate } from './test-utils.js'; -const { test, createTests } = prepareTestFactory({ root: './fixtures/svelte-component/' }); +const { test, createTests } = prepareTestFactory(import.meta.url, { + root: './fixtures/svelte-component/', +}); const config = { componentFilePath: './src/components/SvelteComponent.svelte', diff --git a/packages/astro/e2e/tailwindcss.test.js b/packages/astro/e2e/tailwindcss.test.js index e58e10dfde74..c86d01b0e2fe 100644 --- a/packages/astro/e2e/tailwindcss.test.js +++ b/packages/astro/e2e/tailwindcss.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory } from './test-utils.js'; -const test = testFactory({ root: './fixtures/tailwindcss/' }); +const test = testFactory(import.meta.url, { root: './fixtures/tailwindcss/' }); let devServer; diff --git a/packages/astro/e2e/test-utils.js b/packages/astro/e2e/test-utils.js index 48fcd17bd77e..933186a7181e 100644 --- a/packages/astro/e2e/test-utils.js +++ b/packages/astro/e2e/test-utils.js @@ -14,30 +14,40 @@ const testFileToPort = new Map(); for (let i = 0; i < testFiles.length; i++) { const file = testFiles[i]; if (file.endsWith('.test.js')) { - testFileToPort.set(file.slice(0, -8), 4000 + i); + testFileToPort.set(file, 4000 + i); } } -export function loadFixture(inlineConfig) { +export function loadFixture(testFile, inlineConfig) { if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); + const port = testFileToPort.get(path.basename(testFile)); + // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` return baseLoadFixture({ ...inlineConfig, root: fileURLToPath(new URL(inlineConfig.root, import.meta.url)), server: { - port: testFileToPort.get(path.basename(inlineConfig.root)), + ...inlineConfig?.server, + port, + }, + vite: { + ...inlineConfig?.vite, + server: { + ...inlineConfig?.vite?.server, + strictPort: true, + }, }, }); } -export function testFactory(inlineConfig) { +export function testFactory(testFile, inlineConfig) { let fixture; const test = testBase.extend({ astro: async ({}, use) => { - fixture = fixture || (await loadFixture(inlineConfig)); + fixture = fixture || (await loadFixture(testFile, inlineConfig)); await use(fixture); }, }); diff --git a/packages/astro/e2e/ts-resolution.test.js b/packages/astro/e2e/ts-resolution.test.js index d2d3fcfe8bf1..256269542f4f 100644 --- a/packages/astro/e2e/ts-resolution.test.js +++ b/packages/astro/e2e/ts-resolution.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/ts-resolution/' }); +const test = testFactory(import.meta.url, { root: './fixtures/ts-resolution/' }); function runTest(it) { it('client:idle', async ({ page, astro }) => { diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index 135ec5571ab8..822a57d89447 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -1,7 +1,7 @@ import { expect } from '@playwright/test'; import { testFactory, waitForHydrate } from './test-utils.js'; -const test = testFactory({ root: './fixtures/view-transitions/' }); +const test = testFactory(import.meta.url, { root: './fixtures/view-transitions/' }); let devServer; @@ -447,7 +447,9 @@ test.describe('View Transitions', () => { expect(consoleCount).toEqual(1); // forward '' to 'hash' (no transition) - await page.goForward(); + // NOTE: the networkidle below is needed for Firefox to consistently + // pass the `#longpage` viewport check below + await page.goForward({ waitUntil: 'networkidle' }); locator = page.locator('#click-one-again'); await expect(locator).toBeInViewport(); expect(consoleCount).toEqual(1); diff --git a/packages/astro/e2e/vue-component.test.js b/packages/astro/e2e/vue-component.test.js index 3be31af85fc9..034fe5a6effe 100644 --- a/packages/astro/e2e/vue-component.test.js +++ b/packages/astro/e2e/vue-component.test.js @@ -1,6 +1,8 @@ import { expect } from '@playwright/test'; import { prepareTestFactory } from './shared-component-tests.js'; -const { test, createTests } = prepareTestFactory({ root: './fixtures/vue-component/' }); +const { test, createTests } = prepareTestFactory(import.meta.url, { + root: './fixtures/vue-component/', +}); const config = { componentFilePath: './src/components/VueComponent.vue', diff --git a/packages/astro/playwright.config.js b/packages/astro/playwright.config.js index 2209a5c27f7c..26572c66c872 100644 --- a/packages/astro/playwright.config.js +++ b/packages/astro/playwright.config.js @@ -1,4 +1,5 @@ import { defineConfig } from '@playwright/test'; + // NOTE: Sometimes, tests fail with `TypeError: process.stdout.clearLine is not a function` // for some reason. This comes from Vite, and is conditionally called based on `isTTY`. // We set it to false here to skip this odd behavior. @@ -6,35 +7,16 @@ process.stdout.isTTY = false; export default defineConfig({ testMatch: 'e2e/*.test.js', - /* Maximum time one test can run for. */ - timeout: 40 * 1000, - expect: { - /** - * Maximum time expect() should wait for the condition to be met. - * For example in `await expect(locator).toHaveText();` - */ - timeout: 6 * 1000, - }, - /* Fail the build on CI if you accidentally left test in the source code. */ + timeout: 40000, forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 3 : 0, - /* Opt out of parallel tests on CI. */ - workers: 1, - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ - actionTimeout: 0, - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, projects: [ { name: 'Chrome Stable', use: { browserName: 'chromium', channel: 'chrome', - args: ['--use-gl=egl'], }, }, ], diff --git a/packages/astro/playwright.firefox.config.js b/packages/astro/playwright.firefox.config.js index 77c16ed48c7f..00b82d999786 100644 --- a/packages/astro/playwright.firefox.config.js +++ b/packages/astro/playwright.firefox.config.js @@ -1,43 +1,24 @@ +import { defineConfig } from '@playwright/test'; + // NOTE: Sometimes, tests fail with `TypeError: process.stdout.clearLine is not a function` // for some reason. This comes from Vite, and is conditionally called based on `isTTY`. // We set it to false here to skip this odd behavior. process.stdout.isTTY = false; -const config = { +export default defineConfig({ // TODO: add more tests like view transitions and audits, and fix them. Some of them are failing. testMatch: ['e2e/css.test.js', 'e2e/prefetch.test.js', 'e2e/view-transitions.test.js'], - /* Maximum time one test can run for. */ - timeout: 40 * 1000, - expect: { - /** - * Maximum time expect() should wait for the condition to be met. - * For example in `await expect(locator).toHaveText();` - */ - timeout: 6 * 1000, - }, - /* Fail the build on CI if you accidentally left test in the source code. */ + timeout: 40000, forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 3 : 0, - /* Opt out of parallel tests on CI. */ - workers: 1, - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ - actionTimeout: 0, - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, projects: [ { name: 'Firefox Stable', use: { browserName: 'firefox', channel: 'firefox', - args: ['--use-gl=egl'], }, }, ], -}; - -export default config; +});