1 | const Exclude = require('test-exclude')
|
2 | const findUp = require('find-up')
|
3 | const { readFileSync } = require('fs')
|
4 | const yargs = require('yargs')
|
5 | const parser = require('yargs-parser')
|
6 |
|
7 | const configPath = findUp.sync(['.c8rc', '.c8rc.json'])
|
8 | const config = configPath ? JSON.parse(readFileSync(configPath)) : {}
|
9 |
|
10 | yargs()
|
11 | .usage('$0 [opts] [script] [opts]')
|
12 | .option('reporter', {
|
13 | alias: 'r',
|
14 | describe: 'coverage reporter(s) to use',
|
15 | default: 'text'
|
16 | })
|
17 | .option('exclude', {
|
18 | alias: 'x',
|
19 | default: Exclude.defaultExclude,
|
20 | describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)'
|
21 | })
|
22 | .option('include', {
|
23 | alias: 'n',
|
24 | default: [],
|
25 | describe: 'a list of specific files that should be covered (glob patterns are supported)'
|
26 | })
|
27 | .option('temp-directory', {
|
28 | default: './coverage/tmp',
|
29 | describe: 'directory V8 coverage data is written to and read from'
|
30 | })
|
31 | .option('resolve', {
|
32 | default: '',
|
33 | describe: 'resolve paths to alternate base directory'
|
34 | })
|
35 | .option('omit-relative', {
|
36 | default: true,
|
37 | type: 'boolean',
|
38 | describe: 'omit any paths that are not absolute, e.g., internal/net.js'
|
39 | })
|
40 | .option('clean', {
|
41 | default: true,
|
42 | type: 'boolean',
|
43 | describe: 'should temp files be deleted before script execution'
|
44 | })
|
45 | .command('report', 'read V8 coverage data from temp and output report')
|
46 | .pkgConf('c8')
|
47 | .config(config)
|
48 | .demandCommand(1)
|
49 | .epilog('visit https://git.io/vHysA for list of available reporters')
|
50 |
|
51 | function hideInstrumenterArgs (yargv) {
|
52 | var argv = process.argv.slice(1)
|
53 | argv = argv.slice(argv.indexOf(yargv._[0]))
|
54 | if (argv[0][0] === '-') {
|
55 | argv.unshift(process.execPath)
|
56 | }
|
57 | return argv
|
58 | }
|
59 |
|
60 | function hideInstrumenteeArgs () {
|
61 | let argv = process.argv.slice(2)
|
62 | const yargv = parser(argv)
|
63 |
|
64 | if (!yargv._.length) return argv
|
65 |
|
66 |
|
67 |
|
68 | argv = argv.slice(0, argv.indexOf(yargv._[0]))
|
69 | argv.push(yargv._[0])
|
70 |
|
71 | return argv
|
72 | }
|
73 |
|
74 | module.exports = {
|
75 | yargs,
|
76 | hideInstrumenterArgs,
|
77 | hideInstrumenteeArgs
|
78 | }
|