From 5e05e32c32456ad87a15fb8f991db5b8e1de9722 Mon Sep 17 00:00:00 2001 From: Ryan Ghods Date: Thu, 30 Apr 2020 11:51:04 -0700 Subject: [PATCH] Add karma test runner --- karma.conf.js | 23 +++++++++++++++++++++++ package.json | 13 +++++++++---- test/dataTypes.spec.ts | 11 +++++++---- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 karma.conf.js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..058a266 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,23 @@ +module.exports = function(config) { + config.set({ + frameworks: ['mocha', 'karma-typescript'], + files: ['src/**/*.ts', 'test/**/!(integration)*.ts'], + preprocessors: { + '**/*.ts': ['karma-typescript'], + }, + plugins: ['karma-mocha', 'karma-typescript', 'karma-chrome-launcher', 'karma-firefox-launcher'], + karmaTypescriptConfig: { + bundlerOptions: { + entrypoints: /\.spec\.ts$/, + }, + }, + colors: true, + reporters: ['progress', 'karma-typescript'], + browsers: ['FirefoxHeadless', 'ChromeHeadless'], + singleRun: true, + concurrency: Infinity, + // Fail after timeout + browserDisconnectTimeout: 100000, + browserNoActivityTimeout: 100000, + }) +} \ No newline at end of file diff --git a/package.json b/package.json index e8ab9db..bf4cb75 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "lint": "npm run format && npm run tslint && npm run tsc", "lint:fix": "npm run format:fix && npm run tslint:fix && npm run tsc", "unitTests": "mocha --reporter spec --require ts-node/register test/*.spec.ts", - "test": "npm run lint && npm run build && npm run unitTests", - "test:fix": "npm run lint:fix && npm run unitTests", - "webtest": "browserify test/max.js | testling -u" + "test": "npm run lint && npm run build && npm run unitTests && npm run test:browser", + "test:browser": "karma start karma.conf.js", + "test:fix": "npm run lint:fix && npm run unitTests" }, "husky": { "hooks": { @@ -61,7 +61,12 @@ "@types/mocha": "^5.2.5", "@types/node": "^10.12.2", "husky": "^2.1.0", - "mocha": "4.1.0", + "karma": "^5.0.2", + "karma-chrome-launcher": "^2.0.0", + "karma-firefox-launcher": "^1.0.0", + "karma-mocha": "^2.0.0", + "karma-typescript": "^4.1.1", + "mocha": "7.1.2", "nyc": "^15.0.1", "prettier": "^1.15.2", "ts-node": "^8.9.1", diff --git a/test/dataTypes.spec.ts b/test/dataTypes.spec.ts index d15003d..f09222a 100644 --- a/test/dataTypes.spec.ts +++ b/test/dataTypes.spec.ts @@ -2,6 +2,7 @@ import { version } from 'process' import * as assert from 'assert' import * as RLP from '../src' const BN = require('bn.js') +const Buffer = require('buffer').Buffer // needed for karma describe('invalid rlps', function() { it('should not crash on an invalid rlp', function() { @@ -64,10 +65,12 @@ describe('RLP encoding (list):', function() { describe('RLP encoding (BigInt):', function() { before(function() { - const nodeVersionNumber = Number(version.match(/^v([0-9]+)/)![1]) - if (nodeVersionNumber < 10) { - // tslint:disable-next-line no-invalid-this - this.skip() + if (version) { + const nodeVersionNumber = Number(version.match(/^v([0-9]+)/)![1]) + if (nodeVersionNumber < 10) { + // tslint:disable-next-line no-invalid-this + this.skip() + } } }) it('should encode a BigInt value', function() {