From 914b776215ad3ea54f0e46b4ba2904a8a9d4dfdd Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Sat, 18 May 2019 10:00:22 -0400 Subject: [PATCH] feat: Add `.cjs`, `.mjs`, `.ts`, `.tsx`, `.jsx` to default extensions (#1110) Fixes #1103 --- README.md | 4 ++-- lib/commands/instrument.js | 2 +- lib/commands/report.js | 6 ++++++ lib/config-util.js | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4c7ee6ddb..889c1e68d 100644 --- a/README.md +++ b/README.md @@ -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` | `['.js']` | +| `extension` | List of extensions that nyc should attempt to handle in addition to `.js` | `Array` | `['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx']` | | `include` | See [selecting files for coverage] for more info | `Array` | `['**']`| | `exclude` | See [selecting files for coverage] for more info | `Array` | [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` | `['text']` | @@ -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. diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js index 701dcb6f7..553a1af7b 100644 --- a/lib/commands/instrument.js +++ b/lib/commands/instrument.js @@ -25,7 +25,7 @@ exports.builder = function (yargs) { }) .option('extension', { alias: 'e', - default: [], + default: ['.cjs', '.mjs', '.ts', '.tsx', '.jsx'], describe: 'a list of extensions that nyc should handle in addition to .js' }) .option('source-map', { diff --git a/lib/commands/report.js b/lib/commands/report.js index 345983d23..2af7831bc 100644 --- a/lib/commands/report.js +++ b/lib/commands/report.js @@ -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, diff --git a/lib/config-util.js b/lib/config-util.js index 55c47aa77..177469b60 100644 --- a/lib/config-util.js +++ b/lib/config-util.js @@ -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 })