Skip to content

Commit

Permalink
dump
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilsang committed May 3, 2024
1 parent c960d30 commit 59d2944
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 10 deletions.
4 changes: 2 additions & 2 deletions e2e/404.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from '@playwright/test';
import { screenshotFullPage } from './utils';

test.describe('404', () => {
test('should redirect 404', async ({ page }) => {
Expand All @@ -7,8 +8,7 @@ test.describe('404', () => {
});

test(`screen`, async ({ page }) => {
await page.goto(`/404`);
await expect(page).toHaveScreenshot([`404.png`], { fullPage: true });
await screenshotFullPage({ page, url: `/404`, arg: [`404.png`] });
});

test(`dom`, async ({ page }) => {
Expand Down
Binary file modified e2e/__snapshots__/about.spec.ts/desktop/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/about.spec.ts/mobile/about.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/desktop/goorm-195693.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/desktop/goorm-195696.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/desktop/implicit-coercion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/desktop/mac-init-apps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/desktop/mdn-ko-organizer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/desktop/storybook7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/mobile/goorm-195687.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/mobile/goorm-195693.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/mobile/turborepo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/__snapshots__/post/screen.spec.ts/mobile/use-prevent-leave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions e2e/about.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, test } from '@playwright/test';
import { screenshotFullPage } from './utils';

test.describe('about', () => {
test(`screen`, async ({ page }) => {
await page.goto(`/about`);
await expect(page).toHaveScreenshot([`about.png`], { fullPage: true });
await screenshotFullPage({ page, url: `/about`, arg: [`about.png`] });
});

test(`dom`, async ({ page }) => {
Expand Down
12 changes: 7 additions & 5 deletions e2e/post/screen.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { expect, test } from '@playwright/test';
import { test } from '@playwright/test';
import { urls } from './utils';
import { screenshotFullPage } from 'e2e/utils';

test.describe(`screen`, () => {
for (let i = 0; i < 10; i++) {
for (let i = 0; i < urls.length; i++) {
const url = urls[i];

test(`${url}`, async ({ page }) => {
await page.goto(`/posts/${url}`);
await expect(page).toHaveScreenshot([`${url}.png`], {
fullPage: true,
await screenshotFullPage({
page,
url: `/posts/${url}`,
arg: [`${url}.png`],
timeout: 10 * 1000,
});
});
Expand Down
40 changes: 40 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, type Page } from '@playwright/test';

type ScreenshotOptions = {
fullPage: boolean;
timeout?: number;
clip: { x: number; y: number; width: number; height: number };
};

export const screenshotFullPage = async ({
page,
url,
arg,
timeout,
}: {
page: Page;
url: string;
arg: string[];
timeout?: number;
}) => {
await page.goto(url);
await page.evaluate(() => document.fonts.ready);
// https://github.com/microsoft/playwright/issues/18827#issuecomment-2031261562
await page.locator('#__next').scrollIntoViewIfNeeded();
await page.waitForTimeout(1000);

const { width } = page.viewportSize();
const height = await page.evaluate(
() => document.scrollingElement.scrollHeight,
);

const options: ScreenshotOptions = {
fullPage: true,
clip: { x: 0, y: 0, width, height },
};
if (timeout >= 0) {
options.timeout = timeout;
}

await expect(page).toHaveScreenshot([...arg], options);
};
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default defineConfig({
/* For global expect settings */
expect: {
toHaveScreenshot: {
maxDiffPixelRatio: 0.2,
maxDiffPixelRatio: 0.1,
},
},
});

0 comments on commit 59d2944

Please sign in to comment.