Skip to content

Commit

Permalink
Introduce jest for testing.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
romandev committed Oct 7, 2017
1 parent 347cec5 commit a981c58
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions bootstrap/command/test
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function is_already_formatted() {

if is_already_formatted; then
mocha --napi-modules examples/calculator.js
node --napi-modules $(bacardi_path)/node_modules/.bin/jest
else
echo "You should run |bacardi format| command first."
fi
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
{
"devDependencies": {
"@types/jest": "^21.1.2",
"@types/node": "^8.0.24",
"bindings": "^1.3.0",
"jest": "^21.2.1",
"mkdirp": "^0.5.1",
"mocha": "^3.5.0",
"node-addon-api": "^0.6.3",
"node-gyp": "^3.6.2",
"nunjucks": "^3.0.1",
"mkdirp": "^0.5.1",
"snake-case": "^2.1.0",
"ts-jest": "^21.1.0",
"typescript": "^2.4.2",
"webidl2": "^4.1.0"
},
"optionalDependencies": {
"windows-build-tools": "^1.3.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"jsx",
"ts",
"tsx"
],
"testMatch": [
"**/*.test.(ts|tsx)"
],
"transform": {
"^.+\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
}
}
}
24 changes: 24 additions & 0 deletions test/interface_constructor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) 2017 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as bindings from 'bindings';

const bacardi = bindings('bacardi.node');

test('Default constructor', async () => {
let test_interface: bacardi.TestInterface = new bacardi.TestInterface();
expect(true).toBe(test_interface instanceof bacardi.TestInterface);
});
12 changes: 12 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": ".",
"experimentalDecorators": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"preserveConstEnums": true,
"sourceMap": true,
"target": "es5"
}
}

0 comments on commit a981c58

Please sign in to comment.