You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-5
Original file line number
Diff line number
Diff line change
@@ -195,12 +195,31 @@ Install custom reporters as a development dependency and you can use the `--repo
195
195
nyc report --reporter=<custom-reporter-name>
196
196
```
197
197
198
+
## Producing instrumented source
199
+
200
+
The `nyc instrument` command can produce a set of instrumented source files.
201
+
These files are suitable for client side deployment in end to end testing.
202
+
You can create an instrumented version of your source code by running:
203
+
204
+
```bash
205
+
nyc instrument <input> [output]
206
+
```
207
+
208
+
`<input>` can be any file or directory within the project root directory.
209
+
The `[output]` directory is optional and can be located anywhere, if it is not set the instrumented code will be sent to `stdout`.
210
+
For example, `nyc instrument . ./output` will produce instrumented versions of any source files it finds in `.` and store them in `./output`.
211
+
212
+
Any existing output can be removed by specifying the `--delete` option.
213
+
Run `nyc instrument --help` to display a full list of available command options.
214
+
215
+
**Note:**`nyc instrument` will not copy the contents of a `.git` folder to the output directory.
216
+
198
217
## Setting the project root directory
199
218
200
219
nyc runs a lot of file system operations relative to the project root directory.
201
220
During startup nyc will look for the *default* project root directory.
202
221
The *default* project root directory is the first directory found that contains a `package.json` file when searching from the current working directory up.
203
-
If nyc fails to find a directory containing a `package.json` file, it will use current working directory as the *default* project root directory.
222
+
If nyc fails to find a directory containing a `package.json` file, it will use the current working directory as the *default* project root directory.
204
223
You can change the project root directory with the `--cwd` option.
205
224
206
225
nyc uses the project root directory when:
@@ -220,7 +239,7 @@ It does this by watching for files that are `require()`'d during the test.
220
239
When a file is `require()`'d, nyc creates and returns an instrumented version of the source, rather than the original.
221
240
Only source files that are visited during a test will appear in the coverage report and contribute to coverage statistics.
222
241
223
-
nyc will instrument all files if the `--all` flag is set.
242
+
nyc will instrument all files if the `--all` flag is set or if running `nyc instrument`.
224
243
In this case all files will appear in the coverage report and contribute to coverage statistics.
225
244
226
245
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.
@@ -263,9 +282,6 @@ The `exclude` option has the following defaults settings:
263
282
These settings exclude `test` and `__tests__` directories as well as `test.js`, `*.test.js`, and `test-*.js` files.
264
283
Specifying your own exclude property completely replaces these defaults.
265
284
266
-
**Note:** The exclude list always implicitly contains `**/node_modules/**`, even if not explicitly specified in an overriding `exclude` array.
267
-
To reverse this you must add the negated exclude rule `!**/node_modules/`.
268
-
269
285
For example, the following config will collect coverage for every file in the `src` directory regardless of whether it is `require()`'d in a test.
270
286
It will also exclude any files with the extension `.spec.js`.
271
287
@@ -286,6 +302,32 @@ It will also exclude any files with the extension `.spec.js`.
286
302
**Note:** Be wary of automatic OS glob expansion when specifying include/exclude globs with the CLI.
287
303
To prevent this, wrap each glob in single quotes.
288
304
305
+
### Including files within `node_modules`
306
+
307
+
We always add `**/node_modules/**` to the exclude list, even if not specified in the config.
308
+
You can override this by setting `--exclude-node-modules=false`.
309
+
310
+
For example, in the following config, `"excludeNodeModules: false"` will prevent `node_modules` from being added to the exclude rules.
311
+
The set of include rules then restrict nyc to only consider instrumenting files found under the `lib/` and `node_modules/@my-org/` directories.
312
+
The exclude rules then prevent nyc instrumenting anything in a `test` folder and the file `node_modules/@my-org/something/unwanted.js`.
313
+
314
+
```json
315
+
{
316
+
"nyc": {
317
+
"all": true,
318
+
"include": [
319
+
"lib/**",
320
+
"node_modules/@my-org/**"
321
+
],
322
+
"exclude": [
323
+
"node_modules/@my-org/something/unwanted.js",
324
+
"**/test/**"
325
+
],
326
+
"excludeNodeModules": false
327
+
}
328
+
}
329
+
```
330
+
289
331
## Require additional modules
290
332
291
333
The `--require` flag can be provided to `nyc` to indicate that additional
0 commit comments