aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-06-12 05:25:49 +0800
committerkumavis <aaron@kumavis.me>2018-06-12 05:25:49 +0800
commitebb9447593a877cd299e701ddfcb217070068fac (patch)
tree74380d5656a8ff3d36aa47ae27d4c69b225f76ff
parent02f5502e16fefc8d92392e614861e3f672c4f909 (diff)
downloadtangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.gz
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.bz2
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.lz
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.xz
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.tar.zst
tangerine-wallet-browser-ebb9447593a877cd299e701ddfcb217070068fac.zip
test - e2e - factor out setup phase + rename METAMASK_CONFIG to METAMASK_TEST_CONFIG
-rw-r--r--app/scripts/background.js3
-rw-r--r--test/e2e/beta/metamask-beta-ui.spec.js32
-rw-r--r--test/e2e/func.js34
-rw-r--r--test/e2e/metamask.spec.js29
4 files changed, 51 insertions, 47 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 41fd89016..9866ff0b0 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -31,7 +31,8 @@ const {
ENVIRONMENT_TYPE_FULLSCREEN,
} = require('./lib/enums')
-const firstTimeState = Object.assign({}, rawFirstTimeState, global.METAMASK_CONFIG)
+// METAMASK_TEST_CONFIG is used in e2e tests to set the default network to localhost
+const firstTimeState = Object.assign({}, rawFirstTimeState, global.METAMASK_TEST_CONFIG)
const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = process.env.METAMASK_DEBUG
diff --git a/test/e2e/beta/metamask-beta-ui.spec.js b/test/e2e/beta/metamask-beta-ui.spec.js
index ceeea31a5..8960e7e79 100644
--- a/test/e2e/beta/metamask-beta-ui.spec.js
+++ b/test/e2e/beta/metamask-beta-ui.spec.js
@@ -4,11 +4,8 @@ const webdriver = require('selenium-webdriver')
const { By, Key, until } = webdriver
const {
delay,
- buildChromeWebDriver,
- buildFirefoxWebdriver,
- installWebExt,
- getExtensionIdChrome,
- getExtensionIdFirefox,
+ createModifiedTestBuild,
+ setupBrowserAndExtension,
} = require('../func')
const {
findElement,
@@ -19,6 +16,7 @@ const {
} = require('./helpers')
describe('MetaMask', function () {
+ const browser = process.env.SELENIUM_BROWSER
let extensionId
let driver
let tokenAddress
@@ -33,27 +31,15 @@ describe('MetaMask', function () {
this.bail(true)
before(async function () {
- switch (process.env.SELENIUM_BROWSER) {
- case 'chrome': {
- const extPath = path.resolve('dist/chrome')
- driver = buildChromeWebDriver(extPath)
- extensionId = await getExtensionIdChrome(driver)
- await driver.get(`chrome-extension://${extensionId}/popup.html`)
- break
- }
- case 'firefox': {
- const extPath = path.resolve('dist/firefox')
- driver = buildFirefoxWebdriver()
- await installWebExt(driver, extPath)
- await delay(700)
- extensionId = await getExtensionIdFirefox(driver)
- await driver.get(`moz-extension://${extensionId}/popup.html`)
- }
- }
+ const srcPath = path.resolve(`dist/${browser}`)
+ const { extPath } = await createModifiedTestBuild({ browser, srcPath })
+ const installResult = await setupBrowserAndExtension({ browser, extPath })
+ driver = installResult.driver
+ extensionUri = installResult.extensionUri
})
afterEach(async function () {
- if (process.env.SELENIUM_BROWSER === 'chrome') {
+ if (browser === 'chrome') {
const errors = await checkBrowserForConsoleErrors(driver)
if (errors.length) {
const errorReports = errors.map(err => err.message)
diff --git a/test/e2e/func.js b/test/e2e/func.js
index 9f06e7f37..60e02a296 100644
--- a/test/e2e/func.js
+++ b/test/e2e/func.js
@@ -3,12 +3,15 @@ require('geckodriver')
const fs = require('fs')
const os = require('os')
const path = require('path')
+const pify = require('pify')
+const prependFile = pify(require('prepend-file'))
const webdriver = require('selenium-webdriver')
const Command = require('selenium-webdriver/lib/command').Command
const By = webdriver.By
module.exports = {
delay,
+ createModifiedTestBuild,
buildChromeWebDriver,
buildFirefoxWebdriver,
installWebExt,
@@ -20,6 +23,37 @@ function delay (time) {
return new Promise(resolve => setTimeout(resolve, time))
}
+async function createModifiedTestBuild ({ browser, srcPath }) {
+ // copy build to test-builds directory
+ const extPath = path.resolve(`test-builds/${browser}`)
+ await fs.ensureDir(extPath)
+ await fs.copy(srcPath, extPath)
+ // inject METAMASK_TEST_CONFIG setting default test network
+ const config = { NetworkController: { provider: { type: 'localhost' } } }
+ await prependFile(`${extPath}/background.js`, `window.METAMASK_TEST_CONFIG=${JSON.stringify(config)};\n`)
+ return { extPath }
+}
+
+async function setupBrowserAndExtension ({ browser, extPath }) {
+ let drive, extensionId, extensionUri
+
+ if (browser === 'chrome') {
+ driver = buildChromeWebDriver(extPath)
+ extensionId = await getExtensionIdChrome(driver)
+ extensionUri = `chrome-extension://${extensionId}/popup.html`
+ } else if (browser === 'firefox') {
+ driver = buildFirefoxWebdriver()
+ await installWebExt(driver, extPath)
+ await delay(700)
+ extensionId = await getExtensionIdFirefox(driver)
+ extensionUri = `moz-extension://${extensionId}/popup.html`
+ } else {
+ throw new Error(`Unknown Browser "${browser}"`)
+ }
+
+ return { driver, extensionId, extensionUri }
+}
+
function buildChromeWebDriver (extPath) {
const tmpProfile = path.join(os.tmpdir(), fs.mkdtempSync('mm-chrome-profile'));
return new webdriver.Builder()
diff --git a/test/e2e/metamask.spec.js b/test/e2e/metamask.spec.js
index 06c13b3d0..0d6ab9b35 100644
--- a/test/e2e/metamask.spec.js
+++ b/test/e2e/metamask.spec.js
@@ -3,10 +3,8 @@ const mkdirp = require('mkdirp')
const path = require('path')
const assert = require('assert')
const pify = require('pify')
-const prependFile = pify(require('prepend-file'))
-const webdriver = require('selenium-webdriver')
-const { By, Key } = webdriver
-const { delay, buildChromeWebDriver, buildFirefoxWebdriver, installWebExt, getExtensionIdChrome, getExtensionIdFirefox } = require('./func')
+const { By, Key } = require('selenium-webdriver')
+const { delay, createModifiedTestBuild, setupBrowserAndExtension } = require('./func')
describe('Metamask popup page', function () {
const browser = process.env.SELENIUM_BROWSER
@@ -16,25 +14,11 @@ describe('Metamask popup page', function () {
before(async function () {
const srcPath = path.resolve(`dist/${browser}`)
- const extPath = path.resolve(`test-builds/${browser}`)
- await fs.ensureDir(extPath)
- await fs.copy(srcPath, extPath)
- const config = { NetworkController: { provider: { type: 'localhost' } } }
- await prependFile(`${extPath}/background.js`, `window.METAMASK_CONFIG=${JSON.stringify(config)};\n`)
+ const { extPath } = await createModifiedTestBuild({ browser, srcPath })
+ const installResult = await setupBrowserAndExtension({ browser, extPath })
+ driver = installResult.driver
+ extensionUri = installResult.extensionUri
- if (browser === 'chrome') {
- driver = buildChromeWebDriver(extPath)
- extensionId = await getExtensionIdChrome(driver)
- extensionUri = `chrome-extension://${extensionId}/popup.html`
- } else if (browser === 'firefox') {
- driver = buildFirefoxWebdriver()
- await installWebExt(driver, extPath)
- await delay(700)
- extensionId = await getExtensionIdFirefox(driver)
- extensionUri = `moz-extension://${extensionId}/popup.html`
- } else {
- throw new Error(`Unknown Browser "${browser}"`)
- }
await driver.get(extensionUri)
})
@@ -53,7 +37,6 @@ describe('Metamask popup page', function () {
// gather extra data if test failed
if (this.currentTest.state === 'failed') {
await verboseReportOnFailure(this.currentTest)
- await delay(1000000)
}
})