diff options
-rw-r--r-- | packages/astro/e2e/multiple-frameworks.test.js | 11 | ||||
-rw-r--r-- | packages/astro/playwright.config.js | 65 | ||||
-rw-r--r-- | packages/astro/test/test-utils.js | 15 |
3 files changed, 48 insertions, 43 deletions
diff --git a/packages/astro/e2e/multiple-frameworks.test.js b/packages/astro/e2e/multiple-frameworks.test.js index 6f3906400..d24225d50 100644 --- a/packages/astro/e2e/multiple-frameworks.test.js +++ b/packages/astro/e2e/multiple-frameworks.test.js @@ -101,7 +101,6 @@ test.describe('Multiple frameworks', () => { await expect(aComponent, 'component is visible').toBeVisible(); await expect(aComponent, 'component text is visible').toHaveText('Hello Astro (A)'); - const bComponent = await page.locator('#astro-b'); await expect(bComponent, 'component is visible').toBeVisible(); await expect(bComponent, 'component text is visible').toHaveText('Hello Astro (B)'); @@ -130,12 +129,18 @@ test.describe('Multiple frameworks', () => { // Edit the svelte component's style const svelteCounter = page.locator('#svelte-counter'); - await expect(svelteCounter, 'initial background is white').toHaveCSS('background-color', 'rgb(255, 255, 255)'); + await expect(svelteCounter, 'initial background is white').toHaveCSS( + 'background-color', + 'rgb(255, 255, 255)' + ); await astro.editFile('./src/components/SvelteCounter.svelte', (content) => content.replace('background: white', 'background: rgb(230, 230, 230)') ); - await expect(svelteCounter, 'background color updated').toHaveCSS('background-color', 'rgb(230, 230, 230)'); + await expect(svelteCounter, 'background color updated').toHaveCSS( + 'background-color', + 'rgb(230, 230, 230)' + ); }); }); diff --git a/packages/astro/playwright.config.js b/packages/astro/playwright.config.js index 8c13d8ef9..88c2f4b8e 100644 --- a/packages/astro/playwright.config.js +++ b/packages/astro/playwright.config.js @@ -3,40 +3,39 @@ import { devices } from '@playwright/test'; const config = { testMatch: 'e2e/*.test.js', /* Maximum time one test can run for. */ - timeout: 30 * 1000, - expect: { - /** - * Maximum time expect() should wait for the condition to be met. - * For example in `await expect(locator).toHaveText();` - */ - timeout: 5000 - }, - /* Fail the build on CI if you accidentally left test in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, - /* 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, - /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:3000', - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, - projects: [ - { - name: 'Chrome Stable', - use: { - browserName: 'chromium', - channel: 'chrome', - }, - }, - ], + timeout: 30 * 1000, + expect: { + /** + * Maximum time expect() should wait for the condition to be met. + * For example in `await expect(locator).toHaveText();` + */ + timeout: 5000, + }, + /* Fail the build on CI if you accidentally left test in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* 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, + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:3000', + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + projects: [ + { + name: 'Chrome Stable', + use: { + browserName: 'chromium', + channel: 'chrome', + }, + }, + ], }; export default config; diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index 8fd5393c0..afac6e250 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -98,7 +98,7 @@ export async function loadFixture(inlineConfig) { const resolveUrl = (url) => `http://${'127.0.0.1'}:${config.server.port}${url.replace(/^\/?/, '/')}`; - + // A map of files that have been editted. let fileEdits = new Map(); @@ -112,7 +112,7 @@ export async function loadFixture(inlineConfig) { const onNextChange = () => devServer ? new Promise((resolve) => devServer.watcher.once('change', resolve)) - : Promise.reject(new Error('No dev server running')) + : Promise.reject(new Error('No dev server running')); // After each test, reset each of the edits to their original contents. if (typeof afterEach === 'function') { @@ -155,21 +155,22 @@ export async function loadFixture(inlineConfig) { const contents = await fs.promises.readFile(fileUrl, 'utf-8'); const reset = () => { fs.writeFileSync(fileUrl, contents); - } + }; // Only save this reset if not already in the map, in case multiple edits happen // to the same file. if (!fileEdits.has(fileUrl.toString())) { fileEdits.set(fileUrl.toString(), reset); } - const newContents = typeof newContentsOrCallback === 'function' - ? newContentsOrCallback(contents) - : newContentsOrCallback; + const newContents = + typeof newContentsOrCallback === 'function' + ? newContentsOrCallback(contents) + : newContentsOrCallback; const nextChange = onNextChange(); await fs.promises.writeFile(fileUrl, newContents); await nextChange; return reset; }, - resetAllFiles + resetAllFiles, }; } |