-
Notifications
You must be signed in to change notification settings - Fork 89
/
parse-args.js
101 lines (93 loc) · 4.16 KB
/
parse-args.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* global describe, it */
const {
buildYargs,
hideInstrumenteeArgs,
hideInstrumenterArgs
} = require('../lib/parse-args')
const { join, resolve } = require('path')
describe('parse-args', () => {
describe('hideInstrumenteeArgs', () => {
it('hides arguments passed to instrumented app', () => {
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
const instrumenterArgs = hideInstrumenteeArgs()
instrumenterArgs.should.eql(['--foo=99', 'my-app'])
})
})
describe('hideInstrumenterArgs', () => {
it('hides arguments passed to c8 bin', () => {
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
const argv = buildYargs().parse(hideInstrumenteeArgs())
const instrumenteeArgs = hideInstrumenterArgs(argv)
instrumenteeArgs.should.eql(['my-app', '--help'])
argv.tempDirectory.endsWith(join('coverage', 'tmp')).should.be.equal(true)
})
})
describe('with NODE_V8_COVERAGE already set', () => {
it('should not override it', () => {
const NODE_V8_COVERAGE = process.env.NODE_V8_COVERAGE
process.env.NODE_V8_COVERAGE = './coverage/tmp_'
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
const argv = buildYargs().parse(hideInstrumenteeArgs())
argv.tempDirectory.endsWith('/coverage/tmp_').should.be.equal(true)
process.env.NODE_V8_COVERAGE = NODE_V8_COVERAGE
})
})
describe('--config', () => {
it('should resolve to .nycrc at cwd', () => {
const argv = buildYargs().parse(['node', 'c8', 'my-app'])
argv.lines.should.be.equal(95)
})
it('should use config file specified in --config', () => {
const argv = buildYargs().parse(['node', 'c8', '--config', require.resolve('./fixtures/config/.c8rc.json')])
argv.lines.should.be.equal(101)
argv.tempDirectory.should.be.equal('./foo')
})
it('should have -c as an alias', () => {
const argv = buildYargs().parse(['node', 'c8', '-c', require.resolve('./fixtures/config/.c8rc.json')])
argv.lines.should.be.equal(101)
argv.tempDirectory.should.be.equal('./foo')
})
it('should respect options on the command line over config file', () => {
const argv = buildYargs().parse(['node', 'c8', '--lines', '100', '--config', require.resolve('./fixtures/config/.c8rc.json')])
argv.lines.should.be.equal(100)
})
it('should allow config files to extend each other', () => {
const argv = buildYargs().parse(['node', 'c8', '--lines', '100', '--config', require.resolve('./fixtures/config/.c8rc-base.json')])
argv.branches.should.be.equal(55)
argv.lines.should.be.equal(100)
argv.functions.should.be.equal(24)
})
it('should allow relative path reports directories', () => {
const argsArray = ['node', 'c8', '--lines', '100', '--reports-dir', './coverage_']
const argv = buildYargs().parse(argsArray)
argv.reportsDir.should.be.equal('./coverage_')
})
it('should allow relative path temporary directories', () => {
const argsArray = ['node', 'c8', '--lines', '100', '--temp-directory', './coverage/tmp_']
const argv = buildYargs().parse(argsArray)
argv.tempDirectory.should.be.equal('./coverage/tmp_')
})
it('should allow absolute path reports directories', () => {
const tmpDir = resolve(process.cwd(), 'coverage_')
const argsArray = ['node', 'c8', '--lines', '100', '--reports-dir', tmpDir]
const argv = buildYargs().parse(argsArray)
argv.reportsDir.should.be.equal(tmpDir)
})
it('should allow absolute path temporary directories', () => {
const tmpDir = resolve(process.cwd(), './coverage/tmp_')
const argsArray = ['node', 'c8', '--lines', '100', '--temp-directory', tmpDir]
const argv = buildYargs().parse(argsArray)
argv.tempDirectory.should.be.equal(tmpDir)
})
})
describe('--merge-async', () => {
it('should default to false', () => {
const argv = buildYargs().parse(['node', 'c8'])
argv.mergeAsync.should.be.equal(false)
})
it('should set to true when flag exists', () => {
const argv = buildYargs().parse(['node', 'c8', '--merge-async'])
argv.mergeAsync.should.be.equal(true)
})
})
})