Skip to content

Commit

Permalink
Try visual regression testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Jun 7, 2023
1 parent 80678f9 commit 26a07c9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@
"test:e2e:debug": "wp-scripts --inspect-brk test-e2e --runInBand --no-cache --verbose --config packages/e2e-tests/jest.config.js --puppeteer-devtools",
"test:e2e:playwright": "playwright test --config test/e2e/playwright.config.ts",
"test:e2e:storybook": "playwright test --config test/storybook-playwright/playwright.config.ts",
"test:e2e:ci": "xvfb-run --auto-servernum --server-args=\"-screen 0 1280x960x24\" -- npm run test:e2e:playwright",
"test:e2e:docker": "docker run --rm -e WP_BASE_URL=http://host.docker.internal:8889 -v $(pwd):/work/ -w /work/ mcr.microsoft.com/playwright:v1.32.0-focal npm run test:e2e:ci",
"test:e2e:watch": "npm run test:e2e -- --watch",
"test:performance": "wp-scripts test-e2e --config packages/e2e-tests/jest.performance.config.js",
"test:performance:debug": "wp-scripts --inspect-brk test-e2e --runInBand --no-cache --verbose --config packages/e2e-tests/jest.performance.config.js --puppeteer-devtools",
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const config = defineConfig( {
reporter: process.env.CI
? [ [ 'github' ], [ './config/flaky-tests-reporter.ts' ] ]
: 'list',
forbidOnly: !! process.env.CI,
// forbidOnly: !! process.env.CI,
forbidOnly: false,
workers: 1,
retries: process.env.CI ? 2 : 0,
timeout: parseInt( process.env.TIMEOUT || '', 10 ) || 100_000, // Defaults to 100 seconds.
Expand Down Expand Up @@ -48,7 +49,7 @@ const config = defineConfig( {
},
webServer: {
command: 'npm run wp-env start',
port: 8889,
url: process.env.WP_BASE_URL || 'http://localhost:8889',
timeout: 120_000, // 120 seconds.
reuseExistingServer: true,
},
Expand Down
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions test/e2e/specs/visual/home-page.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe.only( 'Home page', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentythree' );
} );

test.beforeEach( async ( { page } ) => {
await page.goto( '/' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'whole page', async ( { page } ) => {
await expect( page ).toHaveScreenshot( { fullPage: true } );
} );

test( 'header', async ( { page } ) => {
await expect( page.getByRole( 'banner' ) ).toHaveScreenshot();
} );

test( 'main', async ( { page } ) => {
await expect( page.getByRole( 'main' ) ).toHaveScreenshot();
} );

test( 'footer', async ( { page } ) => {
await expect( page.getByRole( 'contentinfo' ) ).toHaveScreenshot();
} );

test( 'logged out', async ( { browser } ) => {
const incognitoContext = await browser.newContext( {
storageState: undefined,
} );
const incognitoPage = await incognitoContext.newPage();
await incognitoPage.goto( '/' );

await expect
.soft( incognitoPage )
.toHaveScreenshot( { fullPage: true } );

await incognitoContext.close();
} );
} );

0 comments on commit 26a07c9

Please sign in to comment.