-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Build: Produce C/JS code coverage reports from make #10856
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const process = require('process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const mkdirSync = fs.mkdirSync; | ||
const writeFileSync = fs.writeFileSync; | ||
|
||
var isWritingCoverage = false; | ||
function writeCoverage() { | ||
if (isWritingCoverage || !global.__coverage__) { | ||
return; | ||
} | ||
isWritingCoverage = true; | ||
|
||
const dirname = path.join(path.dirname(process.execPath), '.coverage'); | ||
const filename = `coverage-${process.pid}-${Date.now()}.json`; | ||
try { | ||
mkdirSync(dirname); | ||
} catch (err) { | ||
if (err.code !== 'EEXIST') { | ||
console.error(err); | ||
return; | ||
} | ||
} | ||
|
||
const target = path.join(dirname, filename); | ||
const coverageInfo = JSON.stringify(global.__coverage__); | ||
try { | ||
writeFileSync(target, coverageInfo); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
function setup() { | ||
const reallyReallyExit = process.reallyExit; | ||
|
||
process.reallyExit = function(code) { | ||
writeCoverage(); | ||
reallyReallyExit(code); | ||
}; | ||
|
||
process.on('exit', writeCoverage); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth running the contents of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've put the check for |
||
|
||
exports.setup = setup; |
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.
Hmmm, not 100% sold on this.
Is
process.really
a JS function? If so, can we put this hook into it directly somehow?Also, could you point to a test that hits this but not the exit event?
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.
process.reallyExit
is a C++ function.I put this in there to try to be really sure that
writeCoverage()
is called, especially since we have code that testsprocess.exit()
itself… I can try to run coverage locally later without this, and see if there’s any difference