Debian Codegraph @

nyc/test/process-args.js

raw
1 'use strict'
2
3 const { test } = require('tap')
4 const yargs = require('yargs/yargs')
5
6 const processArgs = require('../self-coverage/lib/process-args')
7
8 const nycBin = require.resolve('../self-coverage/bin/nyc.js')
9
10 test('hideInstrumenterArgs removes dashed options that proceed bin', async t => {
11 process.argv = [
12 process.execPath,
13 nycBin,
14 '--reporter',
15 'lcov',
16 'node',
17 'test/nyc-tap.js'
18 ]
19
20 const { argv } = yargs(process.argv.slice(2))
21 const munged = processArgs.hideInstrumenterArgs(argv)
22
23 t.strictSame(munged, ['node', 'test/nyc-tap.js'])
24 })
25
26 test('hideInstrumenterArgs parses extra args directly after -- as Node execArgv', async t => {
27 process.argv = [
28 process.execPath,
29 nycBin,
30 '--',
31 '--expose-gc',
32 'index.js'
33 ]
34
35 const { argv } = yargs(process.argv.slice(2))
36 const munged = processArgs.hideInstrumenterArgs(argv)
37
38 t.strictSame(munged, [process.execPath, '--expose-gc', 'index.js'])
39 })
40
41 test('hideInstrumenteeArgs ignores arguments after the instrumented bin', async t => {
42 process.argv = [
43 process.execPath,
44 nycBin,
45 '--reporter',
46 'lcov',
47 'node',
48 'test/nyc-tap.js',
49 '--arg',
50 '--'
51 ]
52
53 const munged = processArgs.hideInstrumenteeArgs()
54 t.strictSame(munged, ['--reporter', 'lcov', 'node'])
55 })
56
57 test('hideInstrumenteeArgs does not ignore arguments if command is recognized', async t => {
58 process.argv = [
59 process.execPath,
60 nycBin,
61 'report',
62 '--reporter',
63 'lcov'
64 ]
65
66 const munged = processArgs.hideInstrumenteeArgs()
67 t.strictSame(munged, ['report', '--reporter', 'lcov'])
68 })
69
70 test('hideInstrumenteeArgs does not ignore arguments if no command is provided', async t => {
71 process.argv = [
72 process.execPath,
73 nycBin,
74 '--version'
75 ]
76
77 const munged = processArgs.hideInstrumenteeArgs()
78 t.strictSame(munged, ['--version'])
79 })