From 45498452868ab82c7678086275bd4d35536ef753 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 22:24:19 -0700 Subject: [PATCH 1/8] ci - deps - download latest chrome and firefox --- circle.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index e81e1bcaa..f5da6857d 100644 --- a/circle.yml +++ b/circle.yml @@ -3,4 +3,15 @@ machine: version: 8.1.4 test: override: - - "npm run ci" \ No newline at end of file + - "npm run ci" +dependencies: + pre: + - sudo apt-get update + # get latest stable firefox + - sudo apt-get install firefox + - firefox_cmd=`which firefox`; sudo rm -f $firefox_cmd; sudo ln -s `which firefox.ubuntu` $firefox_cmd + # get latest stable chrome + - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - + - sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' + - sudo apt-get update + - sudo apt-get install google-chrome-stable \ No newline at end of file From 19d6618c04196f392a455823d1929025d40564fa Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 16:21:58 -0700 Subject: [PATCH 2/8] test - integration - build - use pump + log bundling information --- test/integration/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/integration/index.js b/test/integration/index.js index e089fc39b..8dc8a408f 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const pump = require('pump') const browserify = require('browserify') const tests = fs.readdirSync(path.join(__dirname, 'lib')) const bundlePath = path.join(__dirname, 'bundle.js') @@ -9,11 +10,16 @@ const b = browserify() const writeStream = fs.createWriteStream(bundlePath) tests.forEach(function (fileName) { - b.add(path.join(__dirname, 'lib', fileName)) + const filePath = path.join(__dirname, 'lib', fileName) + console.log(`bundling test "${filePath}"`) + b.add(filePath) }) -b.bundle() -.pipe(writeStream) -.on('error', (err) => { - throw err -}) +pump( + b.bundle(), + writeStream, + (err) => { + if (err) throw err + console.log('bundle completed.') + } +) \ No newline at end of file From ca035743c2a89b90b5b263bf3125cbed1175c4b2 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 16:22:50 -0700 Subject: [PATCH 3/8] ci - dont attempt to submit coveralls if not configured --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9afc181a3..eb0b57bb7 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "test-unit": "METAMASK_ENV=test mocha --require test/helper.js --recursive \"test/unit/**/*.js\"", "single-test": "METAMASK_ENV=test mocha --require test/helper.js", "test-integration": "npm run buildMock && npm run buildCiUnits && testem ci -P 2", - "test-coverage": "nyc npm run test-unit && nyc report --reporter=text-lcov | coveralls", + "test-coverage": "nyc npm run test-unit && if [ $COVERALLS_REPO_TOKEN ]; then nyc report --reporter=text-lcov | coveralls; fi", "ci": "npm run lint && npm run test-coverage && npm run test-integration", "lint": "gulp lint", "buildCiUnits": "node test/integration/index.js", From d4a41e0277bb2a8905b546165a3b0de62d3407cb Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 16:32:07 -0700 Subject: [PATCH 4/8] test - integration - build - manually exit from test builder + add bundle destination log --- test/integration/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/index.js b/test/integration/index.js index 8dc8a408f..144303dbb 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -20,6 +20,7 @@ pump( writeStream, (err) => { if (err) throw err - console.log('bundle completed.') + console.log(`Integration test build completed: "${bundlePath}"`) + process.exit(0) } ) \ No newline at end of file From e9daf0eb280064a81235d144c71d41c8f1535aac Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 17:10:30 -0700 Subject: [PATCH 5/8] test - integration - remove redundant testem scripts --- package.json | 1 - testem.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/package.json b/package.json index eb0b57bb7..71b132b98 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "ui": "npm run genStates && beefy ui-dev.js:bundle.js --live --open --index=./development/index.html --cwd ./", "mock": "beefy mock-dev.js:bundle.js --live --open --index=./development/index.html --cwd ./", "buildMock": "npm run genStates && browserify ./mock-dev.js -o ./development/bundle.js", - "testem": "npm run buildMock && testem", "announce": "node development/announcer.js", "generateNotice": "node notices/notice-generator.js", "deleteNotice": "node notices/notice-delete.js", diff --git a/testem.yml b/testem.yml index 2cf40f7f4..7923a2929 100644 --- a/testem.yml +++ b/testem.yml @@ -6,5 +6,4 @@ launch_in_ci: - Firefox framework: - qunit -before_tests: "npm run buildCiUnits" test_page: "test/integration/index.html" From 0e70366e9c31d3085d505f110b586418c72c217e Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 20:14:52 -0700 Subject: [PATCH 6/8] test - integration - drop testem for karma --- karma.conf.js | 61 +++++++++++++++++++++++++++++ mock-dev.js | 63 +++++++++++++++++------------- package.json | 7 +++- test/integration/helpers.js | 7 ---- test/integration/lib/first-time.js | 60 ++++++++++++++++++++-------- 5 files changed, 146 insertions(+), 52 deletions(-) create mode 100644 karma.conf.js delete mode 100644 test/integration/helpers.js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..8e6d55972 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,61 @@ +// Karma configuration +// Generated on Mon Sep 11 2017 18:45:48 GMT-0700 (PDT) + +module.exports = function(config) { + config.set({ + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: process.cwd(), + + browserConsoleLogOptions: { + terminal: false, + }, + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['qunit'], + + // list of files / patterns to load in the browser + files: [ + 'development/bundle.js', + 'test/integration/jquery-3.1.0.min.js', + 'test/integration/bundle.js', + { pattern: 'dist/chrome/images/**/*.*', watched: false, included: false, served: true }, + { pattern: 'dist/chrome/fonts/**/*.*', watched: false, included: false, served: true }, + ], + + proxies: { + '/images/': '/base/dist/chrome/images/', + '/fonts/': '/base/dist/chrome/fonts/', + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: false, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome', 'Firefox'], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} diff --git a/mock-dev.js b/mock-dev.js index 8e1923a82..b6652bdf7 100644 --- a/mock-dev.js +++ b/mock-dev.js @@ -85,40 +85,47 @@ actions.update = function(stateName) { var css = MetaMaskUiCss() injectCss(css) -const container = document.querySelector('#app-content') - // parse opts var store = configureStore(firstState) // start app -render( - h('.super-dev-container', [ +startApp() - h('button', { - onClick: (ev) => { - ev.preventDefault() - store.dispatch(actions.update('terms')) - }, - style: { - margin: '19px 19px 0px 19px', - }, - }, 'Reset State'), +function startApp(){ + const body = document.body + const container = document.createElement('div') + container.id = 'app-content' + body.appendChild(container) + console.log('container', container) - h(Selector, { actions, selectedKey: selectedView, states, store }), + render( + h('.super-dev-container', [ - h('.mock-app-root', { - style: { - height: '500px', - width: '360px', - boxShadow: 'grey 0px 2px 9px', - margin: '20px', - }, - }, [ - h(Root, { - store: store, - }), - ]), + h('button', { + onClick: (ev) => { + ev.preventDefault() + store.dispatch(actions.update('terms')) + }, + style: { + margin: '19px 19px 0px 19px', + }, + }, 'Reset State'), - ] -), container) + h(Selector, { actions, selectedKey: selectedView, states, store }), + h('.mock-app-root', { + style: { + height: '500px', + width: '360px', + boxShadow: 'grey 0px 2px 9px', + margin: '20px', + }, + }, [ + h(Root, { + store: store, + }), + ]), + + ] + ), container) +} diff --git a/package.json b/package.json index 71b132b98..9d267bde6 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test": "npm run lint && npm run test-unit && npm run test-integration", "test-unit": "METAMASK_ENV=test mocha --require test/helper.js --recursive \"test/unit/**/*.js\"", "single-test": "METAMASK_ENV=test mocha --require test/helper.js", - "test-integration": "npm run buildMock && npm run buildCiUnits && testem ci -P 2", + "test-integration": "npm run buildMock && npm run buildCiUnits && karma start", "test-coverage": "nyc npm run test-unit && if [ $COVERALLS_REPO_TOKEN ]; then nyc report --reporter=text-lcov | coveralls; fi", "ci": "npm run lint && npm run test-coverage && npm run test-integration", "lint": "gulp lint", @@ -171,6 +171,11 @@ "jsdom-global": "^3.0.2", "jshint-stylish": "~2.2.1", "json-rpc-engine": "^3.0.1", + "karma": "^1.7.1", + "karma-chrome-launcher": "^2.2.0", + "karma-cli": "^1.0.1", + "karma-firefox-launcher": "^1.0.1", + "karma-qunit": "^1.2.1", "lodash.assign": "^4.0.6", "mocha": "^3.4.2", "mocha-eslint": "^4.0.0", diff --git a/test/integration/helpers.js b/test/integration/helpers.js deleted file mode 100644 index 10cd74e64..000000000 --- a/test/integration/helpers.js +++ /dev/null @@ -1,7 +0,0 @@ -function wait(time) { - return new Promise(function (resolve, reject) { - setTimeout(function () { - resolve() - }, time * 3 || 1500) - }) -} diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index cc56b3704..c5ecfef95 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -10,26 +10,46 @@ QUnit.test('render init screen', (assert) => { }) }) -async function runFirstTimeUsageTest(assert, done) { - await wait() +<<<<<<< HEAD +======= +// QUnit.testDone(({ module, name, total, passed, failed, skipped, todo, runtime }) => { +// if (failed > 0) { +// const app = $('iframe').contents()[0].documentElement +// console.warn('Test failures - dumping DOM:') +// console.log(app.innerHTML) +// } +// }) - const app = $('iframe').contents().find('#app-content .mock-app-root') +>>>>>>> 5c53bab... test - integration - drop testem for karma +async function runFirstTimeUsageTest(assert, done) { + + await timeout() + + const app = $('#app-content .mock-app-root') const recurseNotices = async () => { const button = app.find('button') if (button.html() === 'Accept') { const termsPage = app.find('.markdown')[0] termsPage.scrollTop = termsPage.scrollHeight - await wait() + await timeout() button.click() +<<<<<<< HEAD await wait() await recurseNotices() +======= + await timeout() +>>>>>>> 5c53bab... test - integration - drop testem for karma } else { await wait() } } +<<<<<<< HEAD await recurseNotices() +======= + await timeout() +>>>>>>> 5c53bab... test - integration - drop testem for karma // Scroll through terms const title = app.find('h1').text() @@ -41,13 +61,13 @@ async function runFirstTimeUsageTest(assert, done) { pwBox.value = PASSWORD confBox.value = PASSWORD - await wait() + await timeout() // create vault const createButton = app.find('button.primary')[0] createButton.click() - await wait(1500) + await timeout(1500) const created = app.find('h3')[0] assert.equal(created.textContent, 'Vault Created', 'Vault created screen') @@ -57,7 +77,7 @@ async function runFirstTimeUsageTest(assert, done) { assert.ok(button, 'button present') button.click() - await wait(1000) + await timeout(1000) const detail = app.find('.account-detail-section')[0] assert.ok(detail, 'Account detail section loaded.') @@ -65,7 +85,7 @@ async function runFirstTimeUsageTest(assert, done) { const sandwich = app.find('.sandwich-expando')[0] sandwich.click() - await wait() + await timeout() const menu = app.find('.menu-droppo')[0] const children = menu.children @@ -73,7 +93,7 @@ async function runFirstTimeUsageTest(assert, done) { assert.ok(lock, 'Lock menu item found') lock.click() - await wait(1000) + await timeout(1000) const pwBox2 = app.find('#password-box')[0] pwBox2.value = PASSWORD @@ -81,39 +101,47 @@ async function runFirstTimeUsageTest(assert, done) { const createButton2 = app.find('button.primary')[0] createButton2.click() - await wait(1000) + await timeout(1000) const detail2 = app.find('.account-detail-section')[0] assert.ok(detail2, 'Account detail section loaded again.') - await wait() + await timeout() // open account settings dropdown const qrButton = app.find('.fa.fa-ellipsis-h')[0] qrButton.click() - await wait(1000) + await timeout(1000) // qr code item const qrButton2 = app.find('.dropdown-menu-item')[1] qrButton2.click() - await wait(1000) + await timeout(1000) const qrHeader = app.find('.qr-header')[0] const qrContainer = app.find('#qr-container')[0] assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.') assert.ok(qrContainer, 'QR Container found') - await wait() + await timeout() const networkMenu = app.find('.network-indicator')[0] networkMenu.click() - await wait() + await timeout() const networkMenu2 = app.find('.network-indicator')[0] const children2 = networkMenu2.children children2.length[3] assert.ok(children2, 'All network options present') -} \ No newline at end of file +} + +function timeout(time) { + return new Promise(function (resolve, reject) { + setTimeout(function () { + resolve() + }, time * 3 || 1500) + }) +} From 48d21f4fca75e1f012ee881eb741a703051ee338 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 22:34:16 -0700 Subject: [PATCH 7/8] tests - integration - fix bad cherry-pick --- test/integration/lib/first-time.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index c5ecfef95..38a94e551 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -5,13 +5,11 @@ QUnit.module('first time usage') QUnit.test('render init screen', (assert) => { const done = assert.async() runFirstTimeUsageTest(assert).then(done).catch((err) => { - assert.notOk(err, 'Should not error') + assert.notOk(err, `Error was thrown: ${err.stack}`) done() }) }) -<<<<<<< HEAD -======= // QUnit.testDone(({ module, name, total, passed, failed, skipped, todo, runtime }) => { // if (failed > 0) { // const app = $('iframe').contents()[0].documentElement @@ -20,36 +18,29 @@ QUnit.test('render init screen', (assert) => { // } // }) ->>>>>>> 5c53bab... test - integration - drop testem for karma async function runFirstTimeUsageTest(assert, done) { await timeout() const app = $('#app-content .mock-app-root') - const recurseNotices = async () => { + // recurse notices + while (true) { const button = app.find('button') if (button.html() === 'Accept') { + // still notices to accept const termsPage = app.find('.markdown')[0] termsPage.scrollTop = termsPage.scrollHeight await timeout() button.click() -<<<<<<< HEAD - await wait() - await recurseNotices() -======= await timeout() ->>>>>>> 5c53bab... test - integration - drop testem for karma } else { - await wait() + // exit loop + break } } -<<<<<<< HEAD - await recurseNotices() -======= await timeout() ->>>>>>> 5c53bab... test - integration - drop testem for karma // Scroll through terms const title = app.find('h1').text() @@ -144,4 +135,4 @@ function timeout(time) { resolve() }, time * 3 || 1500) }) -} +} \ No newline at end of file From 22c7049f6c195e0b3775a1aa78f92fdbe2ac2559 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 11 Sep 2017 22:34:59 -0700 Subject: [PATCH 8/8] ci - remove old testem config --- testem.yml | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 testem.yml diff --git a/testem.yml b/testem.yml deleted file mode 100644 index 7923a2929..000000000 --- a/testem.yml +++ /dev/null @@ -1,9 +0,0 @@ -launch_in_dev: - - Chrome - - Firefox -launch_in_ci: - - Chrome - - Firefox -framework: - - qunit -test_page: "test/integration/index.html"