-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement Istanbul reporting #8
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1550967
feat: implement istanbul reporting
4999add
nit: slight tweak to naming
b5d52e0
chore: fix linting issues
b0bc1dc
fix: use the bin instrumented with c8, matching nyc's behavior
601eec5
chore: dogfood
b6ff55c
chore: working ESM
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
.nyc_output | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const Exclude = require('test-exclude') | ||
const findUp = require('find-up') | ||
const {readFileSync} = require('fs') | ||
const yargs = require('yargs') | ||
const parser = require('yargs-parser') | ||
|
||
const configPath = findUp.sync(['.c8rc', '.c8rc.json']) | ||
const config = configPath ? JSON.parse(readFileSync(configPath)) : {} | ||
|
||
yargs | ||
.usage('$0 [opts] [script] [opts]') | ||
.option('reporter', { | ||
alias: 'r', | ||
describe: 'coverage reporter(s) to use', | ||
default: 'text' | ||
}) | ||
.option('exclude', { | ||
alias: 'x', | ||
default: Exclude.defaultExclude, | ||
describe: 'a list of specific files and directories that should be excluded from coverage, glob patterns are supported.' | ||
}) | ||
.option('include', { | ||
alias: 'n', | ||
default: [], | ||
describe: 'a list of specific files that should be covered, glob patterns are supported' | ||
}) | ||
.option('coverage-directory', { | ||
default: './coverage', | ||
describe: 'directory to output coverage JSON and reports' | ||
}) | ||
.pkgConf('c8') | ||
.config(config) | ||
.demandCommand(1) | ||
.epilog('visit https://git.io/vHysA for list of available reporters') | ||
|
||
function hideInstrumenterArgs (yargv) { | ||
var argv = process.argv.slice(1) | ||
argv = argv.slice(argv.indexOf(yargv._[0])) | ||
if (argv[0][0] === '-') { | ||
argv.unshift(process.execPath) | ||
} | ||
return argv | ||
} | ||
|
||
function hideInstrumenteeArgs () { | ||
let argv = process.argv.slice(2) | ||
const yargv = parser(argv) | ||
|
||
if (!yargv._.length) return argv | ||
|
||
// drop all the arguments after the bin being | ||
// instrumented by c8. | ||
argv = argv.slice(0, argv.indexOf(yargv._[0])) | ||
argv.push(yargv._[0]) | ||
|
||
return argv | ||
} | ||
|
||
module.exports = { | ||
yargs, | ||
hideInstrumenterArgs, | ||
hideInstrumenteeArgs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const libCoverage = require('istanbul-lib-coverage') | ||
const libReport = require('istanbul-lib-report') | ||
const reports = require('istanbul-reports') | ||
const {readdirSync, readFileSync} = require('fs') | ||
const {resolve} = require('path') | ||
|
||
class Report { | ||
constructor ({reporter, coverageDirectory, watermarks}) { | ||
this.reporter = reporter | ||
this.coverageDirectory = coverageDirectory | ||
this.watermarks = watermarks | ||
} | ||
run () { | ||
const map = this._getCoverageMapFromAllCoverageFiles() | ||
var context = libReport.createContext({ | ||
dir: './coverage', | ||
watermarks: this.watermarks | ||
}) | ||
|
||
const tree = libReport.summarizers.pkg(map) | ||
|
||
this.reporter.forEach(function (_reporter) { | ||
tree.visit(reports.create(_reporter), context) | ||
}) | ||
} | ||
_getCoverageMapFromAllCoverageFiles () { | ||
const map = libCoverage.createCoverageMap({}) | ||
|
||
this._loadReports().forEach(function (report) { | ||
map.merge(report) | ||
}) | ||
|
||
return map | ||
} | ||
_loadReports () { | ||
const tmpDirctory = resolve(this.coverageDirectory, './tmp') | ||
const files = readdirSync(tmpDirctory) | ||
|
||
return files.map((f) => { | ||
return JSON.parse(readFileSync( | ||
resolve(tmpDirctory, f), | ||
'utf8' | ||
)) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = function (opts) { | ||
const report = new Report(opts) | ||
report.run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not like it matters much, but can you use asynchronous I/O if possible?