mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -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 }) => {
|
||||
// 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))
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue