Skip to content

Commit

Permalink
feat: add unit testing and coverage support via jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Mar 15, 2017
1 parent 404283d commit 0551a52
Show file tree
Hide file tree
Showing 6 changed files with 1,104 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -3,7 +3,12 @@
.DS_Store
node_modules

coverage
lib
lib-esm
umd
typings

## this is generated by `npm pack`
*.tgz
package
6 changes: 6 additions & 0 deletions .npmignore
Expand Up @@ -4,5 +4,11 @@ tsconfig.*.json
tslint.json
**/webpack.config.js

__tests__
coverage
node_modules
src

## this is generated by `npm pack`
*.tgz
package
44 changes: 42 additions & 2 deletions package.json
Expand Up @@ -14,10 +14,12 @@
"node": ">=6.9"
},
"scripts": {
"cleanup": "shx rm -rf umd lib lib-esm typings",
"cleanup": "shx rm -rf umd lib lib-esm typings coverage",
"prebuild": "npm run cleanup && npm run verify",
"build": " tsc && tsc -p tsconfig.es6.json && webpack",
"test": "echo \"Error: no test specified\" && exit 0",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"ts:lint": "tslint --project tsconfig.json --type-check \"src/**/*.tsx\" \"src/**/*.ts\"",
"ts:lint:fix": "npm run ts:lint -- --fix",
"ts:format": "tsfmt --verify",
Expand Down Expand Up @@ -47,18 +49,56 @@
"maxSubjectLength": 120
}
},
"jest": {
"globals": {
"__TS_CONFIG__": {
"module": "commonjs"
}
},
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "<rootDir>/src/.*(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"modulePathIgnorePatterns": [
"/^((?!src).)/"
],
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
"coveragePathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/lib/",
"<rootDir>/lib-esm/",
"<rootDir>/umd/",
"<rootDir>/src/.*(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$"
],
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": 85
}
}
},
"dependencies": {},
"devDependencies": {
"@types/jest": "19.2.2",
"awesome-typescript-loader": "3.0.8",
"commitizen": "2.9.6",
"cross-var": "1.0.2",
"cz-conventional-changelog": "2.0.0",
"gzip-size-cli": "2.0.0",
"husky": "0.13.1",
"irish-pub": "0.2.0",
"jest": "19.0.2",
"shx": "0.2.2",
"standard-version": "4.0.0",
"strip-json-comments-cli": "1.0.1",
"ts-jest": "19.0.1",
"tslint": "4.5.1",
"tslint-react": "2.4.0",
"typescript": "2.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Greeter.ts
@@ -1,5 +1,5 @@
export class Greeter {
constructor(public greeting: string) { }
constructor(private greeting: string) { }
greet() {
return `Hello, ${this.greeting}!`;
}
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/Greeter.spec.ts
@@ -0,0 +1,20 @@
import { Greeter } from '../Greeter';

describe(`Greeter`, () => {

let greeter: Greeter;

beforeEach(() => {
greeter = new Greeter('World');
});

it(`should greet`, () => {

const actual = greeter.greet();
const expected = 'Hello, World!';

expect(actual).toBe(expected);

});

});

0 comments on commit 0551a52

Please sign in to comment.