Skip to content

Commit

Permalink
Merge 85b9beb into a27b694
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed May 4, 2019
2 parents a27b694 + 85b9beb commit cf4e00a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
11 changes: 8 additions & 3 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const foreground = require('foreground-child')
const { outputReport } = require('../lib/commands/report')
const mkdirp = require('mkdirp')
const { promises } = require('fs')
const { promisify } = require('util')
const rimraf = require('rimraf')
const {
Expand All @@ -21,12 +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).
await promisify(mkdirp)(argv.tempDirectory)

await promises.mkdir(argv.tempDirectory, { recursive: true })
process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), async (done) => {
try {
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"istanbul-lib-coverage": "^2.0.1",
"istanbul-lib-report": "^2.0.1",
"istanbul-reports": "^2.0.0",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.2",
"test-exclude": "^5.0.0",
"v8-to-istanbul": "^3.1.1",
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/disable-fs-promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const fs = require('fs');

Object.defineProperty(fs, 'promises', {value: undefined});
require('../../bin/c8.js');
21 changes: 21 additions & 0 deletions test/legacy-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* global describe, it */

const { execFile } = require('child_process')
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 promisify(execFile)(nodePath, [
c8Path,
'--temp-directory=tmp/legacy-nodejs',
'node',
'--version'
])

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

0 comments on commit cf4e00a

Please sign in to comment.