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 4, 2019
1 parent b1c0949 commit 85b9beb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 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
5 changes: 3 additions & 2 deletions test/legacy-node.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/* 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, [
c8Path,
'--temp-directory=tmp/legacy-nodejs',
'node',
'--version'
])

existsSync(join(__dirname, '..', 'tmp', 'legacy-nodejs')).should.equal(false)
})
})

0 comments on commit 85b9beb

Please sign in to comment.