aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--package.json11
-rw-r--r--test/helper.js51
-rw-r--r--test/unit/keyring-controller-test.js2
-rw-r--r--test/unit/notice-controller-test.js33
4 files changed, 72 insertions, 25 deletions
diff --git a/package.json b/package.json
index ba6a81da9..9b83ca317 100644
--- a/package.json
+++ b/package.json
@@ -5,20 +5,20 @@
"private": true,
"scripts": {
"start": "npm run dev",
- "lint": "gulp lint",
- "buildCiUnits": "node test/integration/index.js",
"dev": "gulp dev --debug",
"disc": "gulp disc --debug",
"dist": "gulp dist --disableLiveReload",
- "test": "npm run lint && npm run fastTest && npm run ci",
- "fastTest": "METAMASK_ENV=test mocha --require test/helper.js --recursive \"test/unit/**/*.js\"",
+ "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\"",
+ "test-integration": "npm run buildMock && npm run buildCiUnits && testem ci -P 2",
+ "lint": "gulp lint",
+ "buildCiUnits": "node test/integration/index.js",
"watch": "mocha watch --recursive \"test/unit/**/*.js\"",
"genStates": "node development/genStates.js",
"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",
- "ci": "npm run buildMock && npm run buildCiUnits && testem ci -P 2",
"announce": "node development/announcer.js",
"generateNotice": "node notices/notice-generator.js",
"deleteNotice": "node notices/notice-delete.js"
@@ -40,6 +40,7 @@
"async": "^1.5.2",
"async-q": "^0.3.1",
"bip39": "^2.2.0",
+ "bluebird": "^3.5.0",
"browser-passworder": "^2.0.3",
"browserify-derequire": "^0.9.4",
"clone": "^1.0.2",
diff --git a/test/helper.js b/test/helper.js
index a01ea1e53..aaac7580e 100644
--- a/test/helper.js
+++ b/test/helper.js
@@ -1,11 +1,54 @@
+// disallow promises from swallowing errors
+enableFailureOnUnhandledPromiseRejection()
+
+// logging util
var log = require('loglevel')
log.setDefaultLevel(5)
+global.log = log
+//
+// polyfills
+//
+
+// dom
require('jsdom-global')()
+
+// localStorage
window.localStorage = {}
-if (!('crypto' in window)) { window.crypto = {} }
-window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
+// crypto.getRandomValues
+if (!window.crypto) window.crypto = {}
+if (!window.crypto.getRandomValues) window.crypto.getRandomValues = require('polyfill-crypto.getrandomvalues')
-window.log = log
-global.log = log
+
+
+function enableFailureOnUnhandledPromiseRejection() {
+ // overwrite node's promise with the stricter Bluebird promise
+ global.Promise = require('bluebird')
+
+ // modified from https://github.com/mochajs/mocha/issues/1926#issuecomment-180842722
+
+ // rethrow unhandledRejections
+ if (typeof process !== 'undefined') {
+ process.on('unhandledRejection', function (reason) {
+ throw reason
+ })
+ } else if (typeof window !== 'undefined') {
+ // 2016-02-01: No browsers support this natively, however bluebird, when.js,
+ // and probably other libraries do.
+ if (typeof window.addEventListener === 'function') {
+ window.addEventListener('unhandledrejection', function (evt) {
+ throw evt.detail.reason
+ })
+ } else {
+ var oldOHR = window.onunhandledrejection
+ window.onunhandledrejection = function (evt) {
+ if (typeof oldOHR === 'function') oldOHR.apply(this, arguments)
+ throw evt.detail.reason
+ }
+ }
+ } else if (typeof console !== 'undefined' &&
+ typeof (console.error || console.log) === 'function') {
+ (console.error || console.log)('Unhandled rejections will be ignored!')
+ }
+} \ No newline at end of file
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index aae4cdfd6..efd0a3546 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -135,7 +135,7 @@ describe('KeyringController', function() {
})
describe('#getAccounts', function() {
- it('returns the result of getAccounts for each keyring', function() {
+ it('returns the result of getAccounts for each keyring', function(done) {
keyringController.keyrings = [
{ getAccounts() { return Promise.resolve([1,2,3]) } },
{ getAccounts() { return Promise.resolve([4,5,6]) } },
diff --git a/test/unit/notice-controller-test.js b/test/unit/notice-controller-test.js
index 73fdb2f2e..ea37108bb 100644
--- a/test/unit/notice-controller-test.js
+++ b/test/unit/notice-controller-test.js
@@ -11,8 +11,6 @@ describe('notice-controller', function() {
beforeEach(function() {
// simple localStorage polyfill
- window.localStorage = {}
- if (window.localStorage.clear) window.localStorage.clear()
let configManager = configManagerGen()
noticeController = new NoticeController({
configManager: configManager,
@@ -21,7 +19,7 @@ describe('notice-controller', function() {
describe('notices', function() {
describe('#getNoticesList', function() {
- it('should return an empty array when new', function() {
+ it('should return an empty array when new', function(done) {
var testList = [{
id:0,
read:false,
@@ -29,11 +27,12 @@ describe('notice-controller', function() {
}]
var result = noticeController.getNoticesList()
assert.equal(result.length, 0)
+ done()
})
})
describe('#setNoticesList', function() {
- it('should set data appropriately', function () {
+ it('should set data appropriately', function (done) {
var testList = [{
id:0,
read:false,
@@ -42,11 +41,12 @@ describe('notice-controller', function() {
noticeController.setNoticesList(testList)
var testListId = noticeController.getNoticesList()[0].id
assert.equal(testListId, 0)
+ done()
})
})
describe('#updateNoticeslist', function() {
- it('should integrate the latest changes from the source', function() {
+ it('should integrate the latest changes from the source', function(done) {
var testList = [{
id:55,
read:false,
@@ -57,26 +57,26 @@ describe('notice-controller', function() {
var newList = noticeController.getNoticesList()
assert.ok(newList[0].id === 55)
assert.ok(newList[1])
+ done()
})
})
- it('should not overwrite any existing fields', function () {
+ it('should not overwrite any existing fields', function (done) {
var testList = [{
id:0,
read:false,
title:"Futuristic Notice"
}]
noticeController.setNoticesList(testList)
- noticeController.updateNoticesList().then(() => {
- var newList = noticeController.getNoticesList()
- assert.equal(newList[0].id, 0)
- assert.equal(newList[0].title, "Futuristic Notice")
- assert.equal(newList.length, 1)
- })
+ var newList = noticeController.getNoticesList()
+ assert.equal(newList[0].id, 0)
+ assert.equal(newList[0].title, "Futuristic Notice")
+ assert.equal(newList.length, 1)
+ done()
})
})
describe('#markNoticeRead', function () {
- it('should mark a notice as read', function () {
+ it('should mark a notice as read', function (done) {
var testList = [{
id:0,
read:false,
@@ -86,11 +86,12 @@ describe('notice-controller', function() {
noticeController.markNoticeRead(testList[0])
var newList = noticeController.getNoticesList()
assert.ok(newList[0].read)
+ done()
})
})
describe('#getLatestUnreadNotice', function () {
- it('should retrieve the latest unread notice', function () {
+ it('should retrieve the latest unread notice', function (done) {
var testList = [
{id:0,read:true,title:"Past Notice"},
{id:1,read:false,title:"Current Notice"},
@@ -99,8 +100,9 @@ describe('notice-controller', function() {
noticeController.setNoticesList(testList)
var latestUnread = noticeController.getLatestUnreadNotice()
assert.equal(latestUnread.id, 2)
+ done()
})
- it('should return undefined if no unread notices exist.', function () {
+ it('should return undefined if no unread notices exist.', function (done) {
var testList = [
{id:0,read:true,title:"Past Notice"},
{id:1,read:true,title:"Current Notice"},
@@ -109,6 +111,7 @@ describe('notice-controller', function() {
noticeController.setNoticesList(testList)
var latestUnread = noticeController.getLatestUnreadNotice()
assert.ok(!latestUnread)
+ done()
})
})
})