feat(console): allow page.on('console', console.log) (#2145)
This commit is contained in:
parent
51fe84922c
commit
7a8dd2c361
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as js from './javascript';
|
import * as js from './javascript';
|
||||||
|
import * as util from 'util';
|
||||||
|
|
||||||
export type ConsoleMessageLocation = {
|
export type ConsoleMessageLocation = {
|
||||||
url?: string,
|
url?: string,
|
||||||
|
|
@ -52,4 +53,8 @@ export class ConsoleMessage {
|
||||||
location(): ConsoleMessageLocation {
|
location(): ConsoleMessageLocation {
|
||||||
return this._location;
|
return this._location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[util.inspect.custom]() {
|
||||||
|
return this.text();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const util = require('util');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
const {FFOX, CHROMIUM, WEBKIT} = require('./utils').testOptions(browserType);
|
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'); } );
|
await page.evaluate(() => { for (let i = 0; i < 2; ++i ) console.log('hello'); } );
|
||||||
expect(messages).toEqual(['hello', '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}) => {
|
it('should work for different console API calls', async({page, server}) => {
|
||||||
const messages = [];
|
const messages = [];
|
||||||
page.on('console', msg => messages.push(msg));
|
page.on('console', msg => messages.push(msg));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue