Skip to content

Commit

Permalink
Add some unit tests via jest for the start
Browse files Browse the repository at this point in the history
Fixes: #14
  • Loading branch information
larixer committed Oct 9, 2018
1 parent 671e10e commit ba8a348
Show file tree
Hide file tree
Showing 3 changed files with 3,279 additions and 27 deletions.
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
"build": "tsc",
"watch": "tsc -w",
"lint": "tslint --fix -p tsconfig.json -c tslint.json",
"tests": " ",
"tests": "jest",
"tests:watch": "jest --watch",
"test": "yarn tests && yarn lint",
"precommit": "lint-staged",
"prepare": "yarn clean && yarn build"
"prepublishOnly": "yarn clean && yarn build"
},
"repository": {
"type": "git",
Expand All @@ -35,16 +36,19 @@
"devDependencies": {
"@types/inquirer": "^0.0.35",
"@types/ip": "^0.0.30",
"@types/jest": "^23.3.4",
"@types/lodash": "^4.14.71",
"@types/mkdirp": "^0.5.0",
"@types/node": "^7.0.18",
"@types/webpack": "^3.0.10",
"@types/webpack-sources": "^0.1.2",
"@types/yargs": "^8.0.2",
"husky": "^0.14.3",
"jest": "^23.6.0",
"lint-staged": "^4.1.3",
"prettier": "^1.6.1",
"rimraf": "^2.6.2",
"ts-jest": "^23.10.4",
"tslint": "^5.2.0",
"tslint-config-prettier": "^1.5.0",
"tslint-plugin-prettier": "^1.3.0",
Expand Down Expand Up @@ -86,5 +90,16 @@
"printWidth": 120,
"singleQuote": true,
"parser": "babylon"
},
"jest": {
"transform": {
".ts": "ts-jest"
},
"testRegex": "(/__tests__/.*\\.(test|spec))\\.(ts|js)$",
"moduleFileExtensions": [
"ts",
"js",
"json"
]
}
}
26 changes: 26 additions & 0 deletions src/plugins/shared/__tests__/JSRuleFinder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Builder } from '../../../Builder';
import JSRuleFinder from '../JSRuleFinder';

describe('JSRuleFinder', () => {
it('should create js rule if it does not exist', () => {
// tslint:disable-next-line
const builder: Builder = {} as Builder;
builder.config = {
module: { rules: [] }
};
const rule = new JSRuleFinder(builder).findAndCreateJSRule();
expect(rule).toHaveProperty('test');
});

it('should find js rule if it exists', () => {
// tslint:disable-next-line
const builder: Builder = {} as Builder;
const regex = /\.js$/;
builder.config = {
module: { rules: [{ test: /abc/ }, { test: regex }, { test: /def/ }] }
};
const rule = new JSRuleFinder(builder).findAndCreateJSRule();
expect(rule).toHaveProperty('test');
expect(rule.test).toEqual(regex);
});
});
Loading

0 comments on commit ba8a348

Please sign in to comment.