From 8a8076c15be789536d25c80123874ecb8ea1e214 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Sat, 13 May 2017 11:05:54 -0700 Subject: [PATCH] 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 --- examples/features.js | 2 +- lib/Page.js | 4 ++-- phantomjs/WebPage.js | 2 +- test/test.js | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/features.js b/examples/features.js index 4ba110d72c0ce..bfc3fd5b1fed4 100644 --- a/examples/features.js +++ b/examples/features.js @@ -21,7 +21,7 @@ var browser = new Browser(); browser.newPage().then(async page => { var modernizrPath = path.join('..', 'third_party', 'phantomjs', 'examples', 'modernizr.js'); await page.injectFile(modernizrPath); - page.on('Page.Events.ConsoleMessageAdded', console.log); + page.on('Page.Events.ConsoleMessage', console.log); await page.evaluate(detectFeatures); browser.close(); }); diff --git a/lib/Page.js b/lib/Page.js index 4d845e8d9623d..4a0f4f19d8b5a 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -204,7 +204,7 @@ class Page extends EventEmitter { _onConsoleAPI(event) { 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 = { - ConsoleMessageAdded: 'Page.Events.ConsoleMessageAdded', + ConsoleMessage: 'Page.Events.ConsoleMessage', DialogOpened: 'Page.Events.DialogOpened', ExceptionThrown: 'Page.Events.ExceptionThrown', ResourceLoadingFailed: 'Page.Events.ResourceLoadingFailed', diff --git a/phantomjs/WebPage.js b/phantomjs/WebPage.js index 1927c04b2d03d..e968d7537aebe 100644 --- a/phantomjs/WebPage.js +++ b/phantomjs/WebPage.js @@ -63,7 +63,7 @@ class WebPage { this._pageEvents = new AsyncEmitter(this._page); 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.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.ExceptionThrown, (exception, stack) => (this._onError || noop).call(null, exception, stack)); } diff --git a/test/test.js b/test/test.js index b55a4c15d36d4..201ad6d4529c5 100644 --- a/test/test.js +++ b/test/test.js @@ -33,6 +33,13 @@ describe('Puppeteer', function() { 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() { it('should work', SX(async function() { await page.setInPageCallback('callController', function(a, b) {