-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## What is this PR doing? It allows developers to listen for fatal Playground errors and collect logs. ## What problem is it solving? This will allow Playground to collect fatal errors from user sessions in the future. It will also allow developers who use `startPlaygroundWeb` to listen for errors and create custom workflows. ## How is the problem addressed? All logs are now collected inside the logger including PHP request errors. When a PHP request error happens the logger dispatches a custom event that developers can listen. ## Testing Instructions - Checkout this branch - Start Playground `npm run dev` - Run Playground with a fatal error http://localhost:5400/website-server/#{%20%22landingPage%22:%20%22/wp-admin/%22,%20%22phpExtensionBundles%22:%20[%20%22kitchen-sink%22%20],%20%22features%22:%20{%20%22networking%22:%20true%20},%20%22steps%22:%20[%20{%20%22step%22:%20%22login%22%20},%20{%20%22step%22:%20%22writeFile%22,%20%22path%22:%20%22/wordpress/wp-content/mu-plugins/rewrite.php%22,%20%22data%22:%20%22%3C?php%20add_action(%20'shutdown',%20function()%20{%20post_message_to_js('test');%20}%20);%22%20}%20]%20} - Open the browser console and search verbose/debug logs for _PHP-WASM Fatal_ - There should be a error message from the logger - Add this code to the end of `packages/playground/website/src/main.tsx` ``` addFatalErrorListener(logger, (e) => { console.log('Playground logs', (e as CustomEvent).detail.logs); }); ``` - Reload Playground and confirm that the even has triggered with log data by checking the browser console for _Playground logs_
- Loading branch information
Showing
8 changed files
with
126 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from './logger'; | ||
// PHP.wasm requires WordPress Playground's Node polyfills. | ||
import '@php-wasm/node-polyfills'; | ||
|
||
export * from './lib/logger'; |
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,23 @@ | ||
import { NodePHP } from '@php-wasm/node'; | ||
import { LatestSupportedPHPVersion } from '@php-wasm/universal'; | ||
import { logger, addFatalErrorListener, collectPhpLogs } from '../lib/logger'; | ||
|
||
describe('Logger', () => { | ||
let php: NodePHP; | ||
beforeEach(async () => { | ||
php = await NodePHP.load(LatestSupportedPHPVersion); | ||
}); | ||
it('Event listener should work', () => { | ||
const listener = vi.fn(); | ||
collectPhpLogs(logger, php); | ||
addFatalErrorListener(logger, listener); | ||
php.dispatchEvent({ | ||
type: 'request.error', | ||
error: new Error('test'), | ||
}); | ||
expect(listener).toBeCalledTimes(1); | ||
|
||
const logs = logger.getLogs(); | ||
expect(logs.length).toBe(1); | ||
}); | ||
}); |
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
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