Skip to content

Commit b47a0a9

Browse files
authored
Merge pull request #33 from conveyal/test-with-jest
feat(tests): Add ability to run Jest test runner on project code usin…
2 parents 775062d + 454ed2c commit b47a0a9

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ $ mastarm --help
4747
commit Force intelligent commit messages.
4848
deploy [options] [entries...] Bundle & Deploy JavaScript & CSS
4949
lint [paths...] Lint JavaScript [& CSS coming soon!]
50+
test [options] Run tests using Jest test runner
5051

5152
Options:
5253

@@ -58,6 +59,7 @@ $ mastarm --help
5859
-p, --proxy <address> Proxy calls through to target address.
5960
-s, --serve Serve with budo. Auto-matically rebuilds on changes.
6061
-S, --skip-check-dependencies Skip checking and installing out of date package.json dependencies.
62+
-u, --update-snapshots Force update of jest snapshots. USE WITH CAUTION.
6163
-w, --watch Rebuild on changes with watchify.
6264
```
6365

@@ -104,6 +106,14 @@ $ mastarm lint "src/util/**/*.js" "test/**/*.js"
104106

105107
Note: by default standard will look for all files matching the patterns: `"**/*.js"`, `"**/*.jsx"`. Always quote the globs. Needed when used as an `npm` command.
106108

109+
### `test`
110+
111+
Run the [Jest](http://facebook.github.io/jest/) test runner on your project. It is expected that you create tests within your project. By default, mastarm will run Jest and generate coverage reports on all .js files in the `lib` folder of your project.
112+
113+
```shell
114+
$ mastarm test
115+
```
116+
107117
[npm-image]: https://img.shields.io/npm/v/mastarm.svg?maxAge=2592000&style=flat-square
108118
[npm-url]: https://www.npmjs.com/package/mastarm
109119
[travis-image]: https://img.shields.io/travis/conveyal/mastarm.svg?style=flat-square

bin/mastarm

+11
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ commander
144144
}
145145
})
146146

147+
commander
148+
.command('test')
149+
.description('Run tests using Jest')
150+
.option('-u, --update-snapshots', 'Force update of snapshots. USE WITH CAUTION.')
151+
.action(function (options) {
152+
const jest = require('jest')
153+
const config = loadConfig(process.cwd(), commander.config, commander.env)
154+
const generateTestConfig = require('../lib/test.js')
155+
jest.run(generateTestConfig(config, options))
156+
})
157+
147158
commander.parse(process.argv)
148159

149160
function checkDependencies () {

lib/test.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
module.exports = function generateTestConfig (config, options) {
3+
if (config.messages) {
4+
process.env.MESSAGES = JSON.stringify(config.messages)
5+
}
6+
const jestConfig = {
7+
collectCoverage: true,
8+
collectCoverageFrom: ['lib/**/*.js'],
9+
coverageDirectory: 'coverage'
10+
}
11+
const jestArguments = []
12+
if (options.updateSnapshots) {
13+
jestArguments.push('-u')
14+
}
15+
jestArguments.push('--config', JSON.stringify(jestConfig))
16+
return jestArguments
17+
}

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"babel-cli": "^6.10.1",
3535
"babel-core": "^6.10.4",
3636
"babel-eslint": "^6.1.2",
37+
"babel-jest": "^15.0.0",
38+
"babel-polyfill": "^6.13.0",
3739
"babel-plugin-add-module-exports": "^0.2.1",
3840
"babel-plugin-transform-runtime": "^6.9.0",
3941
"babel-preset-es2015": "^6.9.0",
@@ -53,6 +55,7 @@
5355
"errorify": "^0.3.1",
5456
"exorcist": "^0.4.0",
5557
"http-proxy": "^1.14.0",
58+
"jest": "^15.1.1",
5659
"mime": "^1.3.4",
5760
"mkdirp": "^0.5.1",
5861
"postcss": "^5.0.21",

0 commit comments

Comments
 (0)