-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(errors-in-console): include runtime exceptions (#3494)
- Loading branch information
1 parent
b6a676a
commit 487bee6
Showing
7 changed files
with
173 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Gathers runtime exceptions. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const Gatherer = require('./gatherer'); | ||
|
||
class RuntimeExceptions extends Gatherer { | ||
constructor() { | ||
super(); | ||
this._exceptions = []; | ||
this._onRuntimeExceptionThrown = this.onRuntimeExceptionThrown.bind(this); | ||
} | ||
|
||
onRuntimeExceptionThrown(entry) { | ||
this._exceptions.push(entry); | ||
} | ||
|
||
beforePass(options) { | ||
const driver = options.driver; | ||
driver.on('Runtime.exceptionThrown', this._onRuntimeExceptionThrown); | ||
} | ||
|
||
afterPass(options) { | ||
return Promise.resolve() | ||
.then(_ => options.driver.off('Runtime.exceptionThrown', this._onRuntimeExceptionThrown)) | ||
.then(_ => this._exceptions); | ||
} | ||
} | ||
|
||
module.exports = RuntimeExceptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
lighthouse-core/test/gather/gatherers/runtime-exceptions-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @license Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/* eslint-env mocha */ | ||
|
||
const RuntimeExceptionsGatherer = require('../../../gather/gatherers/runtime-exceptions'); | ||
const assert = require('assert'); | ||
|
||
const mockDriver = { | ||
off() {}, | ||
}; | ||
|
||
const wrapSendCommand = (mockDriver, runtimeEx) => { | ||
mockDriver = Object.assign({}, mockDriver); | ||
|
||
mockDriver.on = (name, cb) => { | ||
if (name === 'Runtime.exceptionThrown') { | ||
cb(runtimeEx); | ||
} | ||
}; | ||
|
||
mockDriver.sendCommand = () => { | ||
return Promise.resolve(); | ||
}; | ||
|
||
return mockDriver; | ||
}; | ||
|
||
describe('RuntimeExceptions', () => { | ||
it('captures the exceptions raised', () => { | ||
const runtimeExceptionsGatherer = new RuntimeExceptionsGatherer(); | ||
const runtimeEx = | ||
{ | ||
'timestamp': 1506535813608.003, | ||
'exceptionDetails': { | ||
'url': 'http://www.example.com/fancybox.js', | ||
'stackTrace': { | ||
'callFrames': [ | ||
{ | ||
'url': 'http://www.example.com/fancybox.js', | ||
'lineNumber': 28, | ||
'columnNumber': 20, | ||
}, | ||
], | ||
}, | ||
'exception': { | ||
'className': 'TypeError', | ||
'description': 'TypeError: Cannot read property \'msie\' of undefined', | ||
}, | ||
'executionContextId': 3, | ||
}, | ||
}; | ||
|
||
const options = { | ||
driver: wrapSendCommand(mockDriver, runtimeEx), | ||
}; | ||
|
||
return Promise.resolve( | ||
runtimeExceptionsGatherer.beforePass(options)) | ||
.then(_ => runtimeExceptionsGatherer.afterPass(options)) | ||
.then((artifact) => { | ||
assert.equal(artifact[0].exceptionDetails.exception.description, | ||
`TypeError: Cannot read property 'msie' of undefined`); | ||
assert.equal(artifact[0].exceptionDetails.url, | ||
'http://www.example.com/fancybox.js'); | ||
}); | ||
}); | ||
}); |