Skip to content

Commit

Permalink
Fixed too fast e2e auth tests (😱) and updated playwright config for q…
Browse files Browse the repository at this point in the history
…uicker timeouts
  • Loading branch information
derwebcoder committed Aug 29, 2024
1 parent c4e0b49 commit ad5c68d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
11 changes: 7 additions & 4 deletions e2e/pages/AuthPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ export class AuthPage {
}

async clearLocalStorage() {
await this.page.evaluate(() => localStorage.clear());
await this.page.waitForFunction(() => {
localStorage.clear();
return true;
});
}

async hasLocalStorageSecret() {
return await this.page.evaluate(
() => localStorage.getItem("notSoSecretSecret") !== null,
);
return await this.page.evaluate(() => {
return localStorage.getItem("notSoSecretSecret") !== null;
});
}
}
6 changes: 5 additions & 1 deletion e2e/pages/MainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ export class MainPage {
constructor(public readonly page: Page) {
this.noteInput = page.getByLabel("New spark");
this.submitButton = page.getByRole("button", { name: "Add" });
this.sparkList = page.getByRole("list", { name: "Sparks" });
this.sparkList = page
.getByText("Sparks")
.locator("..") // parent node
.getByRole("list");
}

async goto() {
const url = createUrl();
await this.page.goto(url);
await authenticate(this.page);
await this.page.goto(url);
}

async fillNote(password: string) {
Expand Down
14 changes: 12 additions & 2 deletions e2e/tests/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ test.describe("Auth", () => {
expect(process.env.NOT_SO_SECRET_SECRET).not.toBe(undefined);
}

// needed because astro hydration is sometimes not fast enough
// and then the form submits with the usual GET behavior
// This timeout should allow the hydration to finish
await authPage.page.waitForTimeout(1000);

await authPage.enterPassword(process.env.NOT_SO_SECRET_SECRET ?? "");
await authPage.submit();
// Expect a title "to contain" a substring.

await expect(await authPage.hasLocalStorageSecret()).toBe(true);
});

test("shows error for wrong secret", async ({ authPage }) => {
await authPage.enterPassword("wrong-secret");
await authPage.submit();
// Expect a title "to contain" a substring.

// needed because astro hydration is sometimes not fast enough
// and then the form submits with the usual GET behavior
// This timeout should allow the hydration to finish
await authPage.page.waitForTimeout(1000);

await expect(await authPage.getErrorMessage()).toBe(
"😢 Sadly that is not correct.",
);
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export default defineConfig({
reuseExistingServer: !process.env.CI,
},

timeout: 3000,
timeout: 6000,
expect: {
timeout: 3000,
timeout: 6000,
},
});

0 comments on commit ad5c68d

Please sign in to comment.