Convert event names to small caps

This patch takes inspiration from DOM events and makes all the
events small-caps.
This commit is contained in:
Andrey Lushnikov 2017-05-13 12:04:30 -07:00
parent cf900cf717
commit 939038bb08
5 changed files with 12 additions and 12 deletions

View File

@ -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('ConsoleMessage', console.log);
page.on('consolemessage', console.log);
await page.evaluate(detectFeatures);
browser.close();
});

View File

@ -18,7 +18,7 @@ var Browser = require('../lib/Browser');
var browser = new Browser();
browser.newPage().then(async page => {
page.on('ConsoleMessage', console.log);
page.on('consolemessage', console.log);
await page.setInPageCallback('callPhantom', msg => {
console.log("Received by the 'phantom' main context: "+msg);
return "Hello there, I'm coming to you from the 'phantom' context instead";

View File

@ -60,7 +60,7 @@ class Page extends EventEmitter {
client.on('Network.responseReceived', event => this.emit(Page.Events.ResponseReceived, event.response));
client.on('Network.loadingFailed', event => this.emit(Page.Events.ResourceLoadingFailed, event));
client.on('Runtime.consoleAPICalled', event => this._onConsoleAPI(event));
client.on('Page.javascriptDialogOpening', dialog => this.emit(Page.Events.DialogOpened, dialog));
client.on('Page.javascriptDialogOpening', dialog => this.emit(Page.Events.Dialog, dialog));
client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
}
@ -199,7 +199,7 @@ class Page extends EventEmitter {
stack = exceptionDetails.stackTrace.callFrames.map(cf => cf.url);
}
var stackTrace = exceptionDetails.stackTrace;
this.emit(Page.Events.ExceptionThrown, exceptionDetails.exception.description, stack);
this.emit(Page.Events.Exception, exceptionDetails.exception.description, stack);
}
_onConsoleAPI(event) {
@ -416,11 +416,11 @@ Page.ScreenshotTypes = {
};
Page.Events = {
ConsoleMessage: 'ConsoleMessage',
DialogOpened: 'DialogOpened',
ExceptionThrown: 'ExceptionThrown',
ResourceLoadingFailed: 'ResourceLoadingFailed',
ResponseReceived: 'ResponseReceived',
ConsoleMessage: 'consolemessage',
Dialog: 'dialog',
Exception: 'exception',
ResourceLoadingFailed: 'resourceloadingfailed',
ResponseReceived: 'responsereceived',
};
module.exports = Page;

View File

@ -64,8 +64,8 @@ class WebPage {
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.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));
this._pageEvents.on(PageEvents.Dialog, dialog => this._onDialog(dialog));
this._pageEvents.on(PageEvents.Exception, (exception, stack) => (this._onError || noop).call(null, exception, stack));
}
_onResponseReceived(response) {

View File

@ -35,7 +35,7 @@ describe('Puppeteer', function() {
it('Page Events: ConsoleMessage', SX(async function() {
var msgs = [];
page.on('ConsoleMessage', msg => msgs.push(msg));
page.on('consolemessage', msg => msgs.push(msg));
await page.evaluate(() => console.log('Message!'));
expect(msgs).toEqual(['Message!']);
}));