Skip to content

Commit

Permalink
feat(e2e): Add document font ready
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilsang committed May 7, 2024
1 parent 9098dbc commit 8fde3bf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions e2e/404.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MACRO_SUITE } from './shared/constants';

test.describe('404', () => {
test('should redirect 404', async ({ page }) => {
await gotoUrl({ page, url: '/something_wrong_path' });
await gotoUrl({ page, url: '/something_wrong_path', timeout: 60_000 });
await expect(page.getByText(/404 ERROR/)).toBeVisible();
});

Expand All @@ -13,7 +13,7 @@ test.describe('404', () => {
});

test(MACRO_SUITE.DOM_SNAPSHOT, async ({ page }) => {
await gotoUrl({ page, url: '/404' });
await gotoUrl({ page, url: '/404', timeout: 60_000 });
await waitImages({ page });
const body = await page.locator('#__next').innerHTML();
expect(body).toMatchSnapshot([`404.html`]);
Expand Down
1 change: 0 additions & 1 deletion e2e/post/dom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ test.describe(MACRO_SUITE.DOM_SNAPSHOT, () => {

test(`${url}`, async ({ page }) => {
await gotoUrl({ page, url: `/posts/${url}` });
await page.evaluate(() => document.fonts.ready);
const body = await page.locator('#__next').innerHTML();
expect(body).toMatchSnapshot([`${url}.html`]);
});
Expand Down
1 change: 0 additions & 1 deletion e2e/posts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { gotoUrl } from './shared/utils';
test.describe('posts', () => {
test(MACRO_SUITE.DOM_SNAPSHOT, async ({ page }) => {
await gotoUrl({ page, url: '/posts' });
await page.evaluate(() => document.fonts.ready);
const body = await page.locator('#__next').innerHTML();
expect(body).toMatchSnapshot([`posts.html`]);
});
Expand Down
15 changes: 11 additions & 4 deletions e2e/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ type ScreenshotOptions = {
clip?: { x: number; y: number; width: number; height: number };
};

export const gotoUrl = async ({ page, url }: { page: Page; url: string }) => {
// https://stackoverflow.com/a/78183950
await page.goto(url, { waitUntil: 'domcontentloaded' });
export const gotoUrl = async ({
page,
url,
timeout = 30_000,
}: {
page: Page;
url: string;
timeout?: number;
}) => {
await page.goto(url, { timeout });
await page.evaluate(() => document.fonts.ready);
};

export const waitImages = async ({ page }: { page: Page }) => {
Expand Down Expand Up @@ -37,7 +45,6 @@ export const screenshotFullPage = async ({
timeout?: number;
}) => {
await gotoUrl({ page, url });
await page.evaluate(() => document.fonts.ready);

await waitImages({ page });

Expand Down

0 comments on commit 8fde3bf

Please sign in to comment.