Skip to content

Commit

Permalink
chore(bin): rewrite to async I/O (bcoe#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
profnandaa authored and bcoe committed Oct 12, 2018
1 parent b0d1b7b commit 23e5da6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ run `c8 report` to regenerate reports after `c8` has already been run.

c8 uses
[bleeding edge Node.js features](https://github.com/nodejs/node/pull/22527),
make sure you're running Node.js `>= 10.10.0`.
make sure you're running Node.js `>= 10.12.0`.

## Goals of the Project

Expand Down
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.

3 changes: 1 addition & 2 deletions 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 All @@ -55,7 +54,7 @@
"standard-version": "^4.4.0"
},
"engines": {
"node": ">=10.10.0"
"node": ">=10.12.0"
},
"files": [
"lib",
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 23e5da6

Please sign in to comment.