feat(console): allow page.on('console', console.log) (#2145)

This commit is contained in:
Pavel Feldman 2020-05-07 15:34:09 -07:00 committed by GitHub
parent 51fe84922c
commit 7a8dd2c361
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -15,6 +15,7 @@
*/
import * as js from './javascript';
import * as util from 'util';
export type ConsoleMessageLocation = {
url?: string,
@ -52,4 +53,8 @@ export class ConsoleMessage {
location(): ConsoleMessageLocation {
return this._location;
}
[util.inspect.custom]() {
return this.text();
}
}

View file

@ -16,6 +16,7 @@
*/
const path = require('path');
const util = require('util');
const vm = require('vm');
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
@ -169,6 +170,15 @@ describe('Page.Events.Console', function() {
await page.evaluate(() => { for (let i = 0; i < 2; ++i ) console.log('hello'); } );
expect(messages).toEqual(['hello', 'hello']);
});
it('should use text() for inspection', async({page}) => {
let text;
const inspect = value => {
text = util.inspect(value);
}
page.on('console', inspect);
await page.evaluate(() => console.log('Hello world'));
expect(text).toEqual('Hello world');
});
it('should work for different console API calls', async({page, server}) => {
const messages = [];
page.on('console', msg => messages.push(msg));