Skip to content

Commit

Permalink
feat: Add .cjs, .mjs, .ts, .tsx, .jsx to default extensions (
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell authored May 18, 2019
1 parent 5464064 commit 914b776
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ This table is a quick TLDR for the rest of this readme and there are more advanc
| ----------- | ----------- | ---- | ------- |
| `all` | Whether or not to instrument all files (not just the ones touched by your test suite) | `Boolean` | `false` |
| `check-coverage` | Check whether coverage is within thresholds, fail if not | `Boolean` | `false` |
| `extension` | List of extensions that nyc should attempt to handle in addition to `.js` | `Array<String>` | `['.js']` |
| `extension` | List of extensions that nyc should attempt to handle in addition to `.js` | `Array<String>` | `['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx']` |
| `include` | See [selecting files for coverage] for more info | `Array<String>` | `['**']`|
| `exclude` | See [selecting files for coverage] for more info | `Array<String>` | [list](https://github.com/istanbuljs/istanbuljs/blob/master/packages/test-exclude/default-exclude.js) |
| `reporter` | [Coverage reporters to use](https://istanbul.js.org/docs/advanced/alternative-reporters/) | `Array<String>` | `['text']` |
Expand Down Expand Up @@ -148,7 +148,7 @@ Only source files that are visited during a test will appear in the coverage rep
nyc will instrument all files if the `--all` flag is set or if running `nyc instrument`.
In this case all files will appear in the coverage report and contribute to coverage statistics.

nyc will only collect coverage for files that are located under `cwd`, and then only `*.js` files or files with extensions listed in the `extension` array.
nyc will only collect coverage for files that are located under `cwd`, and then only files with extensions listed in the `extension` array.

You can reduce the set of instrumented files by adding `include` and `exclude` filter arrays to your config.
These allow you to shape the set of instrumented files by specifying glob patterns that can filter files from the default instrumented set.
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.builder = function (yargs) {
})
.option('extension', {
alias: 'e',
default: [],
default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'],

This comment has been minimized.

Copy link
@Kosta-Github

Kosta-Github Jun 18, 2019

isn't .js missing in this list?

describe: 'a list of extensions that nyc should handle in addition to .js'
})
.option('source-map', {
Expand Down
6 changes: 6 additions & 0 deletions lib/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ exports.builder = function (yargs) {
describe: 'a list of specific files that should be covered, glob patterns are supported',
global: false
})
.option('extension', {
alias: 'e',
default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
describe: 'a list of extensions that nyc should handle in addition to .js',
global: false
})
.option('show-process-tree', {
describe: 'display the tree of spawned processes',
default: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/config-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Config.buildYargs = function (cwd) {
})
.option('extension', {
alias: 'e',
default: [],
default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
describe: 'a list of extensions that nyc should handle in addition to .js',
global: false
})
Expand Down

2 comments on commit 914b776

@Kosta-Github
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not treating the .js extension the same way as the additional ones and including it into all the default lists?

@coreyfarrell
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this but I fear it would break too many compiled TS projects. Currently many projects include extension: ['.ts'] in their config and .js is automatically added.

Please sign in to comment.