Skip to content

Commit

Permalink
Fix snapshot failures not being captured
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Jul 10, 2021
1 parent a22ae3f commit be0d41c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/e2e-tests/config/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { get } from 'lodash';
import { toMatchInlineSnapshot, toMatchSnapshot } from 'jest-snapshot';

/**
* WordPress dependencies
Expand Down Expand Up @@ -212,6 +213,22 @@ async function simulateAdverseConditions() {
}
}

// Override snapshot matchers to throw errors as soon as possible,
// See https://jestjs.io/docs/expect#bail-out
// This is to fix a bug in Jest that snapshot failures won't trigger `test_fn_failure` events.
expect.extend( {
toMatchInlineSnapshot( ...args ) {
this.dontThrow = () => {};

return toMatchInlineSnapshot.call( this, ...args );
},
toMatchSnapshot( ...args ) {
this.dontThrow = () => {};

return toMatchSnapshot.call( this, ...args );
},
} );

// Before every test suite run, delete all content created by the test. This ensures
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
// each other's side-effects.
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"peerDependencies": {
"jest": ">=26",
"jest-snapshot": ">=26",
"puppeteer": ">=1.19.0"
},
"publishConfig": {
Expand Down

0 comments on commit be0d41c

Please sign in to comment.