Skip to content

Commit b70ffd4

Browse files
authored
Introduce jest for testing. (#114)
We are already using Mocha as testing framework but for some reasons such as readability and convenience, we decided to use jest instead of Mocha. After this patch, ./bacardi test will run both of Mocha and jest. Once we write test codes enough in jest, we will deprecate Mocha. ISSUE=#99,#100 TBR=@hwanseung,@yjaeseok
1 parent 347cec5 commit b70ffd4

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

bootstrap/command/test

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function is_already_formatted() {
2828

2929
if is_already_formatted; then
3030
mocha --napi-modules examples/calculator.js
31+
node --napi-modules $(bacardi_path)/node_modules/jest/bin/jest.js
3132
else
3233
echo "You should run |bacardi format| command first."
3334
fi

package.json

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
{
22
"devDependencies": {
3+
"@types/jest": "^21.1.2",
34
"@types/node": "^8.0.24",
45
"bindings": "^1.3.0",
6+
"jest": "^21.2.1",
7+
"mkdirp": "^0.5.1",
58
"mocha": "^3.5.0",
69
"node-addon-api": "^0.6.3",
710
"node-gyp": "^3.6.2",
811
"nunjucks": "^3.0.1",
9-
"mkdirp": "^0.5.1",
1012
"snake-case": "^2.1.0",
13+
"ts-jest": "^21.1.0",
1114
"typescript": "^2.4.2",
1215
"webidl2": "^4.1.0"
1316
},
1417
"optionalDependencies": {
1518
"windows-build-tools": "^1.3.2"
19+
},
20+
"jest": {
21+
"moduleFileExtensions": [
22+
"js",
23+
"json",
24+
"jsx",
25+
"ts",
26+
"tsx"
27+
],
28+
"testMatch": [
29+
"**/*.test.(ts|tsx)"
30+
],
31+
"transform": {
32+
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
33+
}
1634
}
1735
}

test/interface_constructor.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) 2017 The Bacardi Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as bindings from 'bindings';
18+
19+
const bacardi = bindings('bacardi.node');
20+
21+
test('Default constructor', async () => {
22+
let test_interface: bacardi.TestInterface = new bacardi.TestInterface();
23+
expect(test_interface instanceof bacardi.TestInterface).toBe(true);
24+
});

tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compileOnSave": true,
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"experimentalDecorators": true,
6+
"noImplicitAny": true,
7+
"noImplicitReturns": true,
8+
"preserveConstEnums": true,
9+
"sourceMap": true,
10+
"target": "es5"
11+
}
12+
}

0 commit comments

Comments
 (0)