Code coverage
See original GitHub issueHi devs, maybe you can bring some light to this.
Is it possible to get code coverage as featured in chrome 59 in an understandable way (reporting lines used, unused, percentage)?
I tried to use the Profiler methods but I get function offsets(lines?) and counts that does not match if I use the coverage feature manually in Chrome.
I have some tests running in localhost:3000
. The execution takes 10 seconds (I have a few), so is there a way to extend the recording of the coverage to 10 secs? using setTimeout?.
I’m lost , I’m not grasping this 😦
My code:
const CDP = require('chrome-remote-interface');
CDP((client) => {
// extract domains
const {
Network,
Page,
Profiler
} = client;
// setup handlers
Network.requestWillBeSent((params) => {
console.log(params.request.url);
});
// enable events then start!
Promise.all([
Network.enable(),
Page.enable(),
Profiler.enable(),
Profiler.startPreciseCoverage()
])
.then(() => {
return Page.navigate({
url: 'http://localhost:3000'
});
})
.then(() => Profiler.getBestEffortCoverage())
.then((data) => data.result.forEach((el) => {
console.log('-----', el.url)
el.functions.forEach((el) => {
console.log('--', el.functionName)
console.log('ranges', el.ranges)
})
}))
.catch((err) => {
console.error(err);
client.close();
});
}).on('error', (err) => {
// cannot connect to the remote endpoint
console.error(err);
});
some output
-- myFunction
ranges [ { startOffset: 907, endOffset: 1490, count: 1 } ] // But it is a 3 line function and it is not executed!!
All the best.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Code coverage - Wikipedia
In computer science, test coverage is a percentage measure of the degree to which the source code of a program is executed when...
Read more >Everything you need to know about code coverage - Codegrip
Code coverage is a software testing metric that determines the number of lines of code that is successfully validated under a test procedure,...
Read more >Code coverage testing - Visual Studio (Windows)
Code coverage is counted in blocks. Block is a part of code with exactly one entry and exit point. If the program's control...
Read more >Codecov - The Leading Code Coverage Solution
Codecov is the leading, dedicated code coverage solution. Try Codecov for free now to help your developers find untested code and deploy changes...
Read more >Code Coverage vs Test Coverage: A Detailed Guide
Code coverage is a white-box testing technique performed to verify the extent to which the code has been executed. Code coverage tools use ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For traceability purposes:
https://groups.google.com/forum/#!topic/chrome-debugging-protocol/ILVA8tv7sSc
http://www.mattzeunert.com/2017/03/29/how-does-chrome-code-coverage-work.html
The
scriptSource
is:The offsets are relative to this string, so for example:
You can roughly get the number of lines of the script (or of any range or function) with:
For what concerns
count
I’m a bit puzzled, it seems to be always 1 even though the functionfoo
is called 10000 times per second… The documentation says:But if you’re just interested in the coverage it doesn’t really matter, I guess. You may want to ask this in the Google Group.
Cheers! 😃