Skip to content

Commit d0ce9b5

Browse files
authored
Merge pull request #36 from conveyal/test-improvements
More testing features
2 parents b47a0a9 + 4751cd5 commit d0ce9b5

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ Run the [Jest](http://facebook.github.io/jest/) test runner on your project. It
112112

113113
```shell
114114
$ mastarm test
115+
116+
Usage: test [options]
117+
118+
Run tests using Jest
119+
120+
Options:
121+
122+
-h, --help output usage information
123+
-u, --update-snapshots Force update of snapshots. USE WITH CAUTION.
124+
--coverage Run Jest with coverage reporting
125+
--no-cache Run Jest without cache
126+
115127
```
116128

117129
[npm-image]: https://img.shields.io/npm/v/mastarm.svg?maxAge=2592000&style=flat-square

bin/mastarm

+5-2
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,14 @@ commander
148148
.command('test')
149149
.description('Run tests using Jest')
150150
.option('-u, --update-snapshots', 'Force update of snapshots. USE WITH CAUTION.')
151+
.option('--coverage', 'Run Jest with coverage reporting')
152+
.option('--no-cache', 'Run Jest with cache')
151153
.action(function (options) {
152154
const jest = require('jest')
153155
const config = loadConfig(process.cwd(), commander.config, commander.env)
154-
const generateTestConfig = require('../lib/test.js')
155-
jest.run(generateTestConfig(config, options))
156+
const testUtils = require('../lib/test')
157+
testUtils.setupTestEnvironment(config)
158+
jest.run(testUtils.generateTestConfig(options))
156159
})
157160

158161
commander.parse(process.argv)

lib/jestPreprocessor.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const babel = require('babel-core')
2+
const babel2015 = require('babel-preset-es2015')
3+
const jestPreset = require('babel-preset-jest')
4+
const reactPreset = require('babel-preset-react')
5+
const stage0Preset = require('babel-preset-stage-0')
6+
7+
module.exports = {
8+
process: function (src) {
9+
const transformCfg = {
10+
presets: [babel2015, reactPreset, stage0Preset, jestPreset],
11+
retainLines: true
12+
}
13+
return babel.transform(src, transformCfg).code
14+
}
15+
}

lib/test.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
const path = require('path')
12

2-
module.exports = function generateTestConfig (config, options) {
3-
if (config.messages) {
4-
process.env.MESSAGES = JSON.stringify(config.messages)
5-
}
3+
module.exports.generateTestConfig = (options) => {
64
const jestConfig = {
7-
collectCoverage: true,
5+
cacheDirectory: 'tmp',
6+
collectCoverage: options.coverage,
87
collectCoverageFrom: ['lib/**/*.js'],
9-
coverageDirectory: 'coverage'
8+
coverageDirectory: 'coverage',
9+
scriptPreprocessor: path.resolve(__dirname, 'jestPreprocessor.js')
1010
}
1111
const jestArguments = []
1212
if (options.updateSnapshots) {
1313
jestArguments.push('-u')
1414
}
15+
if (options.cache === false) {
16+
jestArguments.push('--no-cache')
17+
}
1518
jestArguments.push('--config', JSON.stringify(jestConfig))
1619
return jestArguments
1720
}
21+
22+
module.exports.setupTestEnvironment = (config) => {
23+
if (config.messages) {
24+
process.env.MESSAGES = JSON.stringify(config.messages)
25+
}
26+
}

0 commit comments

Comments
 (0)