mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Setup test enviroment for mascara
This commit is contained in:
parent
e7c7c85791
commit
e7e0919d7c
@ -1,4 +1,5 @@
|
|||||||
global.window = global
|
global.window = global
|
||||||
|
const self = global
|
||||||
const pipe = require('pump')
|
const pipe = require('pump')
|
||||||
|
|
||||||
const SwGlobalListener = require('sw-stream/lib/sw-global-listener.js')
|
const SwGlobalListener = require('sw-stream/lib/sw-global-listener.js')
|
||||||
|
7
mascara/test/helpers.js
Normal file
7
mascara/test/helpers.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
function wait(time) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
setTimeout(function() {
|
||||||
|
resolve()
|
||||||
|
}, time * 3 || 1500)
|
||||||
|
})
|
||||||
|
}
|
20
mascara/test/index.html
Normal file
20
mascara/test/index.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width">
|
||||||
|
<title>QUnit Example</title>
|
||||||
|
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.0.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="qunit"></div>
|
||||||
|
<div id="qunit-fixture"></div>
|
||||||
|
<script src="https://code.jquery.com/qunit/qunit-2.0.0.js"></script>
|
||||||
|
<script src="./jquery-3.1.0.min.js"></script>
|
||||||
|
<script src="./helpers.js"></script>
|
||||||
|
<script src="./test-bundle.js"></script>
|
||||||
|
<script src="/testem.js"></script>
|
||||||
|
<script src="./bundle.js"></script>
|
||||||
|
<div id="app-content"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
20
mascara/test/index.js
Normal file
20
mascara/test/index.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
var fs = require('fs')
|
||||||
|
var path = require('path')
|
||||||
|
var browserify = require('browserify');
|
||||||
|
var tests = fs.readdirSync(path.join(__dirname, 'lib'))
|
||||||
|
var bundlePath = path.join(__dirname, 'test-bundle.js')
|
||||||
|
var b = browserify();
|
||||||
|
|
||||||
|
// Remove old bundle
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(bundlePath)
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
var writeStream = fs.createWriteStream(bundlePath)
|
||||||
|
|
||||||
|
tests.forEach(function(fileName) {
|
||||||
|
b.add(path.join(__dirname, 'lib', fileName))
|
||||||
|
})
|
||||||
|
|
||||||
|
b.bundle().pipe(writeStream);
|
||||||
|
|
4
mascara/test/jquery-3.1.0.min.js
vendored
Normal file
4
mascara/test/jquery-3.1.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
119
mascara/test/lib/first-time.js
Normal file
119
mascara/test/lib/first-time.js
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
const PASSWORD = 'password123'
|
||||||
|
|
||||||
|
QUnit.module('first time usage')
|
||||||
|
|
||||||
|
QUnit.test('render init screen', function (assert) {
|
||||||
|
var done = assert.async()
|
||||||
|
let app
|
||||||
|
|
||||||
|
wait().then(function() {
|
||||||
|
app = $('#app-content')
|
||||||
|
const recurseNotices = function () {
|
||||||
|
let button = app.find('button')
|
||||||
|
if (button.html() === 'Continue') {
|
||||||
|
let termsPage = app.find('.markdown')[0]
|
||||||
|
termsPage.scrollTop = termsPage.scrollHeight
|
||||||
|
return wait().then(() => {
|
||||||
|
button.click()
|
||||||
|
return wait()
|
||||||
|
}).then(() => {
|
||||||
|
return recurseNotices()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return wait()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return recurseNotices()
|
||||||
|
}).then(function() {
|
||||||
|
// Scroll through terms
|
||||||
|
var title = app.find('h1').text()
|
||||||
|
assert.equal(title, 'MetaMask', 'title screen')
|
||||||
|
|
||||||
|
// enter password
|
||||||
|
var pwBox = app.find('#password-box')[0]
|
||||||
|
var confBox = app.find('#password-box-confirm')[0]
|
||||||
|
pwBox.value = PASSWORD
|
||||||
|
confBox.value = PASSWORD
|
||||||
|
|
||||||
|
return wait()
|
||||||
|
}).then(function() {
|
||||||
|
|
||||||
|
// create vault
|
||||||
|
var createButton = app.find('button.primary')[0]
|
||||||
|
createButton.click()
|
||||||
|
|
||||||
|
return wait(1500)
|
||||||
|
}).then(function() {
|
||||||
|
|
||||||
|
var created = app.find('h3')[0]
|
||||||
|
assert.equal(created.textContent, 'Vault Created', 'Vault created screen')
|
||||||
|
|
||||||
|
// Agree button
|
||||||
|
var button = app.find('button')[0]
|
||||||
|
assert.ok(button, 'button present')
|
||||||
|
button.click()
|
||||||
|
|
||||||
|
return wait(1000)
|
||||||
|
}).then(function() {
|
||||||
|
|
||||||
|
var detail = app.find('.account-detail-section')[0]
|
||||||
|
assert.ok(detail, 'Account detail section loaded.')
|
||||||
|
|
||||||
|
var sandwich = app.find('.sandwich-expando')[0]
|
||||||
|
sandwich.click()
|
||||||
|
|
||||||
|
return wait()
|
||||||
|
}).then(function() {
|
||||||
|
|
||||||
|
var sandwich = app.find('.menu-droppo')[0]
|
||||||
|
var children = sandwich.children
|
||||||
|
var lock = children[children.length - 2]
|
||||||
|
assert.ok(lock, 'Lock menu item found')
|
||||||
|
lock.click()
|
||||||
|
|
||||||
|
return wait(1000)
|
||||||
|
}).then(function() {
|
||||||
|
|
||||||
|
var pwBox = app.find('#password-box')[0]
|
||||||
|
pwBox.value = PASSWORD
|
||||||
|
|
||||||
|
var createButton = app.find('button.primary')[0]
|
||||||
|
createButton.click()
|
||||||
|
|
||||||
|
return wait(1000)
|
||||||
|
}).then(function() {
|
||||||
|
|
||||||
|
var detail = app.find('.account-detail-section')[0]
|
||||||
|
assert.ok(detail, 'Account detail section loaded again.')
|
||||||
|
|
||||||
|
return wait()
|
||||||
|
}).then(function (){
|
||||||
|
|
||||||
|
var qrButton = app.find('.fa.fa-qrcode')[0]
|
||||||
|
qrButton.click()
|
||||||
|
|
||||||
|
return wait(1000)
|
||||||
|
}).then(function (){
|
||||||
|
|
||||||
|
var qrHeader = app.find('.qr-header')[0]
|
||||||
|
var qrContainer = app.find('#qr-container')[0]
|
||||||
|
assert.equal(qrHeader.textContent, 'Account 1', 'Should show account label.')
|
||||||
|
assert.ok(qrContainer, 'QR Container found')
|
||||||
|
|
||||||
|
return wait()
|
||||||
|
}).then(function (){
|
||||||
|
|
||||||
|
var networkMenu = app.find('.network-indicator')[0]
|
||||||
|
networkMenu.click()
|
||||||
|
|
||||||
|
return wait()
|
||||||
|
}).then(function (){
|
||||||
|
|
||||||
|
var networkMenu = app.find('.network-indicator')[0]
|
||||||
|
var children = networkMenu.children
|
||||||
|
children.length[3]
|
||||||
|
assert.ok(children, 'All network options present')
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
13
mascara/test/testem.yml
Normal file
13
mascara/test/testem.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
launch_in_dev:
|
||||||
|
- Chrome
|
||||||
|
- Firefox
|
||||||
|
- Opera
|
||||||
|
launch_in_ci:
|
||||||
|
- Chrome
|
||||||
|
- Firefox
|
||||||
|
- Opera
|
||||||
|
framework:
|
||||||
|
- qunit
|
||||||
|
before_tests: "npm run mascaraCi"
|
||||||
|
after_tests: "rm ./background.js ./test-bundle.js ./bundle.js"
|
||||||
|
test_page: "./index.html"
|
40
mascara/test/util/mascara-test-helper.js
Normal file
40
mascara/test/util/mascara-test-helper.js
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
const EventEmitter = require('events')
|
||||||
|
const IDB = require('../../../mascara/src/lib/index-db-controller')
|
||||||
|
const KEY = 'metamask-test-config'
|
||||||
|
module.exports = class Helper extends EventEmitter {
|
||||||
|
constructor () {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
|
||||||
|
tryToCleanContext () {
|
||||||
|
this.unregister()
|
||||||
|
.then(() => this.clearDb())
|
||||||
|
.then(() => super.emit('complete'))
|
||||||
|
.catch((err) => super.emit('complete'))
|
||||||
|
}
|
||||||
|
|
||||||
|
unregister () {
|
||||||
|
return global.navigator.serviceWorker.getRegistration()
|
||||||
|
.then((registration) => {
|
||||||
|
if (registration) return registration.unregister()
|
||||||
|
.then((b) => b ? Promise.resolve() : Promise.reject())
|
||||||
|
else return Promise.resolve()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
clearDb () {
|
||||||
|
return new Promise ((resolve, reject) => {
|
||||||
|
const deleteRequest = global.indexDB.deleteDatabase(KEY)
|
||||||
|
deleteRequest.addEventListener('success', resolve)
|
||||||
|
deleteRequest.addEventListener('error', reject)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
mockState (state) {
|
||||||
|
const db = new IDB({
|
||||||
|
version: 2,
|
||||||
|
key: KEY,
|
||||||
|
initialState: state
|
||||||
|
})
|
||||||
|
return db.open()
|
||||||
|
}
|
||||||
|
}
|
7
mascara/test/window-load.js
Normal file
7
mascara/test/window-load.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
const Helper = require('./util/mascara-test-helper.js')
|
||||||
|
debugger
|
||||||
|
window.addEventListener('load', () => {
|
||||||
|
const helper = new Helper()
|
||||||
|
helper.on('complete', () => require('../src/ui.js'))
|
||||||
|
helper.tryToCleanContext()
|
||||||
|
})
|
@ -22,7 +22,11 @@
|
|||||||
"announce": "node development/announcer.js",
|
"announce": "node development/announcer.js",
|
||||||
"generateNotice": "node notices/notice-generator.js",
|
"generateNotice": "node notices/notice-generator.js",
|
||||||
"deleteNotice": "node notices/notice-delete.js",
|
"deleteNotice": "node notices/notice-delete.js",
|
||||||
"mascara": "node ./mascara/example/server"
|
"mascara": "node ./mascara/example/server",
|
||||||
|
"buildMascaraCi": "browserify mascara/test/window-load.js -o mascara/test/bundle.js",
|
||||||
|
"buildMascaraSWCi": "browserify mascara/src/background.js -o mascara/test/background.js",
|
||||||
|
"mascaraCi": "npm run buildMascaraCi && npm run buildMascaraSWCi && node mascara/test/index.js",
|
||||||
|
"testMascara": "cd mascara/test && npm run mascaraCi && testem ci -P 3"
|
||||||
},
|
},
|
||||||
"browserify": {
|
"browserify": {
|
||||||
"transform": [
|
"transform": [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user