Skip to content

Commit 8ccaff5

Browse files
committed
Swaps jest for karma (Fix #2)
It's still jasmine, but the react test-runner wars are over and jest won. In it goes!
1 parent 268ffc4 commit 8ccaff5

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ typings
44
*.swp
55
npm-debug.log
66
src/**/*.js
7+
coverage

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"watch": "webpack --watch",
1111
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
1212
"pretest": "npm run lint",
13-
"test": "karma start karma.conf --single-run=true"
13+
"test": "jest --coverage"
1414
},
1515
"typings": "typings/index.d.ts",
1616
"author": "RJ Zaworski <rj@rjzaworski.com> (http://rjzaworski.com)",
@@ -27,13 +27,8 @@
2727
"babel-loader": "^6.2.5",
2828
"babel-preset-es2015": "^6.14.0",
2929
"jasmine-core": "2.4.1",
30-
"karma": "^1.1.2",
31-
"karma-jasmine": "1.0.2",
32-
"karma-phantomjs-launcher": "^1.0.1",
33-
"karma-sinon": "1.0.5",
34-
"karma-spec-reporter": "0.0.26",
35-
"karma-webpack": "^1.7.0",
36-
"phantomjs-prebuilt": "^2.1.10",
30+
"jest": "^17.0.3",
31+
"jest-cli": "^17.0.3",
3732
"react-addons-test-utils": "^15.3.0",
3833
"sinon": "1.17.4",
3934
"source-map-loader": "0.1.5",
@@ -44,5 +39,16 @@
4439
"webpack": "^1.13.1",
4540
"webpack-fail-plugin": "^1.0.5",
4641
"zakalwe": "https://github.com/rjz/zakalwe.git"
42+
},
43+
"jest": {
44+
"moduleFileExtensions": [
45+
"ts",
46+
"tsx",
47+
"js"
48+
],
49+
"transform": {
50+
"^.+\\.(ts|tsx)$": "<rootDir>/preprocessor.js"
51+
},
52+
"testRegex": "/__tests__/.*\\.(ts|tsx|js)$"
4753
}
4854
}

preprocessor.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var tsc = require('typescript');
2+
var tsConfig = require('./tsconfig.json');
3+
4+
module.exports = {
5+
process: function (src, path) {
6+
if (path.match(/\.tsx?$/)) {
7+
return tsc.transpile(src, tsConfig.compilerOptions, path, []);
8+
}
9+
return src;
10+
}
11+
};

src/components/__tests__/counter_spec.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ describe('components/Counter', () => {
2222
const wrapper = renderElement(
2323
<Provider store={store}>
2424
<Counter label='a counter!' />
25-
</Provider>)
25+
</Provider>
26+
)
2627
const counter = findComponentByType(wrapper, Counter)
2728
return counter
2829
}
@@ -39,19 +40,14 @@ describe('components/Counter', () => {
3940
expect(label.textContent).toEqual('a counter!')
4041
})
4142

42-
4343
describe('clicking "increment"', () => {
44-
let counter: React.Component<{}, {}>
45-
46-
beforeEach(() => {
47-
counter = setup()
44+
it('increments counter', () => {
45+
const counter = setup()
4846
const [ increment ] = TestUtils.scryRenderedDOMComponentsWithTag(counter, 'button')
4947
TestUtils.Simulate.click(increment)
5048
TestUtils.Simulate.click(increment)
5149
TestUtils.Simulate.click(increment)
52-
})
5350

54-
it('increments counter', () => {
5551
const pre = TestUtils.findRenderedDOMComponentWithTag(counter, 'pre')
5652
expect(JSON.parse(pre.textContent).counter.value).toEqual(3)
5753
})

src/middleware/__tests__/index_spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { apiMiddleware } from '../'
44

55
import { api } from '../../api'
66

7+
import * as sinon from 'sinon'
8+
79
import {
810
Action,
911
loadCount,

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
},
1010
"files": [
1111
"typings/index.d.ts"
12-
],
13-
"exclude": []
12+
]
1413
}

0 commit comments

Comments
 (0)