Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.

Commit 5e05e32

Browse files
committed
Add karma test runner
1 parent 70f8320 commit 5e05e32

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

karma.conf.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = function(config) {
2+
config.set({
3+
frameworks: ['mocha', 'karma-typescript'],
4+
files: ['src/**/*.ts', 'test/**/!(integration)*.ts'],
5+
preprocessors: {
6+
'**/*.ts': ['karma-typescript'],
7+
},
8+
plugins: ['karma-mocha', 'karma-typescript', 'karma-chrome-launcher', 'karma-firefox-launcher'],
9+
karmaTypescriptConfig: {
10+
bundlerOptions: {
11+
entrypoints: /\.spec\.ts$/,
12+
},
13+
},
14+
colors: true,
15+
reporters: ['progress', 'karma-typescript'],
16+
browsers: ['FirefoxHeadless', 'ChromeHeadless'],
17+
singleRun: true,
18+
concurrency: Infinity,
19+
// Fail after timeout
20+
browserDisconnectTimeout: 100000,
21+
browserNoActivityTimeout: 100000,
22+
})
23+
}

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"lint": "npm run format && npm run tslint && npm run tsc",
2121
"lint:fix": "npm run format:fix && npm run tslint:fix && npm run tsc",
2222
"unitTests": "mocha --reporter spec --require ts-node/register test/*.spec.ts",
23-
"test": "npm run lint && npm run build && npm run unitTests",
24-
"test:fix": "npm run lint:fix && npm run unitTests",
25-
"webtest": "browserify test/max.js | testling -u"
23+
"test": "npm run lint && npm run build && npm run unitTests && npm run test:browser",
24+
"test:browser": "karma start karma.conf.js",
25+
"test:fix": "npm run lint:fix && npm run unitTests"
2626
},
2727
"husky": {
2828
"hooks": {
@@ -61,7 +61,12 @@
6161
"@types/mocha": "^5.2.5",
6262
"@types/node": "^10.12.2",
6363
"husky": "^2.1.0",
64-
"mocha": "4.1.0",
64+
"karma": "^5.0.2",
65+
"karma-chrome-launcher": "^2.0.0",
66+
"karma-firefox-launcher": "^1.0.0",
67+
"karma-mocha": "^2.0.0",
68+
"karma-typescript": "^4.1.1",
69+
"mocha": "7.1.2",
6570
"nyc": "^15.0.1",
6671
"prettier": "^1.15.2",
6772
"ts-node": "^8.9.1",

test/dataTypes.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { version } from 'process'
22
import * as assert from 'assert'
33
import * as RLP from '../src'
44
const BN = require('bn.js')
5+
const Buffer = require('buffer').Buffer // needed for karma
56

67
describe('invalid rlps', function() {
78
it('should not crash on an invalid rlp', function() {
@@ -64,10 +65,12 @@ describe('RLP encoding (list):', function() {
6465

6566
describe('RLP encoding (BigInt):', function() {
6667
before(function() {
67-
const nodeVersionNumber = Number(version.match(/^v([0-9]+)/)![1])
68-
if (nodeVersionNumber < 10) {
69-
// tslint:disable-next-line no-invalid-this
70-
this.skip()
68+
if (version) {
69+
const nodeVersionNumber = Number(version.match(/^v([0-9]+)/)![1])
70+
if (nodeVersionNumber < 10) {
71+
// tslint:disable-next-line no-invalid-this
72+
this.skip()
73+
}
7174
}
7275
})
7376
it('should encode a BigInt value', function() {

0 commit comments

Comments
 (0)