diff --git a/.eslintrc b/.eslintrc index d7cb8022e..7fab8f127 100644 --- a/.eslintrc +++ b/.eslintrc @@ -98,7 +98,7 @@ "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, - "no-path-concat": 2, + "no-path-concat": 1, "no-proto": 2, "no-redeclare": 2, "no-regex-spaces": 2, diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 103ea5348..1eb04059d 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -5,7 +5,7 @@ const extension = require('./lib/extension') const fs = require('fs') const path = require('path') -const inpageText = fs.readFileSync(__dirname + '/inpage.js').toString() +const inpageText = fs.readFileSync(path.join(__dirname + '/inpage.js')).toString() // Eventually this streaming injection could be replaced with: // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js index e0e7c948b..b9d0ed06d 100644 --- a/app/scripts/lib/extension-instance.js +++ b/app/scripts/lib/extension-instance.js @@ -26,7 +26,10 @@ function Extension () { const _this = this apis.forEach(function (api) { - _this[api] = chrome ? chrome[api] : window[api] || browser.extension[api] + _this[api] = chrome !== undefined && chrome[api] ? chrome[api] + : window[api] ? window[api] + : browser && browser.extension && browser.extension[api] + ? browser.extension[api] : null }) } diff --git a/package.json b/package.json index 1691f769a..2c264cfd0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "private": true, "scripts": { "start": "gulp dev", - "test": "mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\" && npm run ci", + "test": "npm run fastTest && npm run ci", + "fastTest": "mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "watch": "mocha watch --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "ui": "node development/genStates.js && 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 ./", diff --git a/test/unit/extension-test.js b/test/unit/extension-test.js index 0a03a3b97..6b695e835 100644 --- a/test/unit/extension-test.js +++ b/test/unit/extension-test.js @@ -1,6 +1,8 @@ var assert = require('assert') var sinon = require('sinon') const ethUtil = require('ethereumjs-util') +GLOBAL.chrome = {} +GLOBAL.browser = {} var path = require('path') var Extension = require(path.join(__dirname, '..', '..', 'app', 'scripts', 'lib', 'extension-instance.js')) @@ -11,7 +13,7 @@ describe('extension', function() { let extension beforeEach(function() { - window.chrome = { + GLOBAL.chrome = { alarms: 'foo' } extension = new Extension() @@ -24,13 +26,20 @@ describe('extension', function() { describe('without chrome global', function() { let extension + let realWindow beforeEach(function() { - window.chrome = undefined - window.alarms = 'foo' + realWindow = window + window = GLOBAL + GLOBAL.chrome = undefined + GLOBAL.alarms = 'foo' extension = new Extension() }) + after(function() { + window = realWindow + }) + it('should use the global apis', function() { assert.equal(extension.alarms, 'foo') })