-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge together multiple istanbul format reports (#840)
- Loading branch information
Showing
8 changed files
with
544 additions
and
16 deletions.
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
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,51 @@ | ||
'use strict' | ||
const fs = require('fs') | ||
|
||
var NYC | ||
try { | ||
NYC = require('../../index.covered.js') | ||
} catch (e) { | ||
NYC = require('../../index.js') | ||
} | ||
|
||
exports.command = 'merge <input-directory> [output-file]' | ||
|
||
exports.describe = 'merge istanbul format coverage output in a given folder' | ||
|
||
exports.builder = function (yargs) { | ||
return yargs | ||
.positional('input-directory', { | ||
describe: 'directory containing multiple istanbul coverage files', | ||
type: 'text', | ||
default: './.nyc_output' | ||
}) | ||
.positional('output-file', { | ||
describe: 'file to output combined istanbul format coverage to', | ||
type: 'text', | ||
default: 'coverage.json' | ||
}) | ||
.option('temp-directory', { | ||
describe: 'directory to read raw coverage information from', | ||
default: './.nyc_output' | ||
}) | ||
.example('$0 merge ./out coverage.json', 'merge together reports in ./out and output as coverage.json') | ||
} | ||
|
||
exports.handler = function (argv) { | ||
process.env.NYC_CWD = process.cwd() | ||
const nyc = new NYC(argv) | ||
let inputStat | ||
try { | ||
inputStat = fs.statSync(argv.inputDirectory) | ||
if (!inputStat.isDirectory()) { | ||
console.error(`${argv.inputDirectory} was not a directory`) | ||
process.exit(1) | ||
} | ||
} catch (err) { | ||
console.error(`failed access input directory ${argv.inputDirectory} with error:\n\n${err.message}`) | ||
process.exit(1) | ||
} | ||
const map = nyc.getCoverageMapFromAllCoverageFiles(argv.inputDirectory) | ||
fs.writeFileSync(argv.outputFile, JSON.stringify(map, null, 2), 'utf8') | ||
console.info(`coverage files in ${argv.inputDirectory} merged into ${argv.outputFile}`) | ||
} |
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,200 @@ | ||
{ | ||
"/private/tmp/contrived/library.js": { | ||
"path": "/private/tmp/contrived/library.js", | ||
"statementMap": { | ||
"0": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 15, | ||
"column": 1 | ||
} | ||
}, | ||
"1": { | ||
"start": { | ||
"line": 3, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 16 | ||
} | ||
}, | ||
"2": { | ||
"start": { | ||
"line": 6, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 6, | ||
"column": 16 | ||
} | ||
}, | ||
"3": { | ||
"start": { | ||
"line": 9, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 13, | ||
"column": 5 | ||
} | ||
}, | ||
"4": { | ||
"start": { | ||
"line": 10, | ||
"column": 6 | ||
}, | ||
"end": { | ||
"line": 10, | ||
"column": 14 | ||
} | ||
}, | ||
"5": { | ||
"start": { | ||
"line": 12, | ||
"column": 6 | ||
}, | ||
"end": { | ||
"line": 12, | ||
"column": 14 | ||
} | ||
} | ||
}, | ||
"fnMap": { | ||
"0": { | ||
"name": "(anonymous_0)", | ||
"decl": { | ||
"start": { | ||
"line": 2, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 12 | ||
} | ||
}, | ||
"loc": { | ||
"start": { | ||
"line": 2, | ||
"column": 21 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 3 | ||
} | ||
}, | ||
"line": 2 | ||
}, | ||
"1": { | ||
"name": "(anonymous_1)", | ||
"decl": { | ||
"start": { | ||
"line": 5, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 5, | ||
"column": 12 | ||
} | ||
}, | ||
"loc": { | ||
"start": { | ||
"line": 5, | ||
"column": 21 | ||
}, | ||
"end": { | ||
"line": 7, | ||
"column": 3 | ||
} | ||
}, | ||
"line": 5 | ||
}, | ||
"2": { | ||
"name": "(anonymous_2)", | ||
"decl": { | ||
"start": { | ||
"line": 8, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"line": 8, | ||
"column": 12 | ||
} | ||
}, | ||
"loc": { | ||
"start": { | ||
"line": 8, | ||
"column": 18 | ||
}, | ||
"end": { | ||
"line": 14, | ||
"column": 3 | ||
} | ||
}, | ||
"line": 8 | ||
} | ||
}, | ||
"branchMap": { | ||
"0": { | ||
"loc": { | ||
"start": { | ||
"line": 9, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 13, | ||
"column": 5 | ||
} | ||
}, | ||
"type": "if", | ||
"locations": [ | ||
{ | ||
"start": { | ||
"line": 9, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 13, | ||
"column": 5 | ||
} | ||
}, | ||
{ | ||
"start": { | ||
"line": 9, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 13, | ||
"column": 5 | ||
} | ||
} | ||
], | ||
"line": 9 | ||
} | ||
}, | ||
"s": { | ||
"0": 1, | ||
"1": 1, | ||
"2": 0, | ||
"3": 1, | ||
"4": 0, | ||
"5": 1 | ||
}, | ||
"f": { | ||
"0": 1, | ||
"1": 0, | ||
"2": 1 | ||
}, | ||
"b": { | ||
"0": [ | ||
0, | ||
1 | ||
] | ||
}, | ||
"_coverageSchema": "332fd63041d2c1bcb487cc26dd0d5f7d97098a6c", | ||
"hash": "e86c0c0fa7c4fadac81e2479bfba3c0d59b657aa" | ||
} | ||
} |
Oops, something went wrong.