Skip to content

Commit

Permalink
chore(bin): rewrite to async I/O
Browse files Browse the repository at this point in the history
- Replace mkdirp with the new fs.mkdir with `recursive` option
- Rewrite all top level IO to async (mkdir and rimraf)

Remaining work: to rewrite lib/*.js to async I/O

Ref: bcoe#9
  • Loading branch information
profnandaa committed Sep 18, 2018
1 parent 6cf3601 commit b2ffe52
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
36 changes: 21 additions & 15 deletions bin/c8.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env node
'use strict'

const fs = require('fs')
const util = require('util')

const foreground = require('foreground-child')
const mkdirp = require('mkdirp')
const report = require('../lib/report')
const rimraf = require('rimraf')
const {
Expand All @@ -14,20 +16,7 @@ const {
const instrumenterArgs = hideInstrumenteeArgs()
let argv = yargs.parse(instrumenterArgs)

if (argv._[0] === 'report') {
argv = yargs.parse(process.argv) // support flag arguments after "report".
outputReport()
} else {
if (argv.clean) {
rimraf.sync(argv.tempDirectory)
mkdirp.sync(argv.tempDirectory)
}
process.env.NODE_V8_COVERAGE = argv.tempDirectory

foreground(hideInstrumenterArgs(argv), () => {
outputReport()
})
}
const _p = util.promisify

function outputReport () {
report({
Expand All @@ -40,3 +29,20 @@ function outputReport () {
omitRelative: argv.omitRelative
})
}

(async function run () {
if (argv._[0] === 'report') {
argv = yargs.parse(process.argv) // support flag arguments after "report".
outputReport()
} else {
if (argv.clean) {
await _p(rimraf)(argv.tempDirectory)
await _p(fs.mkdir)(argv.tempDirectory, { recursive: true })
}
process.env.NODE_V8_COVERAGE = argv.tempDirectory

foreground(hideInstrumenterArgs(argv), () => {
outputReport()
})
}
})()
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 @@ -37,7 +37,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",
"uuid": "^3.3.2",
Expand Down
6 changes: 3 additions & 3 deletions test/integration.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ second
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 92.5 | 69.23 | 0 | 92.5 | |
bin | 83.72 | 57.14 | 100 | 83.72 | |
c8.js | 83.72 | 57.14 | 100 | 83.72 |... 22,40,41,42,43 |
All files | 93.01 | 69.81 | 0 | 93.01 | |
bin | 87.76 | 62.5 | 100 | 87.76 | |
c8.js | 87.76 | 62.5 | 100 | 87.76 | 35,39,46,47,48,49 |
lib | 93.71 | 62.96 | 100 | 93.71 | |
parse-args.js | 97.47 | 44.44 | 100 | 97.47 | 55,56 |
report.js | 90.63 | 72.22 | 100 | 90.63 |... 70,71,85,86,87 |
Expand Down

0 comments on commit b2ffe52

Please sign in to comment.