Skip to content

Commit

Permalink
Merge 622f0d5 into fde596e
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed May 2, 2019
2 parents fde596e + 622f0d5 commit 93b601e
Show file tree
Hide file tree
Showing 22 changed files with 385 additions and 23 deletions.
4 changes: 2 additions & 2 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let argv = buildYargs().parse(instrumenterArgs)
}

process.env.NODE_V8_COVERAGE = argv.tempDirectory
foreground(hideInstrumenterArgs(argv), done => {
outputReport(argv)
foreground(hideInstrumenterArgs(argv), async (done) => {
await outputReport(argv)
done()
})
}
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/check-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ exports.handler = function (argv) {
exports.checkCoverages(argv, report)
}

exports.checkCoverages = function (argv, report) {
exports.checkCoverages = async function (argv, report) {
const thresholds = {
lines: argv.lines,
functions: argv.functions,
branches: argv.branches,
statements: argv.statements
}
const map = report.getCoverageMapFromAllCoverageFiles()
const map = await report.getCoverageMapFromAllCoverageFiles()
if (argv.perFile) {
map.files().forEach(file => {
checkCoverage(map.fileCoverageFor(file).toSummary(), thresholds, file)
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ exports.command = 'report'

exports.describe = 'read V8 coverage data from temp and output report'

exports.handler = function (argv) {
exports.outputReport(argv)
exports.handler = async function (argv) {
await exports.outputReport(argv)
}

exports.outputReport = function (argv) {
exports.outputReport = async function (argv) {
const report = Report({
include: argv.include,
exclude: argv.exclude,
Expand All @@ -21,6 +21,6 @@ exports.outputReport = function (argv) {
omitRelative: argv.omitRelative,
wrapperLength: argv.wrapperLength
})
report.run()
await report.run()
if (argv.checkCoverage) checkCoverages(argv, report)
}
7 changes: 4 additions & 3 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Report {
this.omitRelative = omitRelative
this.wrapperLength = wrapperLength
}
run () {
const map = this.getCoverageMapFromAllCoverageFiles()
async run () {
const map = await this.getCoverageMapFromAllCoverageFiles()
var context = libReport.createContext({
dir: this.reportsDirectory,
watermarks: this.watermarks
Expand All @@ -47,7 +47,7 @@ class Report {
})
}

getCoverageMapFromAllCoverageFiles () {
async getCoverageMapFromAllCoverageFiles () {
// the merge process can be very expensive, and it's often the case that
// check-coverage is called immediately after a report. We memoize the
// result from getCoverageMapFromAllCoverageFiles() to address this
Expand All @@ -62,6 +62,7 @@ class Report {
try {
const path = resolve(this.resolve, v8ScriptCov.url)
const script = v8toIstanbul(path, this.wrapperLength)
await script.load()
script.applyCoverage(v8ScriptCov.functions)
map.merge(script.toIstanbul())
} catch (err) {
Expand Down
25 changes: 15 additions & 10 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 @@ -41,8 +41,7 @@
"istanbul-reports": "^2.0.0",
"rimraf": "^2.6.2",
"test-exclude": "^5.0.0",
"uuid": "^3.3.2",
"v8-to-istanbul": "^2.0.4",
"v8-to-istanbul": "^3.0.1",
"yargs": "^13.1.0",
"yargs-parser": "^10.1.0"
},
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/source-maps/branches/branches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if (false) {
console.info('unreachable')
} else if (true) {
console.info('reachable')
} else {
console.info('unreachable')
}

function branch (a) {
if (a) {
console.info('a = true')
} else if (undefined) {
console.info('unreachable')
} else {
console.info('a = false')
}
}

branch(true)
branch(false)
2 changes: 2 additions & 0 deletions test/fixtures/source-maps/branches/branches.nyc.js

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

28 changes: 28 additions & 0 deletions test/fixtures/source-maps/branches/branches.typescript.js

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

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

25 changes: 25 additions & 0 deletions test/fixtures/source-maps/branches/branches.typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
enum ATrue {
IsTrue = 1,
IsFalse = 0
}

if (false) {
console.info('unreachable')
} else if (true) {
console.info('reachable')
} else {
console.info('unreachable')
}

function branch (a: boolean) {
if (a) {
console.info('a = true')
} else if (undefined) {
console.info('unreachable')
} else {
console.info('a = false')
}
}

branch(!!ATrue.IsTrue)
branch(!!ATrue.IsFalse)
2 changes: 2 additions & 0 deletions test/fixtures/source-maps/branches/branches.uglify.js

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

1 change: 1 addition & 0 deletions test/fixtures/source-maps/branches/branches.uglify.js.map

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

27 changes: 27 additions & 0 deletions test/fixtures/source-maps/classes/classes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Foo {
constructor (x=33) {
this.x = x ? x : 99
if (this.x) {
console.info('covered')
} else {
console.info('uncovered')
}
this.methodC()
}
methodA () {
console.info('covered')
}
methodB () {
console.info('uncovered')
}
methodC () {
console.info('covered')
}
methodD () {
console.info('uncovered')
}
}

const a = new Foo(0)
const b = new Foo(33)
a.methodA()
2 changes: 2 additions & 0 deletions test/fixtures/source-maps/classes/classes.nyc.js

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

32 changes: 32 additions & 0 deletions test/fixtures/source-maps/classes/classes.typescript.js

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

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

33 changes: 33 additions & 0 deletions test/fixtures/source-maps/classes/classes.typescript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export interface FooOptions {
x: number;
}

class Foo {
x: number;
constructor (options: FooOptions) {
this.x = options.x ? options.x : 99
if (this.x) {
console.info('covered')
} else {
console.info('uncovered')
}
this.methodC()
}
methodA (): number {
console.info('covered')
return 33
}
methodB () {
console.info('uncovered')
}
private methodC () {
console.info('covered')
}
methodD () {
console.info('uncovered')
}
}

const a = new Foo({x: 0})
const b = new Foo({x: 33})
a.methodA()

0 comments on commit 93b601e

Please sign in to comment.