Created
October 7, 2017 21:01
-
-
Save jkrems/761d459bd913f2db16a0299659b16a87 to your computer and use it in GitHub Desktop.
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
// V8 6.2 required | |
'use strict'; | |
const fs = require('fs'); | |
const { Session } = require('inspector'); | |
const { promisify } = require('util'); | |
const session = new Session(); | |
if (session != null) { | |
session.connect(); | |
} | |
const run = promisify(session.post.bind(session)); | |
const NATIVES = process.binding('natives'); | |
function formatCoverage({ url, scriptId, functions }) { | |
const isInternal = /^[\w-]+(?:\/[\w-]+)*\.js$/.test(url); | |
if (url.includes('internal/fs')) { | |
const source = isInternal ? | |
NATIVES[url.replace(/\.js$/, '')] : fs.readFileSync(url, 'utf8'); | |
const markers = [ | |
{ | |
startOffset: 0, | |
endOffset: source.length, | |
count: 0, | |
} | |
]; | |
functions.forEach(f => { | |
f.ranges.forEach(range => { | |
if (range.count > 0) { | |
console.log('covered:\n', source.slice(range.startOffset, range.endOffset)); | |
} | |
}); | |
}); | |
} | |
} | |
run('Profiler.enable') | |
.then(() => run('Profiler.startPreciseCoverage', { detailed: true })) | |
.then(() => { | |
require('./test/parallel/test-fs-read-file-sync.js'); | |
}) | |
.then(() => run('Profiler.takePreciseCoverage')) | |
.then((data) => data.result.forEach(formatCoverage)) | |
.then(() => run('Profiler.stopPreciseCoverage')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment