Skip to content

Commit

Permalink
Testing: Check markup for errors in visitAdminPage
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Mar 22, 2019
1 parent 53b4351 commit c22e3b7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
22 changes: 22 additions & 0 deletions packages/e2e-test-utils/src/has-php-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Regular expression matching a displayed PHP error within a markup string.
*
* @link 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>/;

/**
* Returns a promise resolving to a boolean reflecting whether a PHP notice is
* present anywhere within the document's markup. This requires the environment
* be configured to display errors.
*
* @link http://php.net/manual/en/function.error-reporting.php
*
* @return {Promise} Promise resolving to a boolean reflecting whether a PHP
* notice is present.
*/
export async function hasPHPError() {
return REGEXP_PHP_ERROR.test( await page.content() );
}
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export { getAvailableBlockTransforms } from './get-available-block-transforms';
export { getBlockSetting } from './get-block-setting';
export { getEditedPostContent } from './get-edited-post-content';
export { hasBlockSwitcher } from './has-block-switcher';
export { hasPHPError } from './has-php-error';
export { insertBlock } from './insert-block';
export { installPlugin } from './install-plugin';
export { isCurrentURL } from './is-current-url';
export { isInDefaultBlock } from './is-in-default-block';
export { loginUser } from './login-user';
export { observeFocusLoss } from './observe-focus-loss';
export { openAllBlockInserterCategories } from './open-all-block-inserter-categories';
export { observePageWarnings } from './observe-page-warnings';
export { openDocumentSettingsSidebar } from './open-document-settings-sidebar';
export { openGlobalBlockInserter } from './open-global-block-inserter';
export { openPublishPanel } from './open-publish-panel';
Expand Down
15 changes: 0 additions & 15 deletions packages/e2e-test-utils/src/observe-page-warnings.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/e2e-test-utils/src/visit-admin-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { join } from 'path';
import { createURL } from './create-url';
import { isCurrentURL } from './is-current-url';
import { loginUser } from './login-user';
import { hasPHPError } from './has-php-error';

/**
* Visits admin page; if user is not logged in then it logging in it first, then visits admin page.
Expand All @@ -25,4 +26,6 @@ export async function visitAdminPage( adminPath, query ) {
await loginUser();
await visitAdminPage( adminPath, query );
}

expect( await hasPHPError() ).toBe( false );
}
2 changes: 0 additions & 2 deletions packages/e2e-tests/config/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import '@wordpress/jest-console';
import {
clearLocalStorage,
enablePageDialogAccept,
observePageWarnings,
setBrowserViewport,
visitAdminPage,
activatePlugin,
Expand Down Expand Up @@ -156,7 +155,6 @@ beforeAll( async () => {
capturePageEventsForTearDown();
enablePageDialogAccept();
observeConsoleLogging();
observePageWarnings();

await trashExistingPosts();
await setupBrowser();
Expand Down

0 comments on commit c22e3b7

Please sign in to comment.