Skip to content

Commit

Permalink
Removed screenshot testing from complex pages (#624)
Browse files Browse the repository at this point in the history
* Strip screenshot tests for nondeterministic page endpoints

Some acmcsuf.com pages give the Playwright testing some trouble, being capable of generating non-deterministic screenshots. This is a problem and should be stripped out of the main branch for now so that the nondeterministic screenshot tests may be rewritten on a case-by-case basis.
  • Loading branch information
EthanThatOneKid authored Oct 22, 2022
1 parent 0a113a1 commit 933fa16
Show file tree
Hide file tree
Showing 32 changed files with 0 additions and 126 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 0 additions & 50 deletions src/routes/(site)/1st/page.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,8 @@
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('first contributions page has expected h1', async ({ page }) => {
await page.goto('/1st');
expect(await page.textContent('h1')).toBe('First Contributions');
});

test('first contributions 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('/1st', { waitUntil: 'networkidle' });
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot({
name: `page-${data.projectName}.png`,
maxDiffPixelRatio: 0.1,
threshold: 1,
});

cleanupSnapshot();
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
23 changes: 0 additions & 23 deletions src/routes/(site)/blog/[id]/page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,3 @@ test('blog post h1 matches page title', async ({ page }) => {
await page.goto('/blog/272');
expect(await page.title()).toContain(await page.textContent('h1'));
});

test('blog post 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('/blog/272', { waitUntil: 'networkidle' });
expect(await page.screenshot({ fullPage: true, scale: 'css' })).toMatchSnapshot({
name: `page-${data.projectName}.png`,
maxDiffPixelRatio: 0.1,
threshold: 1,
});

cleanupSnapshot();
});
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.
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.
52 changes: 0 additions & 52 deletions src/routes/(site)/events/page.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,6 @@
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('events page has expected h2', async ({ page }) => {
await page.goto('/events');
expect(await page.textContent('h2')).toBe('Curated events for growth and success');
});

test('events 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('/events', { waitUntil: 'networkidle' });
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot({
name: `page-${data.projectName}.png`,
maxDiffPixelRatio: 0.1,
threshold: 1,
});

cleanupSnapshot();
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.

1 comment on commit 933fa16

@vercel
Copy link

@vercel vercel bot commented on 933fa16 Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.