diff options
author | 2024-08-28 00:00:19 +0800 | |
---|---|---|
committer | 2024-08-28 00:00:19 +0800 | |
commit | ccce6d2061c4653d285a31164ac1b84073b73f31 (patch) | |
tree | 5c7009fe484b5a0d33cea2691ac1b1cdeefd2dc3 | |
parent | b601e47aff5e3c36fea0ca18f28dc5c785e1cba8 (diff) | |
download | astro-ccce6d2061c4653d285a31164ac1b84073b73f31.tar.gz astro-ccce6d2061c4653d285a31164ac1b84073b73f31.tar.zst astro-ccce6d2061c4653d285a31164ac1b84073b73f31.zip |
Improve e2e setup (#11850)
Diffstat (limited to '')
45 files changed, 97 insertions, 106 deletions
diff --git a/packages/astro/e2e/actions-blog.test.js b/packages/astro/e2e/actions-blog.test.js index 1631f7dfe..d9c1bc1df 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 5ce72a419..3298db1e3 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 0e9c1eaed..d8fd4a2be 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 f6f3c5031..60baa65a0 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 08c5fb3ac..62a05f8dc 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 63c5077c9..fdb8d5e00 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 fd4de700e..f865969f7 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 ef9de808a..8f90916f2 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 6ef63cc1e..d0c5da847 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 ae8b6ef5c..628b3af3a 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 84f4d1d1d..62b502fab 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 11862fb86..05774220e 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 34cecd816..f64a22b5c 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 72eaf8375..1f0cda2c4 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 0ee578243..95469fe73 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 e7d74a551..88d3a0b08 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 d68f5f7b8..75cdbe147 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 08a2fb648..4b52dfd4c 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 58c00713a..1212e0ce1 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 f2bc4d728..2ad62e95f 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 db9eeb0dd..7dee69937 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 0fab17468..2d9deade1 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 88aa826a8..eeecb0442 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 deed309c7..7e25e4747 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 262cd6772..d9f612642 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 c482570f0..1a3aeb0e0 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 0db9895d1..91e3b5c5e 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 e1b603e7f..83831c9e7 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 d808b4890..3beb14da3 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 585d2d347..ce0e3afec 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 84ead590c..2da44189a 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 361ee8d69..4585887ad 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 496cf229c..ae8f95b86 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 024f1aade..ea45da13b 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 5dd0e8b80..796800a21 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 b998d1873..6a934b1c4 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 de3759e98..eb0fa3770 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 01c7aa41d..d72235797 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 e58e10dfd..c86d01b0e 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 48fcd17bd..933186a71 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 d2d3fcfe8..256269542 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 135ec5571..822a57d89 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 3be31af85..034fe5a6e 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 2209a5c27..26572c66c 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 77c16ed48..00b82d999 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; +}); |