Skip to content

Commit 914b776

Browse files
authored
feat: Add .cjs, .mjs, .ts, .tsx, .jsx to default extensions (#1110)
Fixes #1103
1 parent 5464064 commit 914b776

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ This table is a quick TLDR for the rest of this readme and there are more advanc
9898
| ----------- | ----------- | ---- | ------- |
9999
| `all` | Whether or not to instrument all files (not just the ones touched by your test suite) | `Boolean` | `false` |
100100
| `check-coverage` | Check whether coverage is within thresholds, fail if not | `Boolean` | `false` |
101-
| `extension` | List of extensions that nyc should attempt to handle in addition to `.js` | `Array<String>` | `['.js']` |
101+
| `extension` | List of extensions that nyc should attempt to handle in addition to `.js` | `Array<String>` | `['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx']` |
102102
| `include` | See [selecting files for coverage] for more info | `Array<String>` | `['**']`|
103103
| `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) |
104104
| `reporter` | [Coverage reporters to use](https://istanbul.js.org/docs/advanced/alternative-reporters/) | `Array<String>` | `['text']` |
@@ -148,7 +148,7 @@ Only source files that are visited during a test will appear in the coverage rep
148148
nyc will instrument all files if the `--all` flag is set or if running `nyc instrument`.
149149
In this case all files will appear in the coverage report and contribute to coverage statistics.
150150

151-
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.
151+
nyc will only collect coverage for files that are located under `cwd`, and then only files with extensions listed in the `extension` array.
152152

153153
You can reduce the set of instrumented files by adding `include` and `exclude` filter arrays to your config.
154154
These allow you to shape the set of instrumented files by specifying glob patterns that can filter files from the default instrumented set.

lib/commands/instrument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exports.builder = function (yargs) {
2525
})
2626
.option('extension', {
2727
alias: 'e',
28-
default: [],
28+
default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
2929
describe: 'a list of extensions that nyc should handle in addition to .js'
3030
})
3131
.option('source-map', {

lib/commands/report.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ exports.builder = function (yargs) {
4949
describe: 'a list of specific files that should be covered, glob patterns are supported',
5050
global: false
5151
})
52+
.option('extension', {
53+
alias: 'e',
54+
default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
55+
describe: 'a list of extensions that nyc should handle in addition to .js',
56+
global: false
57+
})
5258
.option('show-process-tree', {
5359
describe: 'display the tree of spawned processes',
5460
default: false,

lib/config-util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Config.buildYargs = function (cwd) {
148148
})
149149
.option('extension', {
150150
alias: 'e',
151-
default: [],
151+
default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'],
152152
describe: 'a list of extensions that nyc should handle in addition to .js',
153153
global: false
154154
})

0 commit comments

Comments
 (0)