mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
Test utils fixes
This commit is contained in:
parent
d9876187ab
commit
d4e71867af
3 changed files with 5 additions and 10 deletions
|
@ -14,16 +14,13 @@ test.afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test.afterEach(async ({ astro }) => {
|
test.afterEach(async ({ astro }) => {
|
||||||
// Allow time for fs events to flush
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500))
|
|
||||||
// Force database reset between tests
|
// 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.describe('Astro Actions - Blog', () => {
|
||||||
test('Like action', async ({ page, astro }) => {
|
test('Like action', async ({ page, astro }) => {
|
||||||
await page.goto(astro.resolveUrl('/blog/first-post/'));
|
await page.goto(astro.resolveUrl('/blog/first-post/'));
|
||||||
|
|
||||||
const likeButton = page.getByLabel('Like');
|
const likeButton = page.getByLabel('Like');
|
||||||
await waitForHydrate(page, likeButton);
|
await waitForHydrate(page, likeButton);
|
||||||
await new Promise(resolve => setTimeout(resolve, 500))
|
await new Promise(resolve => setTimeout(resolve, 500))
|
||||||
|
|
|
@ -7,14 +7,11 @@ let devServer;
|
||||||
|
|
||||||
test.beforeAll(async ({ astro }) => {
|
test.beforeAll(async ({ astro }) => {
|
||||||
devServer = await astro.startDevServer();
|
devServer = await astro.startDevServer();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test.afterEach(async ({ astro }) => {
|
test.afterEach(async ({ astro }) => {
|
||||||
// Allow time for fs events to flush
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500))
|
|
||||||
// Force database reset between tests
|
// 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 () => {
|
test.afterAll(async () => {
|
||||||
|
|
|
@ -181,6 +181,7 @@ export async function loadFixture(inlineConfig) {
|
||||||
devServer = await dev(mergeConfig(inlineConfig, extraInlineConfig));
|
devServer = await dev(mergeConfig(inlineConfig, extraInlineConfig));
|
||||||
config.server.host = parseAddressToHost(devServer.address.address); // update host
|
config.server.host = parseAddressToHost(devServer.address.address); // update host
|
||||||
config.server.port = devServer.address.port; // update port
|
config.server.port = devServer.address.port; // update port
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100))
|
||||||
return devServer;
|
return devServer;
|
||||||
},
|
},
|
||||||
onNextDataStoreChange: (timeout = 5000) => {
|
onNextDataStoreChange: (timeout = 5000) => {
|
||||||
|
@ -284,7 +285,7 @@ export async function loadFixture(inlineConfig) {
|
||||||
app.manifest = manifest;
|
app.manifest = manifest;
|
||||||
return app;
|
return app;
|
||||||
},
|
},
|
||||||
editFile: async (filePath, newContentsOrCallback) => {
|
editFile: async (filePath, newContentsOrCallback, waitForNextWrite = true) => {
|
||||||
const fileUrl = new URL(filePath.replace(/^\//, ''), config.root);
|
const fileUrl = new URL(filePath.replace(/^\//, ''), config.root);
|
||||||
const contents = await fs.promises.readFile(fileUrl, 'utf-8');
|
const contents = await fs.promises.readFile(fileUrl, 'utf-8');
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
|
@ -299,7 +300,7 @@ export async function loadFixture(inlineConfig) {
|
||||||
typeof newContentsOrCallback === 'function'
|
typeof newContentsOrCallback === 'function'
|
||||||
? newContentsOrCallback(contents)
|
? newContentsOrCallback(contents)
|
||||||
: newContentsOrCallback;
|
: newContentsOrCallback;
|
||||||
const nextChange = devServer ? onNextChange() : Promise.resolve();
|
const nextChange = devServer && waitForNextWrite ? onNextChange() : Promise.resolve();
|
||||||
await fs.promises.writeFile(fileUrl, newContents);
|
await fs.promises.writeFile(fileUrl, newContents);
|
||||||
await nextChange;
|
await nextChange;
|
||||||
return reset;
|
return reset;
|
||||||
|
|
Loading…
Reference in a new issue