Skip to content

Commit

Permalink
test: fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin-LL committed Sep 12, 2023
1 parent 7644dff commit 5873de1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/components/layout/FullScreenCenter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ const topBarHeight = ref(0);
onMounted(() => {
window.addEventListener("resize", updateHeight);
updateHeight();
// add this to let the test know that the component is loaded
document.body.dataset.loaded = "";
});
onBeforeUnmount(() => {
Expand Down
24 changes: 16 additions & 8 deletions tests/e2e/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ test("encrypt then decrypt text", async ({ page, context }) => {
.getAttribute("href");
const encryptPage = await context.newPage();
encryptPage.on("console", console.log);
await encryptPage.goto(encryptLink!);
await encryptPage.waitForSelector("body[data-loaded]");
await astroGoto(encryptPage, encryptLink!);

const message =
"!#$%&()*MNOPQRSTUVWXYZ[]^_`abcdefghijklmnz{|}~☇☈☉☊☋☌☍☎☏☐☑☒☓☚☛☜☝☞☟☠☡☢☣☤☥买乱乲乳乴乵乶乷乸乹乺乻乼乽癩羅蘿螺裸邏樂洛烙珞落酪駱亂👩🏼‍🦯👩‍❤️‍👨👩‍❤️‍👩👨‍❤️‍👨👩‍❤️‍💋‍👨👩‍❤️‍💋‍👩👨‍👩‍👦👨‍❤️‍💋‍👨👨‍👩‍👧👩‍👩‍👧‍👧👩‍👦👗👮🏿‍♀️👮🏿👮🏽‍♂️";
Expand All @@ -63,8 +62,7 @@ test("encrypt then decrypt text", async ({ page, context }) => {
.getAttribute("href");
const decryptPage = await context.newPage();
decryptPage.on("console", console.log);
await decryptPage.goto(decryptLink!);
await decryptPage.waitForSelector("body[data-loaded]");
await astroGoto(decryptPage, decryptLink!);

await decryptPage.locator("textarea:not([readonly])").type(encryptedMessage);

Expand Down Expand Up @@ -95,8 +93,7 @@ test("encrypt then decrypt files", async ({ page, context }) => {
.getAttribute("href");
const encryptPage = await context.newPage();
encryptPage.on("console", console.log);
await encryptPage.goto(encryptLink!);
await encryptPage.waitForSelector("body[data-loaded]");
await astroGoto(encryptPage, encryptLink!);

const file1Content = "test1";
const file2Content = "test2";
Expand Down Expand Up @@ -128,8 +125,7 @@ test("encrypt then decrypt files", async ({ page, context }) => {
.getAttribute("href");
const decryptPage = await context.newPage();
decryptPage.on("console", console.log);
await decryptPage.goto(decryptLink!);
await decryptPage.waitForSelector("body[data-loaded]");
await astroGoto(decryptPage, decryptLink!);

const [encryptedFileChooser] = await Promise.all([
decryptPage.waitForEvent("filechooser"),
Expand Down Expand Up @@ -217,3 +213,15 @@ async function readStreamToBuffer(

return Buffer.concat(chunks);
}

/**
* returns a promise that resolves when the page and all astro components have loaded
*/
async function astroGoto(page: Page, path: string) {
await Promise.all([
page.waitForFunction(
() => document.querySelectorAll("astro-island[ssr]").length === 0
),
page.goto(path),
]);
}

0 comments on commit 5873de1

Please sign in to comment.