Rename Page.Events.ConsoleMessageAdded -> Page.Events.ConsoleMessage

This patch:
- renames ConsoleMessageAdded into ConsoleMessage for the sake of
  clarity
- adds a test to cover basic functionality
This commit is contained in:
Andrey Lushnikov 2017-05-13 11:05:54 -07:00
parent 2b0d0e6551
commit 8a8076c15b
4 changed files with 11 additions and 4 deletions

View File

@ -21,7 +21,7 @@ var browser = new Browser();
browser.newPage().then(async page => { browser.newPage().then(async page => {
var modernizrPath = path.join('..', 'third_party', 'phantomjs', 'examples', 'modernizr.js'); var modernizrPath = path.join('..', 'third_party', 'phantomjs', 'examples', 'modernizr.js');
await page.injectFile(modernizrPath); await page.injectFile(modernizrPath);
page.on('Page.Events.ConsoleMessageAdded', console.log); page.on('Page.Events.ConsoleMessage', console.log);
await page.evaluate(detectFeatures); await page.evaluate(detectFeatures);
browser.close(); browser.close();
}); });

View File

@ -204,7 +204,7 @@ class Page extends EventEmitter {
_onConsoleAPI(event) { _onConsoleAPI(event) {
var values = event.args.map(arg => arg.value || arg.description || ''); var values = event.args.map(arg => arg.value || arg.description || '');
this.emit(Page.Events.ConsoleMessageAdded, values.join(' ')); this.emit(Page.Events.ConsoleMessage, values.join(' '));
} }
/** /**
@ -416,7 +416,7 @@ Page.ScreenshotTypes = {
}; };
Page.Events = { Page.Events = {
ConsoleMessageAdded: 'Page.Events.ConsoleMessageAdded', ConsoleMessage: 'Page.Events.ConsoleMessage',
DialogOpened: 'Page.Events.DialogOpened', DialogOpened: 'Page.Events.DialogOpened',
ExceptionThrown: 'Page.Events.ExceptionThrown', ExceptionThrown: 'Page.Events.ExceptionThrown',
ResourceLoadingFailed: 'Page.Events.ResourceLoadingFailed', ResourceLoadingFailed: 'Page.Events.ResourceLoadingFailed',

View File

@ -63,7 +63,7 @@ class WebPage {
this._pageEvents = new AsyncEmitter(this._page); this._pageEvents = new AsyncEmitter(this._page);
this._pageEvents.on(PageEvents.ResponseReceived, response => this._onResponseReceived(response)); this._pageEvents.on(PageEvents.ResponseReceived, response => this._onResponseReceived(response));
this._pageEvents.on(PageEvents.ResourceLoadingFailed, event => (this.onResourceError || noop).call(null, event)); this._pageEvents.on(PageEvents.ResourceLoadingFailed, event => (this.onResourceError || noop).call(null, event));
this._pageEvents.on(PageEvents.ConsoleMessageAdded, msg => (this.onConsoleMessage || noop).call(null, msg)); this._pageEvents.on(PageEvents.ConsoleMessage, msg => (this.onConsoleMessage || noop).call(null, msg));
this._pageEvents.on(PageEvents.DialogOpened, dialog => this._onDialog(dialog)); this._pageEvents.on(PageEvents.DialogOpened, dialog => this._onDialog(dialog));
this._pageEvents.on(PageEvents.ExceptionThrown, (exception, stack) => (this._onError || noop).call(null, exception, stack)); this._pageEvents.on(PageEvents.ExceptionThrown, (exception, stack) => (this._onError || noop).call(null, exception, stack));
} }

View File

@ -33,6 +33,13 @@ describe('Puppeteer', function() {
expect(result).toBe(56); expect(result).toBe(56);
})); }));
it('Page.Events.ConsoleMessage', SX(async function() {
var msgs = [];
page.on('Page.Events.ConsoleMessage', msg => msgs.push(msg));
await page.evaluate(() => console.log('Message!'));
expect(msgs).toEqual(['Message!']);
}));
describe('Page.setInPageCallback', function() { describe('Page.setInPageCallback', function() {
it('should work', SX(async function() { it('should work', SX(async function() {
await page.setInPageCallback('callController', function(a, b) { await page.setInPageCallback('callController', function(a, b) {