1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #4333 from MetaMask/test-e2e-check-for-errors

test - e2e - check for console errors after each test
This commit is contained in:
Thomas Huang 2018-05-22 12:59:55 -07:00 committed by GitHub
commit 492b4a6743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 51 deletions

View File

@ -62,7 +62,7 @@ function mapStateToProps (state) {
isInitialized: state.metamask.isInitialized, isInitialized: state.metamask.isInitialized,
isUnlocked: state.metamask.isUnlocked, isUnlocked: state.metamask.isUnlocked,
currentView: state.appState.currentView, currentView: state.appState.currentView,
activeAddress: state.appState.activeAddress, selectedAddress: state.metamask.selectedAddress,
transForward: state.appState.transForward, transForward: state.appState.transForward,
isMascara: state.metamask.isMascara, isMascara: state.metamask.isMascara,
isOnboarding: Boolean(!noActiveNotices || seedWords || !isInitialized), isOnboarding: Boolean(!noActiveNotices || seedWords || !isInitialized),
@ -197,7 +197,7 @@ App.prototype.renderAppBar = function () {
style: {}, style: {},
enableAccountsSelector: true, enableAccountsSelector: true,
identities: this.props.identities, identities: this.props.identities,
selected: this.props.currentView.context, selected: this.props.selectedAddress,
network: this.props.network, network: this.props.network,
keyrings: this.props.keyrings, keyrings: this.props.keyrings,
}, []), }, []),
@ -588,7 +588,7 @@ App.prototype.renderPrimary = function () {
}, },
}, [ }, [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer.color-orange', { h('i.fa.fa-arrow-left.fa-lg.cursor-pointer.color-orange', {
onClick: () => props.dispatch(actions.backToAccountDetail(props.activeAddress)), onClick: () => props.dispatch(actions.backToAccountDetail(props.selectedAddress)),
style: { style: {
marginLeft: '10px', marginLeft: '10px',
marginTop: '50px', marginTop: '50px',

View File

@ -1,7 +1,6 @@
const Component = require('react').Component const Component = require('react').Component
const h = require('react-hyperscript') const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const extend = require('xtend')
const debounce = require('debounce') const debounce = require('debounce')
const copyToClipboard = require('copy-to-clipboard') const copyToClipboard = require('copy-to-clipboard')
const ENS = require('ethjs-ens') const ENS = require('ethjs-ens')
@ -20,55 +19,61 @@ function EnsInput () {
EnsInput.prototype.render = function () { EnsInput.prototype.render = function () {
const props = this.props const props = this.props
const opts = extend(props, {
list: 'addresses',
onChange: () => {
const network = this.props.network
const networkHasEnsSupport = getNetworkEnsSupport(network)
if (!networkHasEnsSupport) return
const recipient = document.querySelector('input[name="address"]').value function onInputChange() {
if (recipient.match(ensRE) === null) { const network = this.props.network
return this.setState({ const networkHasEnsSupport = getNetworkEnsSupport(network)
loadingEns: false, if (!networkHasEnsSupport) return
ensResolution: null,
ensFailure: null,
})
}
this.setState({ const recipient = document.querySelector('input[name="address"]').value
loadingEns: true, if (recipient.match(ensRE) === null) {
return this.setState({
loadingEns: false,
ensResolution: null,
ensFailure: null,
}) })
this.checkName() }
},
}) this.setState({
return h('div', { loadingEns: true,
style: { width: '100%' }, })
}, [ this.checkName()
h('input.large-input', opts), }
// The address book functionality.
h('datalist#addresses', return (
[ h('div', {
// Corresponds to the addresses owned. style: { width: '100%' },
Object.keys(props.identities).map((key) => { }, [
const identity = props.identities[key] h('input.large-input', {
return h('option', { name: props.name,
value: identity.address, placeholder: props.placeholder,
label: identity.name, list: 'addresses',
key: identity.address, onChange: onInputChange.bind(this),
}) }),
}), // The address book functionality.
// Corresponds to previously sent-to addresses. h('datalist#addresses',
props.addressBook.map((identity) => { [
return h('option', { // Corresponds to the addresses owned.
value: identity.address, Object.keys(props.identities).map((key) => {
label: identity.name, const identity = props.identities[key]
key: identity.address, return h('option', {
}) value: identity.address,
}), label: identity.name,
]), key: identity.address,
this.ensIcon(), })
]) }),
// Corresponds to previously sent-to addresses.
props.addressBook.map((identity) => {
return h('option', {
value: identity.address,
label: identity.name,
key: identity.address,
})
}),
]),
this.ensIcon(),
])
)
} }
EnsInput.prototype.componentDidMount = function () { EnsInput.prototype.componentDidMount = function () {

View File

@ -30,6 +30,18 @@ describe('Metamask popup page', function () {
}) })
afterEach(async function () { afterEach(async function () {
// logs command not supported in firefox
// https://github.com/SeleniumHQ/selenium/issues/2910
if (process.env.SELENIUM_BROWSER === 'chrome') {
// check for console errors
const errors = await checkBrowserForConsoleErrors()
if (errors.length) {
const errorReports = errors.map(err => err.message)
const errorMessage = `Errors found in browser console:\n${errorReports.join('\n')}`
this.test.error(new Error(errorMessage))
}
}
// gather extra data if test failed
if (this.currentTest.state === 'failed') { if (this.currentTest.state === 'failed') {
await verboseReportOnFailure(this.currentTest) await verboseReportOnFailure(this.currentTest)
} }
@ -300,13 +312,33 @@ describe('Metamask popup page', function () {
await driver.executeScript('window.metamask.setProviderType(arguments[0])', type) await driver.executeScript('window.metamask.setProviderType(arguments[0])', type)
} }
async function checkBrowserForConsoleErrors() {
const ignoredLogTypes = ['WARNING']
const ignoredErrorMessages = [
// React throws error warnings on "dataset", but still sets the data-* properties correctly
'Warning: Unknown prop `dataset` on ',
// Third-party Favicon 404s show up as errors
'favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)',
// React Development build - known issue blocked by test build sys
'Warning: It looks like you\'re using a minified copy of the development build of React.',
// Redux Development build - known issue blocked by test build sys
'This means that you are running a slower development build of Redux.',
]
const browserLogs = await driver.manage().logs().get('browser')
const errorEntries = browserLogs.filter(entry => !ignoredLogTypes.includes(entry.level.toString()))
const errorObjects = errorEntries.map(entry => entry.toJSON())
// ignore all errors that contain a message in `ignoredErrorMessages`
const matchedErrorObjects = errorObjects.filter(entry => !ignoredErrorMessages.some(message => entry.message.includes(message)))
return matchedErrorObjects
}
async function verboseReportOnFailure (test) { async function verboseReportOnFailure (test) {
let artifactDir let artifactDir
if (process.env.SELENIUM_BROWSER === 'chrome') { if (process.env.SELENIUM_BROWSER === 'chrome') {
artifactDir = `./test-artifacts/chrome/${test.title}` artifactDir = `./test-artifacts/chrome/${test.title}`
} else if (process.env.SELENIUM_BROWSER === 'firefox') { } else if (process.env.SELENIUM_BROWSER === 'firefox') {
artifactDir = `./test-artifacts/firefox/${test.title}` artifactDir = `./test-artifacts/firefox/${test.title}`
} }
const filepathBase = `${artifactDir}/test-failure` const filepathBase = `${artifactDir}/test-failure`
await pify(mkdirp)(artifactDir) await pify(mkdirp)(artifactDir)
// capture screenshot // capture screenshot