From d4e71867af43677767825b61bd38b414c73f1760 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 23 Dec 2024 16:18:34 +0000 Subject: [PATCH] Test utils fixes --- packages/astro/e2e/actions-blog.test.js | 5 +---- packages/astro/e2e/actions-react-19.test.js | 5 +---- packages/astro/test/test-utils.js | 5 +++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/astro/e2e/actions-blog.test.js b/packages/astro/e2e/actions-blog.test.js index ebbffc3b07..03e0c20575 100644 --- a/packages/astro/e2e/actions-blog.test.js +++ b/packages/astro/e2e/actions-blog.test.js @@ -14,16 +14,13 @@ test.afterAll(async () => { }); test.afterEach(async ({ astro }) => { - // Allow time for fs events to flush - await new Promise(resolve => setTimeout(resolve, 500)) // Force database reset between tests - await astro.editFile('./db/seed.ts', (original) => original); + await astro.editFile('./db/seed.ts', (original) => original, false); }); test.describe('Astro Actions - Blog', () => { test('Like action', async ({ page, astro }) => { await page.goto(astro.resolveUrl('/blog/first-post/')); - const likeButton = page.getByLabel('Like'); await waitForHydrate(page, likeButton); await new Promise(resolve => setTimeout(resolve, 500)) diff --git a/packages/astro/e2e/actions-react-19.test.js b/packages/astro/e2e/actions-react-19.test.js index e6063dea71..d0274e43f2 100644 --- a/packages/astro/e2e/actions-react-19.test.js +++ b/packages/astro/e2e/actions-react-19.test.js @@ -7,14 +7,11 @@ let devServer; test.beforeAll(async ({ astro }) => { devServer = await astro.startDevServer(); - }); test.afterEach(async ({ astro }) => { - // Allow time for fs events to flush - await new Promise(resolve => setTimeout(resolve, 500)) // Force database reset between tests - await astro.editFile('./db/seed.ts', (original) => original); + await astro.editFile('./db/seed.ts', (original) => original, false); }); test.afterAll(async () => { diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index f0bdf8542f..246d152327 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -181,6 +181,7 @@ export async function loadFixture(inlineConfig) { devServer = await dev(mergeConfig(inlineConfig, extraInlineConfig)); config.server.host = parseAddressToHost(devServer.address.address); // update host config.server.port = devServer.address.port; // update port + await new Promise(resolve => setTimeout(resolve, 100)) return devServer; }, onNextDataStoreChange: (timeout = 5000) => { @@ -284,7 +285,7 @@ export async function loadFixture(inlineConfig) { app.manifest = manifest; return app; }, - editFile: async (filePath, newContentsOrCallback) => { + editFile: async (filePath, newContentsOrCallback, waitForNextWrite = true) => { const fileUrl = new URL(filePath.replace(/^\//, ''), config.root); const contents = await fs.promises.readFile(fileUrl, 'utf-8'); const reset = () => { @@ -299,7 +300,7 @@ export async function loadFixture(inlineConfig) { typeof newContentsOrCallback === 'function' ? newContentsOrCallback(contents) : newContentsOrCallback; - const nextChange = devServer ? onNextChange() : Promise.resolve(); + const nextChange = devServer && waitForNextWrite ? onNextChange() : Promise.resolve(); await fs.promises.writeFile(fileUrl, newContents); await nextChange; return reset;