Skip to content

Commit

Permalink
Test utils fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Dec 23, 2024
1 parent d987618 commit 224ccb6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
6 changes: 1 addition & 5 deletions packages/astro/e2e/actions-blog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ 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))
await expect(likeButton, 'like button starts with 10 likes').toContainText('10');
await likeButton.click();
await expect(likeButton, 'like button should increment likes').toContainText('11');
Expand Down
6 changes: 1 addition & 5 deletions packages/astro/e2e/actions-react-19.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -26,7 +23,6 @@ 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 new Promise(resolve => setTimeout(resolve, 500))

await expect(likeButton).toBeVisible();
await likeButton.click();
Expand Down
5 changes: 3 additions & 2 deletions packages/astro/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 = () => {
Expand All @@ -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;
Expand Down

0 comments on commit 224ccb6

Please sign in to comment.