Skip to content

Commit 56d59ef

Browse files
committed
Set up Jest testing framework
1 parent 407d388 commit 56d59ef

File tree

7 files changed

+74
-4334
lines changed

7 files changed

+74
-4334
lines changed

.eslintignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ node_modules
22
dist
33
coverage
44
**/*.d.ts
5-
tests
6-
_temp_extension
5+
_temp_extension
6+
test
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: 9 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,16 +73,21 @@
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",
7782
"husky": "^4.2.5",
83+
"jest": "^24",
7884
"lint-staged": "^10.2.13",
7985
"mkdirp": "^1.0.3",
8086
"npm-run-all": "^4.1.5",
8187
"prettier": "^1.19.0",
8288
"rimraf": "^3.0.2",
83-
"typescript": "~4.1.3"
89+
"typescript": "~4.1.3",
90+
"ts-jest": "^24",
8491
},
8592
"sideEffects": [
8693
"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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"noImplicitAny": true,
5+
"noEmitOnError": true,
6+
"noUnusedLocals": true,
7+
"module": "commonjs",
8+
"moduleResolution": "node",
9+
"target": "es2015",
10+
"outDir": "lib",
11+
"lib": [
12+
"es2015",
13+
"es2015.collection",
14+
"dom",
15+
"es2015.iterable",
16+
"es2017.object"
17+
],
18+
"types": ["jest", "node"],
19+
"jsx": "react",
20+
"resolveJsonModule": true,
21+
"esModuleInterop": true,
22+
"strictNullChecks": true,
23+
"skipLibCheck": true
24+
},
25+
"include": ["src/*", "test/*"]
26+
}

0 commit comments

Comments
 (0)