Skip to content

Commit 7d97b38

Browse files
committed
Set up Jest testing framework
1 parent 61f4d5e commit 7d97b38

File tree

7 files changed

+47
-6825
lines changed

7 files changed

+47
-6825
lines changed

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ dist
33
coverage
44
**/*.d.ts
55
test
6-
_temp_extension
6+
_temp_extension
7+
babel.config.ts
8+
jest.config.ts

babel.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current'
8+
}
9+
}
10+
]
11+
]
12+
};

jest.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import path = require('path');
2+
3+
const config = function(baseDir: string) {
4+
return {
5+
preset: 'ts-jest/presets/js-with-babel',
6+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7+
transformIgnorePatterns: ['/node_modules/(?!(@jupyterlab/.*)/)'],
8+
reporters: ['default', 'jest-junit', 'jest-summary-reporter'],
9+
coverageReporters: ['json', 'lcov', 'text', 'html'],
10+
coverageDirectory: path.join(baseDir, 'coverage'),
11+
testRegex: '/test/.*.ts[x]?$',
12+
globals: {
13+
'ts-jest': {
14+
tsConfig: 'tsconfig.test.json'
15+
}
16+
}
17+
};
18+
};
19+
20+
module.exports = config(__dirname);

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
"prepare": "jlpm run clean && jlpm run build:prod",
4545
"watch": "run-p watch:src watch:labextension",
4646
"watch:labextension": "jupyter labextension watch .",
47-
"watch:src": "tsc -w"
47+
"watch:src": "tsc -w",
48+
"test": "jest",
49+
"test:cov": "jest --collect-coverage"
4850
},
4951
"dependencies": {
5052
"@jupyterlab/application": "^3.0.3",
@@ -71,6 +73,9 @@
7173
"@typescript-eslint/eslint-plugin": "^2.27.0",
7274
"@typescript-eslint/parser": "^2.27.0",
7375
"eslint": "^7.5.0",
76+
"@babel/core": "^7",
77+
"@babel/preset-env": "^7",
78+
"@types/jest": "^24",
7479
"eslint-config-prettier": "^6.10.1",
7580
"eslint-plugin-prettier": "^3.1.2",
7681
"eslint-plugin-react": "^7.20.4",
@@ -82,7 +87,8 @@
8287
"npm-run-all": "^4.1.5",
8388
"prettier": "^1.19.0",
8489
"rimraf": "^3.0.2",
85-
"typescript": "~4.1.3"
90+
"typescript": "~4.1.3",
91+
"ts-jest": "^24"
8692
},
8793
"sideEffects": [
8894
"style/*.css",

test/test.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test('two plus two is four', () => {
2+
expect(2 + 2).toBe(4);
3+
});

tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"es2015.iterable",
1616
"es2017.object"
1717
],
18-
"types": ["jest"],
18+
"types": ["jest", "node"],
1919
"typeRoots": ["./types", "./node_modules/@types"],
2020
"jsx": "react",
2121
"resolveJsonModule": true,

0 commit comments

Comments
 (0)