Browse Source

Added coverage support to jest preset (#76)

* Added coverage support to jest preset

* Documented jest coverage option

* Added missing documentation
v5.0.0-beta
Łukasz Golder 8 years ago
committed by Eli Perelman
parent
commit
24d7faa8e0
  1. 9
      docs/cli/README.md
  2. 24
      docs/presets/neutrino-preset-jest/README.md
  3. 2
      packages/neutrino-preset-jest/src/index.js
  4. 5
      packages/neutrino/bin/neutrino

9
docs/cli/README.md

@ -69,6 +69,7 @@ Options:
--presets A list of Neutrino presets used to configure the build [array] [default: []]
--version Show version number [boolean]
--help Show help [boolean]
--coverage Collect test coverage information and generate report [boolean] [default: false]
--watch Watch source files for changes and re-run tests [boolean] [default: false]
```
@ -91,6 +92,14 @@ You can also pass a flag `--watch` to watch source files for changes and re-run
❯ neutrino test --watch
```
As well you can pass a flag `--coverage` to collect test coverage information and generate a report, if your preset
supports it.
```bash
❯ neutrino test --coverage
```
## Exit codes
When the CLI creates an instance of Neutrino, it waits for all commands to either resolve or reject their Promise.

24
docs/presets/neutrino-preset-jest/README.md

@ -8,6 +8,7 @@
- Zero upfront configuration necessary to start testing
- Babel compilation that compiles your tests using the same Babel options used by your source code
- Source watching for re-running of tests on change
- Collecting test coverage information and generating report
- Easily extensible to customize your testing as needed
## Requirements
@ -144,6 +145,29 @@ Use the command line [`files` parameters](/cli/README.md#neutrino-test) to execu
`neutrino-preset-jest` can watch for changes on your source directory and subsequently re-run tests. Simply use the
`--watch` flag with your `neutrino test` command.
## Coverage reporting
Jest has an integrated coverage reporter, which requires no configuration. To collect test coverage information and
generate report run:
```bash
❯ neutrino test --coverage
```
You can also edit your package.json file and create a separate command for generating coverage report, which can be
very helpful during continues integration of your project:
```json
{
"scripts": {
"coverage": "neutrino test --coverage"
}
}
```
See the [Jest's documentation](https://facebook.github.io/jest/docs/configuration.html#collectcoveragefrom-array) for
more configuration options for generating coverage reports.
## Customizing
To override the test configuration, start with the documentation on [customization](/customization/README.md).

2
packages/neutrino-preset-jest/src/index.js

@ -79,7 +79,7 @@ module.exports = neutrino => {
const configFile = path.join(os.tmpdir(), 'config.json');
return new Promise((resolve, reject) => {
const jestCliOptions = { config: configFile, watch: args.watch };
const jestCliOptions = { config: configFile, coverage: args.coverage, watch: args.watch };
fs.writeFileSync(configFile, `${JSON.stringify(jest, null, 2)}\n`);
runCLI(jestCliOptions, jest.rootDir || process.cwd(), result => {

5
packages/neutrino/bin/neutrino

@ -17,6 +17,11 @@ const args = yargs
.command('start', 'Build a project in development mode')
.command('build', 'Compile the source directory to a bundled build')
.command('test [files..]', 'Run all suites from the test directory or provided files', {
coverage: {
description: 'Collect test coverage information and generate report',
boolean: true,
default: false
},
watch: {
description: 'Watch source files for changes and re-run tests',
boolean: true,

Loading…
Cancel
Save