diff --git a/.gitignore b/.gitignore index 7b35ef1..de7638c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ core log.txt package-lock.json gen/ +test_tmp/ diff --git a/.npmignore b/.npmignore index 7ab2ef2..7abd979 100644 --- a/.npmignore +++ b/.npmignore @@ -6,3 +6,4 @@ package-lock.json gen/ scripts/ +test_tmp/ diff --git a/.travis.yml b/.travis.yml index 0b84ddb..c37f442 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: node_js +sudo: required os: - linux node_js: diff --git a/config/karma.conf.js b/config/karma.conf.js index 8de339b..cbe6237 100644 --- a/config/karma.conf.js +++ b/config/karma.conf.js @@ -2,41 +2,64 @@ const configuration = { basePath: '', frameworks: [ 'mocha', - 'browserify' + 'browserify', + 'detectBrowsers' ], files: [ - '../test/unit.test.js', - '../test/issues.test.js', - '../test/performance.test.js' + '../test_tmp/karma.test.js' ], port: 9876, colors: true, autoWatch: false, + /** + * see + * @link https://github.com/litixsoft/karma-detect-browsers + */ + detectBrowsers: { + enabled: true, + usePhantomJS: false, + postDetection: function(availableBrowser) { + return ['Firefox']; // comment in to test specific browser + const browsers = availableBrowser + .filter(b => !['PhantomJS', 'FirefoxAurora', 'FirefoxNightly'].includes(b)) + .map(b => { + if (b === 'Chrome') return 'Chrome_travis_ci'; + else return b; + }); + return browsers; + } + }, + // Karma plugins loaded plugins: [ 'karma-mocha', 'karma-browserify', - 'karma-chrome-launcher' + 'karma-chrome-launcher', + 'karma-edge-launcher', + 'karma-firefox-launcher', + 'karma-ie-launcher', + 'karma-opera-launcher', + 'karma-detect-browsers' ], // Source files that you wanna generate coverage for. // Do not include tests or libraries (these files will be instrumented by Istanbul) preprocessors: { - '../test/*.test.js': ['browserify'] + '../test_tmp/*.test.js': ['browserify'] }, client: { mocha: { bail: true, - timeout: 6000 + timeout: 12000 } }, - browsers: ['ChromeNoSandbox'], - browserDisconnectTimeout: 6000, - processKillTimeout: 6000, + browsers: ['Chrome_travis_ci'], + browserDisconnectTimeout: 12000, + processKillTimeout: 12000, customLaunchers: { - ChromeNoSandbox: { + Chrome_travis_ci: { base: 'Chrome', flags: ['--no-sandbox'] } @@ -45,12 +68,12 @@ const configuration = { }; if (process.env.TRAVIS) { - + configuration.browsers = ['Chrome_travis_ci']; /** * overwrite reporters-default * So no big list will be shown at log */ - // configuration.reporters = []; + configuration.reporters = []; } module.exports = function(config) { diff --git a/package.json b/package.json index 53356dc..bea5631 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,12 @@ "test:node": "npm run build && mocha ./test/index.test.js -b --timeout 6000 --exit", "test:browser": "npm run build && karma start ./config/karma.conf.js --single-run", "lint": "eslint --ignore-path ./config/.eslintignore src test config scripts && solhint \"contracts/**/*.sol\"", - "clear": "rimraf -rf ./dist && rimraf -rf ./gen", + "clear": "rimraf -rf ./dist && rimraf -rf ./gen && rimraf -rf ./test_tmp", "build:sol": "solidity-cli -i './contracts/*.sol' -o ./gen", "build:es6": "rimraf -rf dist/es && cross-env NODE_ENV=es6 babel src --out-dir dist/es", "build:es5": "cross-env NODE_ENV=es5 node node_modules/babel-cli/bin/babel.js src --out-dir dist/lib", - "build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5\" \"npm run build:sol\"" + "build:test": "cross-env NODE_ENV=es5 node node_modules/babel-cli/bin/babel.js test --out-dir test_tmp", + "build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5\" \"npm run build:test\" \"npm run build:sol\"" }, "repository": { "type": "git", @@ -43,7 +44,7 @@ "homepage": "https://github.com/pubkey/eth-crypto#readme", "devDependencies": { "assert": "1.4.1", - "async-test-util": "1.5.1", + "async-test-util": "1.6.1", "babel-cli": "6.26.0", "babel-core": "6.26.3", "babel-eslint": "8.2.3", @@ -70,15 +71,22 @@ "cross-env": "5.1.6", "eslint": "4.19.1", "ganache-cli": "6.1.0", + "is-node": "1.0.2", "js-sha3": "0.7.0", "karma": "2.0.2", "karma-babel-preprocessor": "7.0.0", "karma-browserify": "5.2.0", "karma-chrome-launcher": "2.2.0", "karma-coverage": "1.1.2", + "karma-detect-browsers": "2.3.2", + "karma-edge-launcher": "0.4.2", + "karma-firefox-launcher": "1.1.0", + "karma-ie-launcher": "1.0.0", "karma-mocha": "1.3.0", + "karma-opera-launcher": "1.0.0", + "karma-safari-launcher": "1.0.0", "mocha": "5.2.0", - "node": "10.1.0", + "node": "10.3.0", "rimraf": "2.6.2", "solhint": "1.2.1", "solidity-cli": "1.0.1", diff --git a/test/issues.test.js b/test/issues.test.js index 1bf0e2f..a78155f 100644 --- a/test/issues.test.js +++ b/test/issues.test.js @@ -44,13 +44,4 @@ describe('issues.test.js', () => { ); assert.ok(signer); }); - it('#6 web3 should not set window.Web3', () => { - if (typeof window !== 'undefined' && window){ - const web3 = EthCrypto.util.web3; - assert.ok(web3); - - assert.deepEqual(window.Web3, undefined); - } - }); - }); diff --git a/test/karma.test.js b/test/karma.test.js new file mode 100644 index 0000000..929968c --- /dev/null +++ b/test/karma.test.js @@ -0,0 +1,3 @@ +require('./unit.test'); +require('./issues.test'); +require('./performance.test'); diff --git a/test/performance.test.js b/test/performance.test.js index 4f3ae36..5a75a44 100644 --- a/test/performance.test.js +++ b/test/performance.test.js @@ -1,6 +1,4 @@ -const convertHrtime = require('convert-hrtime'); const AsyncTestUtil = require('async-test-util'); - const EthCrypto = require('../dist/lib/index'); const benchmark = { @@ -11,19 +9,11 @@ const benchmark = { }; const nowTime = () => { - try { - return process.hrtime(); - } catch (err) { - return performance.now(); - } + return AsyncTestUtil.performanceNow(); }; const elapsedTime = before => { - try { - return convertHrtime(process.hrtime(before)).milliseconds; - } catch (err) { - return performance.now() - before; - } + return AsyncTestUtil.performanceNow() - before; }; describe('performance.test.js', () => {