Skip to content

Commit

Permalink
Merge pull request #33 from conveyal/test-with-jest
Browse files Browse the repository at this point in the history
feat(tests): Add ability to run Jest test runner on project code usin…
  • Loading branch information
evansiroky committed Sep 23, 2016
2 parents 775062d + 454ed2c commit b47a0a9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ $ mastarm --help
commit Force intelligent commit messages.
deploy [options] [entries...] Bundle & Deploy JavaScript & CSS
lint [paths...] Lint JavaScript [& CSS coming soon!]
test [options] Run tests using Jest test runner

Options:

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

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

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.

### `test`

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.

```shell
$ mastarm test
```

[npm-image]: https://img.shields.io/npm/v/mastarm.svg?maxAge=2592000&style=flat-square
[npm-url]: https://www.npmjs.com/package/mastarm
[travis-image]: https://img.shields.io/travis/conveyal/mastarm.svg?style=flat-square
Expand Down
11 changes: 11 additions & 0 deletions bin/mastarm
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ commander
}
})

commander
.command('test')
.description('Run tests using Jest')
.option('-u, --update-snapshots', 'Force update of snapshots. USE WITH CAUTION.')
.action(function (options) {
const jest = require('jest')
const config = loadConfig(process.cwd(), commander.config, commander.env)
const generateTestConfig = require('../lib/test.js')
jest.run(generateTestConfig(config, options))
})

commander.parse(process.argv)

function checkDependencies () {
Expand Down
17 changes: 17 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

module.exports = function generateTestConfig (config, options) {
if (config.messages) {
process.env.MESSAGES = JSON.stringify(config.messages)
}
const jestConfig = {
collectCoverage: true,
collectCoverageFrom: ['lib/**/*.js'],
coverageDirectory: 'coverage'
}
const jestArguments = []
if (options.updateSnapshots) {
jestArguments.push('-u')
}
jestArguments.push('--config', JSON.stringify(jestConfig))
return jestArguments
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"babel-cli": "^6.10.1",
"babel-core": "^6.10.4",
"babel-eslint": "^6.1.2",
"babel-jest": "^15.0.0",
"babel-polyfill": "^6.13.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
Expand All @@ -53,6 +55,7 @@
"errorify": "^0.3.1",
"exorcist": "^0.4.0",
"http-proxy": "^1.14.0",
"jest": "^15.1.1",
"mime": "^1.3.4",
"mkdirp": "^0.5.1",
"postcss": "^5.0.21",
Expand Down

0 comments on commit b47a0a9

Please sign in to comment.