Debian Codegraph @

nyc/docs/instrument.md

raw
1 # Producing instrumented source
2
3 The `nyc instrument` command can produce instrumented source files.
4 These files are suitable for client side deployment during end to end testing.
5 You can either pre-instrument your source, or write instrumented source to a stream.
6
7 Run `nyc instrument --help` to display a full list of available command options.
8
9 ## Pre-instrumented source
10
11 You can create pre-instrumented source code by running:
12
13 ```bash
14 nyc instrument <input> [output]
15 ```
16
17 `<input>` can be any file or directory within the project root directory.
18 The `[output]` directory is optional and can be located anywhere, if not set the instrumented code will be sent to `stdout`.
19 For example, `nyc instrument . ./output` will produce instrumented versions of any source files it finds in `.` and store them in `./output`.
20
21 The `--delete` option will remove the existing output directory before instrumenting.
22
23 The `--in-place` option will allow you to run the instrument command.
24
25 The `--complete-copy` option will copy all remaining files from the `input` directory to the `output` directory.
26 When using `--complete-copy` nyc will not copy the contents of a `.git` folder to the output directory.
27
28 **Note:** `--complete-copy` will dereference any symlinks during the copy process, this may stop scripts running properly from the output directory.
29
30 ## Streaming instrumentation
31
32 `nyc instrument <input>` will stream instrumented source directly to `stdout` and that output can then be piped to another process.
33 You can use this behaviour to create a server that dynamically instruments files on request.
34 The following example shows streaming instrumentation middleware capable of instrumenting files on request.
35
36 ```javascript
37 app.use((req, res, next) => {
38 const myOptions = ""
39 const filename = myHelper.getFilename(req)
40 const nyc = cp.spawn(`nyc instrument ${myOptions} ${filename}`)
41 nyc.stdout.pipe(res)
42 })
43 ```