Skip to content

Commit

Permalink
E2E Test Utils: Handle both plaintext and HTML errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Apr 3, 2020
1 parent e11c202 commit 8d9aff1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/src/has-page-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @type {RegExp}
*/
const REGEXP_PHP_ERROR = /<b>(Fatal error|Recoverable fatal error|Warning|Parse error|Notice|Strict Standards|Deprecated|Unknown error)<\/b>: /;
const REGEXP_PHP_ERROR = /(Fatal error|Recoverable fatal error|Warning|Parse error|Notice|Strict Standards|Deprecated|Unknown error)(<\/b>)?: (.*?) in (.*?) on line /;

/**
* Returns a promise resolving to a boolean reflecting whether a PHP notice is
Expand Down
44 changes: 44 additions & 0 deletions packages/e2e-test-utils/src/test/has-page-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Internal dependencies
*/
import { hasPageError } from '../has-page-error';

describe( 'hasPageError', () => {
let originalPage;

beforeEach( () => {
originalPage = global.page;
} );

afterEach( () => {
global.page = originalPage;
} );

it( 'returns false if there is no error', async () => {
global.page = {
content: () => 'Happy!',
};

expect( await hasPageError() ).toBe( false );
} );

it.each( [
[
'PHP, HTML',
'<b>Notice</b>: Undefined property: WP_Block_Type_Registry::$x in <b>/var/www/html/wp-content/plugins/gutenberg/lib/blocks.php</b> on line <b>47</b><br />',
],
[
'PHP, Plaintext',
'Notice: Undefined property: WP_Block_Type_Registry::$x in /var/www/html/wp-content/plugins/gutenberg/lib/blocks.php on line 47',
],
] )(
'returns true if there is an error (%s)',
async ( _variant, error ) => {
global.page = {
content: () => error,
};

expect( await hasPageError() ).toBe( true );
}
);
} );

0 comments on commit 8d9aff1

Please sign in to comment.