Skip to content

Commit 3114d97

Browse files
author
Ian Tan
committed
test(): set up Jest as test framework
1 parent 0a17b6b commit 3114d97

File tree

6 files changed

+1910
-116
lines changed

6 files changed

+1910
-116
lines changed

.babelrc

+67-77
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,71 @@
11
{
2-
"presets": [
3-
[
4-
"@babel/env",
5-
{
6-
"modules": false,
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"modules": false,
7+
"targets": {
8+
"browsers": [
9+
">0.25%"
10+
]
11+
},
12+
"useBuiltIns": "usage"
13+
}
14+
],
15+
"@babel/typescript"
16+
],
17+
"env": {
18+
"development": {
19+
"plugins": [
20+
"@babel/transform-runtime"
21+
]
22+
},
23+
"production": {
24+
"plugins": [
25+
"@babel/transform-runtime",
26+
"transform-remove-console"
27+
]
28+
},
29+
"test": {
30+
"presets": [
31+
[
32+
"@babel/env",
33+
{
34+
"modules": "commonjs",
735
"targets": {
8-
"browsers": [
9-
">0.25%"
10-
]
11-
},
12-
"useBuiltIns": "usage"
13-
}
14-
],
15-
"@babel/typescript"
16-
],
17-
"env": {
18-
"development": {
19-
"plugins": [
20-
"@babel/transform-runtime"
21-
]
22-
},
23-
"production": {
24-
"plugins": [
25-
"@babel/transform-runtime",
26-
"transform-remove-console"
27-
]
28-
},
29-
"test": {
30-
"presets": [
31-
[
32-
"@babel/env",
33-
{
34-
"modules": "commonjs",
35-
"targets": {
36-
"node": "current"
37-
}
38-
}
39-
],
40-
[
41-
"@babel/stage-1",
42-
{
43-
"decoratorsLegacy": true
44-
}
45-
],
46-
"@babel/typescript"
47-
],
48-
"plugins": [
49-
"@babel/transform-runtime",
50-
"@babel/plugin-transform-modules-commonjs"
51-
]
36+
"node": "current"
37+
}
38+
}
39+
],
40+
"@babel/typescript"
41+
]
42+
}
43+
},
44+
"plugins": [
45+
"@babel/plugin-syntax-dynamic-import",
46+
"@babel/plugin-syntax-import-meta",
47+
"@babel/plugin-proposal-class-properties",
48+
"@babel/plugin-proposal-json-strings",
49+
[
50+
"@babel/plugin-proposal-decorators",
51+
{
52+
"legacy": true
53+
}
54+
],
55+
"@babel/plugin-proposal-function-sent",
56+
"@babel/plugin-proposal-export-namespace-from",
57+
"@babel/plugin-proposal-numeric-separator",
58+
"@babel/plugin-proposal-throw-expressions",
59+
"@babel/plugin-proposal-export-default-from",
60+
"@babel/plugin-proposal-logical-assignment-operators",
61+
"@babel/plugin-proposal-optional-chaining",
62+
[
63+
"@babel/plugin-proposal-pipeline-operator",
64+
{
65+
"proposal": "minimal"
5266
}
53-
},
54-
"plugins": [
55-
"@babel/plugin-syntax-dynamic-import",
56-
"@babel/plugin-syntax-import-meta",
57-
"@babel/plugin-proposal-class-properties",
58-
"@babel/plugin-proposal-json-strings",
59-
[
60-
"@babel/plugin-proposal-decorators",
61-
{
62-
"legacy": true
63-
}
64-
],
65-
"@babel/plugin-proposal-function-sent",
66-
"@babel/plugin-proposal-export-namespace-from",
67-
"@babel/plugin-proposal-numeric-separator",
68-
"@babel/plugin-proposal-throw-expressions",
69-
"@babel/plugin-proposal-export-default-from",
70-
"@babel/plugin-proposal-logical-assignment-operators",
71-
"@babel/plugin-proposal-optional-chaining",
72-
[
73-
"@babel/plugin-proposal-pipeline-operator",
74-
{
75-
"proposal": "minimal"
76-
}
77-
],
78-
"@babel/plugin-proposal-nullish-coalescing-operator",
79-
"@babel/plugin-proposal-do-expressions"
80-
]
67+
],
68+
"@babel/plugin-proposal-nullish-coalescing-operator",
69+
"@babel/plugin-proposal-do-expressions"
70+
]
8171
}

jest-setup.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const crypto = require('@trust/webcrypto');
2+
window.crypto = crypto;

jest.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const config = {
2+
transform: {
3+
'^.+\\.(t|j)s$': 'ts-jest',
4+
},
5+
testMatch: [
6+
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
7+
'<rootDir>/src/**/?(*.)+(spec|test).ts?(x)',
8+
],
9+
moduleDirectories: ['src', 'node_modules'],
10+
moduleFileExtensions: ['js', 'ts'],
11+
globals: {
12+
'ts-jest': { useBabelrc: true },
13+
},
14+
testURL: 'http://localhost',
15+
coverageThreshold: {
16+
global: {
17+
branches: 80,
18+
functions: 80,
19+
lines: 80,
20+
statements: 80,
21+
},
22+
},
23+
setupFiles: ['<rootDir>/jest-setup.js'],
24+
watchPlugins: [
25+
'jest-watch-typeahead/filename',
26+
'jest-watch-typeahead/testname',
27+
],
28+
}
29+
30+
module.exports = config;

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"typings": "dist/index.d.ts",
77
"scripts": {
88
"build": "rimraf dist/* && tsc --emitDeclarationOnly && cross-env NODE_ENV=production webpack --config webpack.config.js",
9-
"test": "mocha"
9+
"test": "jest -c jest.config.js"
1010
},
1111
"dependencies": {
1212
"bn.js": "^4.11.8",
@@ -40,8 +40,12 @@
4040
"@babel/preset-env": "7.0.0-beta.54",
4141
"@babel/preset-typescript": "^7.0.0-beta.56",
4242
"@babel/runtime": "^7.0.0-beta.56",
43+
"@trust/webcrypto": "^0.9.2",
44+
"@types/jest": "^23.3.1",
4345
"@types/node": "^10.5.6",
4446
"@types/valid-url": "^1.0.2",
47+
"babel-core": "^7.0.0-bridge.0",
48+
"babel-jest": "^23.4.2",
4549
"babel-loader": "^8.0.0-beta.0",
4650
"babel-plugin-transform-remove-console": "^6.9.4",
4751
"babelify": "^8.0.0",
@@ -52,7 +56,10 @@
5256
"gulp-uglify-es": "^1.0.4",
5357
"gulp-util": "^3.0.8",
5458
"hoek": "^5.0.3",
59+
"jest": "^23.4.2",
60+
"jest-watch-typeahead": "^0.2.0",
5561
"mocha": "^5.2.0",
62+
"ts-jest": "^23.1.3",
5663
"tslint": "^5.11.0",
5764
"typescript": "^3.0.1",
5865
"vinyl-buffer": "^1.0.1",

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
3-
"allowSyntheticDefaultImports": true,
3+
"allowJs": true,
4+
"esModuleInterop": true,
45
"outDir": "dist",
56
"module": "commonjs",
67
"target": "es5",

0 commit comments

Comments
 (0)