Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase Code Quality By Increasing Code Coverage: lib/parse-args.js #447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function buildYargs (withCommands = false) {
alias: ['o', 'report-dir'],
group: 'Reporting options',
describe: 'directory where coverage reports will be output to',
default: './coverage'
default: './coverage',
type: 'string'
})
.options('all', {
default: false,
Expand Down Expand Up @@ -126,7 +127,8 @@ function buildYargs (withCommands = false) {
})
.option('temp-directory', {
describe: 'directory V8 coverage data is written to and read from',
default: process.env.NODE_V8_COVERAGE
default: process.env.NODE_V8_COVERAGE,
type: 'string'
})
.option('clean', {
default: true,
Expand Down Expand Up @@ -207,12 +209,12 @@ function hideInstrumenteeArgs () {
let argv = process.argv.slice(2)
const yargv = parser(argv)

if (!yargv._.length) return argv

// drop all the arguments after the bin being
// instrumented by c8.
argv = argv.slice(0, argv.indexOf(yargv._[0]))
argv.push(yargv._[0])
if (yargv._.length !== 0) {
// drop all the arguments after the bin being
// instrumented by c8.
argv = argv.slice(0, argv.indexOf(yargv._[0]))
argv.push(yargv._[0])
}

return argv
}
mcknasty marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ All files | 3.52 | 12.5 | 6.52 | 3.52
prettify.js | 0 | 0 | 0 | 0 | 1-2
sorter.js | 0 | 0 | 0 | 0 | 1-196
c8/lib | 0 | 0 | 0 | 0 |
parse-args.js | 0 | 0 | 0 | 0 | 1-224
parse-args.js | 0 | 0 | 0 | 0 | 1-226
report.js | 0 | 0 | 0 | 0 | 1-402
source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100
c8/lib/commands | 0 | 0 | 0 | 0 |
Expand Down Expand Up @@ -531,7 +531,7 @@ All files | 3.52 | 12.5 | 6.52 | 3.52
prettify.js | 0 | 0 | 0 | 0 | 1-2
sorter.js | 0 | 0 | 0 | 0 | 1-196
c8/lib | 0 | 0 | 0 | 0 |
parse-args.js | 0 | 0 | 0 | 0 | 1-224
parse-args.js | 0 | 0 | 0 | 0 | 1-226
report.js | 0 | 0 | 0 | 0 | 1-402
source-map-from-file.js | 0 | 0 | 0 | 0 | 1-100
c8/lib/commands | 0 | 0 | 0 | 0 |
Expand Down
24 changes: 24 additions & 0 deletions test/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ describe('parse-args', () => {
const instrumenterArgs = hideInstrumenteeArgs()
instrumenterArgs.should.eql(['--foo=99', 'my-app'])
})
it('test early exit from function if no arguments are passed', () => {
process.argv = []
const instrumenterArgs = hideInstrumenteeArgs()
instrumenterArgs.length.should.eql(0)
})
})

describe('hideInstrumenterArgs', () => {
Expand All @@ -25,6 +30,13 @@ describe('parse-args', () => {
instrumenteeArgs.should.eql(['my-app', '--help'])
argv.tempDirectory.endsWith(join('coverage', 'tmp')).should.be.equal(true)
})
it('interprets first args after -- as Node.js execArgv', () => {
const expected = [process.execPath, '--expose-gc', 'index.js']
process.argv = ['node', 'c8', '--', '--expose-gc', 'index.js']
const argv = buildYargs().parse(hideInstrumenteeArgs())
const munged = hideInstrumenterArgs(argv)
munged.should.deep.equal(expected)
})
})

describe('with NODE_V8_COVERAGE already set', () => {
Expand All @@ -34,8 +46,20 @@ describe('parse-args', () => {
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
const argv = buildYargs().parse(hideInstrumenteeArgs())
argv.tempDirectory.endsWith('/coverage/tmp_').should.be.equal(true)
delete process.env.NODE_V8_COVERAGE
process.env.NODE_V8_COVERAGE = NODE_V8_COVERAGE
})
/** Commenting out till the print config PR is ready * /
it('should set it if undefined', () => {
const NODE_V8_COVERAGE = process.env.NODE_V8_COVERAGE
process.env.NODE_V8_COVERAGE = undefined
process.argv = ['node', 'c8', '--foo=99', 'my-app', '--help']
const argv = buildYargs().parse(hideInstrumenteeArgs())
argv.tempDirectory.endsWith('/coverage/tmp').should.be.equal(true)
delete process.env.NODE_V8_COVERAGE
process.env.NODE_V8_COVERAGE = NODE_V8_COVERAGE
})
/** */
Comment on lines +52 to +62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another candidate for updating unit tests as it relates to (#516)

Comment on lines +52 to +62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to uncomment and skip this test.

})

describe('--config', () => {
Expand Down