-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing: Fail E2E when page displays warning notices (#13452)
* Testing: Fail E2E when page displays warning notices * Testing: Check markup for errors in visitAdminPage * E2E Test Utils: Rename hasPHPError to hasPageError * E2E Test Utils: Handle both plaintext and HTML errors * E2E Test Utils: Refactor hasPageError as getPageError Return error message so it can be used in failure output * E2E Test Utils: Display page error message in failure output
- Loading branch information
Showing
6 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Regular expression matching a displayed PHP error within a markup string. | ||
* | ||
* @see https://github.com/php/php-src/blob/598175e/main/main.c#L1257-L1297 | ||
* | ||
* @type {RegExp} | ||
*/ | ||
const REGEXP_PHP_ERROR = /(<b>)?(Fatal error|Recoverable fatal error|Warning|Parse error|Notice|Strict Standards|Deprecated|Unknown error)(<\/b>)?: (.*?) in (.*?) on line (<b>)?\d+(<\/b>)?/; | ||
|
||
/** | ||
* Returns a promise resolving to one of either a string or null. A string will | ||
* be resolved if an error message is present in the contents of the page. If no | ||
* error is present, a null value will be resolved instead. This requires the | ||
* environment be configured to display errors. | ||
* | ||
* @see http://php.net/manual/en/function.error-reporting.php | ||
* | ||
* @return {Promise<?string>} Promise resolving to a string or null, depending | ||
* whether a page error is present. | ||
*/ | ||
export async function getPageError() { | ||
const content = await page.content(); | ||
const match = content.match( REGEXP_PHP_ERROR ); | ||
return match ? match[ 0 ] : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getPageError } from '../get-page-error'; | ||
|
||
describe( 'getPageError', () => { | ||
let originalPage; | ||
|
||
beforeEach( () => { | ||
originalPage = global.page; | ||
} ); | ||
|
||
afterEach( () => { | ||
global.page = originalPage; | ||
} ); | ||
|
||
it( 'resolves to null if there is no error', async () => { | ||
global.page = { | ||
content: () => 'Happy!', | ||
}; | ||
|
||
expect( await getPageError() ).toBe( null ); | ||
} ); | ||
|
||
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>', | ||
], | ||
[ | ||
'PHP, Plaintext', | ||
'Notice: Undefined property: WP_Block_Type_Registry::$x in /var/www/html/wp-content/plugins/gutenberg/lib/blocks.php on line 47', | ||
], | ||
] )( | ||
'resolves to the error message if there is an error (%s)', | ||
async ( _variant, error ) => { | ||
global.page = { | ||
content: () => error, | ||
}; | ||
|
||
expect( await getPageError() ).toBe( error ); | ||
} | ||
); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters