Skip to content

Commit

Permalink
Added screenshot testing to /nodebuds
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Oct 12, 2022
1 parent a39fff3 commit e708ba4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/routes/(site)/nodebuds/page.test.ts
@@ -1,8 +1,58 @@
import type { TestInfo } from '@playwright/test';
import { expect, test } from '@playwright/test';
import path from 'node:path';

test.describe.configure({ mode: 'parallel' });

// setupSnapshot is a helper that creates handles the necessary boilerplate
// for snapshot testing. It returns a function that can be called after the
// snapshot test has executed.
//
// See:
// https://github.com/microsoft/playwright/issues/14527#issuecomment-1143352769
export function setupSnapshot(testInfo: TestInfo) {
const snapshotDir = testInfo.snapshotDir;
const snapshotSuffix = testInfo.snapshotSuffix;
const projectName = testInfo.project.name;

testInfo.snapshotDir = path.resolve(snapshotDir, '..', 'screenshots');
testInfo.snapshotSuffix = '';
testInfo.project.name = '';

return {
data: { projectName },
cleanupSnapshot() {
testInfo.snapshotDir = snapshotDir;
testInfo.snapshotSuffix = snapshotSuffix;
testInfo.project.name = projectName;
},
};
}

test('nodebuds page has expected h1', async ({ page }) => {
await page.goto('/nodebuds');
expect(await page.textContent('h1')).toBe('Personalized for your success');
});

test('nodebuds page matches screenshot', async ({ page }, testInfo) => {
const { cleanupSnapshot, data } = setupSnapshot(testInfo);

if (testInfo.project.use.viewport) {
await page.setViewportSize(testInfo.project.use.viewport);
}

if (testInfo.project.use.colorScheme) {
await page.emulateMedia({
colorScheme: testInfo.project.use.colorScheme,
});
}

await page.goto('/nodebuds', { waitUntil: 'networkidle' });
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot({
name: `page-${data.projectName}.png`,
maxDiffPixelRatio: 0.1,
threshold: 1,
});

cleanupSnapshot();
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e708ba4

Please sign in to comment.