Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store screenshots of CI e2e failures as CI artifacts #26664

Merged
merged 5 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
squash
  • Loading branch information
adamziel committed Nov 12, 2020
commit d0e4737d17988d17329b8ba44059eda0053d9199
29 changes: 29 additions & 0 deletions .github/workflows/end2end-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ jobs:
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 0' < ~/.jest-e2e-tests )

- name: Archive screenshots
uses: actions/upload-artifact@v2
if: always()
with:
name: failures-screenshots
path: artifacts

admin-2:
name: Admin - 2

Expand Down Expand Up @@ -92,6 +99,13 @@ jobs:
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 1' < ~/.jest-e2e-tests )

- name: Archive screenshots
uses: actions/upload-artifact@v2
if: always()
with:
name: failures-screenshots
path: artifacts

admin-3:
name: Admin - 3

Expand Down Expand Up @@ -133,6 +147,13 @@ jobs:
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 2' < ~/.jest-e2e-tests )

- name: Archive screenshots
uses: actions/upload-artifact@v2
if: always()
with:
name: failures-screenshots
path: artifacts

admin-4:
name: Admin - 4

Expand Down Expand Up @@ -173,3 +194,11 @@ jobs:
run: |
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % 4 == 3' < ~/.jest-e2e-tests )

- name: Archive screenshots
uses: actions/upload-artifact@v2
if: always()
with:
name: failures-screenshots
path: artifacts

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions packages/e2e-tests/config/setup-debug-artifacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* External dependencies
*/
const fs = require( 'fs' );
const util = require( 'util' );
const root = process.env.GITHUB_WORKSPACE || __dirname + '/../../../';
const ARTIFACTS_PATH = root + '/artifacts';

const writeFile = util.promisify( fs.writeFile );

if ( ! fs.existsSync( ARTIFACTS_PATH ) ) {
fs.mkdirSync( ARTIFACTS_PATH );
}

/**
* Gutenberg uses the default jest-jasmine2 test runner that comes with Jest.
* Unfortunately, version 2 of jasmine doesn't support async reporters. It
* does support async before and after hooks though, so the workaround here
* works by making each test wait for the artifacts before starting.
*
* Kudos to Tom Esterez (@testerez) for sharing this idea in https://github.com/smooth-code/jest-puppeteer/issues/131#issuecomment-424073620
*/
let artifactsPromise;
// eslint-disable-next-line jest/no-jasmine-globals
jasmine.getEnv().addReporter( {
specDone: ( result ) => {
if ( result.status === 'failed' ) {
artifactsPromise = storeArtifacts( result.fullName );
}
},
} );

beforeEach( () => artifactsPromise );
afterAll( () => artifactsPromise );

async function storeArtifacts( testName ) {
const slug = slugify( testName );
await writeFile(
`${ ARTIFACTS_PATH }/${ slug }-snapshot.html`,
await page.content()
);
await page.screenshot( { path: `${ ARTIFACTS_PATH }/${ slug }.jpg` } );
}

function slugify( testName ) {
const datetime = new Date().toISOString().split( '.' )[ 0 ];
const readableName = `${ testName } ${ datetime }`;
const slug = readableName
.toLowerCase()
.replace( /:/g, '-' )
.replace( /[^0-9a-zA-Z \-\(\)]/g, '' )
.replace( / /g, '-' );
return slug;
}
1 change: 1 addition & 0 deletions packages/e2e-tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
...require( '@wordpress/scripts/config/jest-e2e.config' ),
setupFiles: [ '<rootDir>/config/gutenberg-phase.js' ],
setupFilesAfterEnv: [
'<rootDir>/config/setup-debug-artifacts.js',
'<rootDir>/config/setup-test-framework.js',
'@wordpress/jest-console',
'@wordpress/jest-puppeteer-axe',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe( 'Multi-entity editor states', () => {
);
await page.keyboard.type( 'Nested test words!' );

expect( await isEntityDirty( templateName ) ).toBe( false );
expect( await isEntityDirty( templateName ) ).toBe( true ); // Broken on purpose to test the screenshots
expect( await isEntityDirty( templatePartName ) ).toBe( false );
expect( await isEntityDirty( nestedTPName ) ).toBe( true );
} );
Expand Down
Loading