Skip to content

Commit

Permalink
chore: Add test for nyc --no-clean. (#1071)
Browse files Browse the repository at this point in the history
Verify that running `nyc command1 && nyc --no-clean command2` causes
results results to be merged.
  • Loading branch information
coreyfarrell committed Apr 18, 2019
1 parent 21fb2c8 commit 85c1eac
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/fixtures/cli/by-arg2.js
@@ -0,0 +1,8 @@
const arg = process.argv[2];
if (arg === '1') {
console.log('1')
} else if (arg === '2') {
console.log('2')
} else {
console.log('unexpected')
}
42 changes: 42 additions & 0 deletions test/nyc-integration.js
Expand Up @@ -1254,6 +1254,48 @@ describe('the nyc cli', function () {
})
})

it('handles --clean / --no-clean properly', () => {
rimraf.sync(path.resolve(fixturesCLI, '.nyc_output'))
const args = (doClean, arg) => [
bin,
doClean ? '--clean' : '--no-clean',
process.execPath,
'./by-arg2.js',
arg
]
const opts = {
cwd: fixturesCLI,
env: env,
encoding: 'utf8'
}

const proc1 = spawnSync(process.execPath, args(true, '1'), opts)
proc1.status.should.equal(0)
stdoutShouldEqual(proc1.stdout, `
1
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 50 | 25 | 100 | 50 | |
by-arg2.js | 50 | 25 | 100 | 50 | 4,5,7 |
------------|----------|----------|----------|----------|-------------------|`
)
proc1.stderr.should.equal('')

const proc2 = spawnSync(process.execPath, args(false, '2'), opts)
proc2.status.should.equal(0)
stdoutShouldEqual(proc2.stdout, `
2
------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
------------|----------|----------|----------|----------|-------------------|
All files | 83.33 | 75 | 100 | 83.33 | |
by-arg2.js | 83.33 | 75 | 100 | 83.33 | 7 |
------------|----------|----------|----------|----------|-------------------|`
)
proc2.stderr.should.equal('')
})

describe('noop instrumenter', function () {
it('setting instrument to "false" configures noop instrumenter', function (done) {
var args = [
Expand Down

0 comments on commit 85c1eac

Please sign in to comment.