Skip to content

Commit

Permalink
do not try creating reports on legacy Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed May 5, 2019
1 parent b1c0949 commit f9bdcb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ async function run () {
].indexOf(argv._[0]) !== -1) {
argv = buildYargs(true).parse(process.argv.slice(2))
} else {
// allow c8 to run on Node 8 (coverage just won't work).
if (!promises) {
foreground(hideInstrumenterArgs(argv))
return
}

if (argv.clean) {
await promisify(rimraf)(argv.tempDirectory)
}
// allow c8 to run on Node 8 (coverage just won't work).
if (promises) {
await promises.mkdir(argv.tempDirectory, { recursive: true })
}

await promises.mkdir(argv.tempDirectory, { recursive: true })
process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), async (done) => {
try {
Expand Down
16 changes: 9 additions & 7 deletions test/legacy-node.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/* global describe, it */

const { execFile } = require('child_process')
const { mkdir } = require('fs').promises
const { existsSync } = require('fs')
const { join } = require('path')
const { promisify } = require('util')
const c8Path = require.resolve('./fixtures/disable-fs-promises')
const nodePath = process.execPath

describe('c8 on Node.js < 10', () => {
it('doesn\'t crash', async () => {
await mkdir(join(__dirname, '..', 'tmp', 'legacy-nodejs'))
await promisify(execFile)(nodePath, [
it('skip coverage', async () => {
const tmp = join(__dirname, '..', 'tmp', 'legacy-nodejs')

await promisify(execFile)(process.execPath, [
c8Path,
'--temp-directory=tmp/legacy-nodejs',
'node',
`--temp-directory=${__filename}`,
process.execPath,
'--version'
])

existsSync(tmp).should.equal(false)
})
})

0 comments on commit f9bdcb4

Please sign in to comment.