summaryrefslogtreecommitdiffstatshomepage
path: root/tests/e2e/specs/fatal-error-handler.test.js
blob: 1b5522358ebb90897e36f939ab788da1201f3e12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * External dependencies
 */
import { existsSync, mkdirSync, writeFileSync, unlinkSync } from 'node:fs';
import { join } from 'node:path';

/**
 * WordPress dependencies
 */
import { test, expect } from '@wordpress/e2e-test-utils-playwright';

test.describe( 'Fatal error handler', () => {
	const muPlugins = join(
		process.cwd(),
		process.env.LOCAL_DIR ?? 'src',
		'wp-content/mu-plugins'
	);
	const muPluginFile = join( muPlugins, 'fatal-error.php' );

	test.beforeAll( async () => {
		const muPluginCode = `<?php new NonExistentClass();`;

		if ( ! existsSync( muPlugins ) ) {
			mkdirSync( muPlugins, { recursive: true } );
		}
		writeFileSync( muPluginFile, muPluginCode );
	} );

	test.afterAll( async () => {
		unlinkSync( muPluginFile );
	} );

	test( 'should display fatal error notice', async ( { admin, page } ) => {
		await admin.visitAdminPage( '/' );

		await expect(
			page.getByText( /Fatal error:/ ),
			'should display PHP error message'
		).toBeVisible();

		await expect(
			page.getByText( /There has been a critical error on this website/ ),
			'should display WordPress fatal error handler message'
		).toBeVisible();
	} );
} );