Skip to content

Commit a8a38dc

Browse files
authored
Merge pull request #51 from conveyal/dev
Merge latest Jest changes into master to create a new version
2 parents aa7b1fa + 00b8686 commit a8a38dc

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

README.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ $ mastarm --help
6868
Compile JS, HTML, CSS, YAML, Markdown into a single `.js`. Utilizes [babel](https://babeljs.io/), [browserify](https://github.com/substack/node-browserify), [budo](https://github.com/mattdesl/budo), and [postcss](http://postcss.org/).
6969

7070
```shell
71-
$ mastarm build [entries...] [options]
71+
$ mastarm build [options] [entries...]
7272

7373
Options:
7474

@@ -98,7 +98,7 @@ Build, push to S3, and invalidate CloudFront in one command.
9898
```shell
9999
$ mastarm deploy --help
100100

101-
Usage: deploy [entries...] [options]
101+
Usage: deploy [options] [entries...]
102102

103103
Bundle & Deploy JavaScript & CSS
104104

@@ -115,7 +115,7 @@ Options:
115115
Lint using [Standard](http://standardjs.com/). Everything is passed directly to [`standard-engine`](https://github.com/Flet/standard-engine).
116116

117117
```shell
118-
$ mastarm lint
118+
$ mastarm lint [paths...]
119119
```
120120

121121
You can optionally pass in a directory (or directories) using the glob pattern. Be sure to quote paths containing glob patterns so that they are expanded by standard instead of your shell:
@@ -128,21 +128,23 @@ Note: by default standard will look for all files matching the patterns: `"**/*.
128128

129129
### `test`
130130

131-
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.
131+
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. The `patterns` argument will make Jest run only tests whose filename match the provided pattern.
132132

133133
```shell
134134
$ mastarm test
135135

136-
Usage: test [options]
136+
Usage: test [options] [patterns...]
137137

138138
Run tests using Jest
139139

140140
Options:
141141

142-
-h, --help output usage information
143-
-u, --update-snapshots Force update of snapshots. USE WITH CAUTION.
144-
--coverage Run Jest with coverage reporting
145-
--no-cache Run Jest without cache
142+
-h, --help output usage information
143+
-u, --update-snapshots Force update of snapshots. USE WITH CAUTION.
144+
--coverage Run Jest with coverage reporting
145+
--no-cache Run Jest with cache
146+
--coverage-paths <paths> Extra paths to collect code coverage from
147+
--setup-files <paths> Setup files to run before each test
146148

147149
```
148150

bin/mastarm

+5-4
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,20 @@ commander
155155
})
156156

157157
commander
158-
.command('test')
158+
.command('test [patterns...]')
159159
.description('Run tests using Jest')
160160
.option('-u, --update-snapshots', 'Force update of snapshots. USE WITH CAUTION.')
161161
.option('--coverage', 'Run Jest with coverage reporting')
162162
.option('--no-cache', 'Run Jest with cache')
163-
.option('--coverage-paths <paths>')
164-
.action(function (options) {
163+
.option('--coverage-paths <paths>', 'Extra paths to collect code coverage from')
164+
.option('--setup-files <paths>', 'Setup files to run before each test')
165+
.action(function (patterns, options) {
165166
checkDependencies()
166167
const jest = require('jest')
167168
const config = loadConfig(process.cwd(), commander.config, commander.env)
168169
const testUtils = require('../lib/test')
169170
testUtils.setupTestEnvironment(config)
170-
jest.run(testUtils.generateTestConfig(options))
171+
jest.run(testUtils.generateTestConfig(patterns, options))
171172
})
172173

173174
commander.parse(process.argv)

lib/test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path')
22

3-
module.exports.generateTestConfig = (options) => {
3+
module.exports.generateTestConfig = (patterns, options) => {
44
// jest config params
55
const jestConfig = {
66
cacheDirectory: 'tmp',
@@ -14,8 +14,12 @@ module.exports.generateTestConfig = (options) => {
1414
jestConfig.collectCoverageFrom = jestConfig.collectCoverageFrom.concat(options.coveragePaths.split(' '))
1515
}
1616

17+
if (options.setupFiles) {
18+
jestConfig.setupFiles = options.setupFiles
19+
}
20+
1721
// jest cli params
18-
const jestArguments = []
22+
let jestArguments = []
1923
if (options.updateSnapshots) {
2024
jestArguments.push('-u')
2125
}
@@ -25,6 +29,10 @@ module.exports.generateTestConfig = (options) => {
2529
}
2630

2731
jestArguments.push('--config', JSON.stringify(jestConfig))
32+
33+
if (patterns) {
34+
jestArguments = jestArguments.concat(patterns)
35+
}
2836
return jestArguments
2937
}
3038

tests/lib/__snapshots__/test.test.js.snap

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Array [
33
"-u",
44
"--no-cache",
55
"--config",
6+
"these",
7+
"files",
8+
"only",
69
]
710
`;
811

@@ -16,6 +19,9 @@ Object {
1619
"another-folder",
1720
],
1821
"coverageDirectory": "coverage",
22+
"setupFiles": Array [
23+
"beforeTestsSetup.js",
24+
],
1925
}
2026
`;
2127

tests/lib/test.test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ const testUtils = require('../../lib/test')
44

55
describe('test.js', () => {
66
it('generateTestConfig should generate proper config', () => {
7-
const cfg = testUtils.generateTestConfig({
7+
const cfg = testUtils.generateTestConfig(['these', 'files', 'only'], {
88
coveragePaths: 'bin src another-folder',
99
updateSnapshots: true,
10-
cache: false
10+
cache: false,
11+
setupFiles: ['beforeTestsSetup.js']
1112
})
1213
expect(cfg).toBeTruthy()
13-
expect(cfg.length).toEqual(4)
14-
expect(cfg.slice(0, 3)).toMatchSnapshot()
15-
const jestCfg = JSON.parse(cfg[3])
14+
expect(cfg.length).toEqual(7)
15+
const jestCfg = JSON.parse(cfg.splice(3, 1))
16+
expect(cfg).toMatchSnapshot()
1617
expect(jestCfg.scriptPreprocessor).toContain('lib/jest-preprocessor.js')
1718
delete jestCfg.scriptPreprocessor
1819
expect(jestCfg).toMatchSnapshot()

0 commit comments

Comments
 (0)