Coverage with Istanbul
See original GitHub issueI’m currently implementing coverage reporting with Istanbul and have coverage being written on a per-test basis, using a custom command.
Is there a way to hook a function into a global afterEach hook that will run with the same browser context as the test ran with, so it would have access to the same window object in the browser (to access the coverage variable)?
Are there any plans on adding coverage reporting into Nightwatch directly?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Istanbul, a JavaScript test coverage tool.
JavaScript test coverage made simple. How Istanbul works. Istanbul instruments your ES5 and ES2015+ JavaScript code with line counters, so that you can...
Read more >Measure your code coverage using Istanbul (with a demo)
Provides visual and informative reports. Provides ability to enforce minimum code coverage threshold. After some research, we found several good coverage tools ...
Read more >Learn how to use the Istanbul JavaScript Code Coverage Tool
Istanbul gives us four code coverage metrics: Statements: How many of the statements in you code are executed. Branches: Conditional statements create branches ......
Read more >Using Istanbul for Code Coverage in React | Pluralsight
Istanbul is a JavaScript code coverage tool that works by analyzing your codebase and providing you with the coverage insights you need in ......
Read more >karma-coverage-istanbul-reporter - npm
A karma reporter that uses the latest istanbul 1.x APIs (with full sourcemap support) to report coverage. About. This is a reporter only...
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 Free
Top 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

@KBPratap I did manage to get it working, but it’s a bit of a faff to get working.
First you need to have a version of your website with instrumented code. You then need to run nightwatch against this instrumented version of your site, and before calling
.end()in your tests you need to get the coverage information out of the window and write it to a file. I did this by creating a custom command,.finish, which does this, then calls.end, and stores coverage information into a data store.In the global
afterin nightwatch I then write out reports to the file system from the store of data.This isn’t a great method, but works for me. It has some limitations though, as if you get a full page load at any point in your test then you lose coverage information from the previous page. This wasn’t an issue for my project, but may be for you.
I haven’t been working with nightwatch in any projects recently so can’t say if there’s a better way of doing it, bit this worked for me.
FWIW I setup an example repo that does something similar to what is illustrated above https://github.com/aberonni/nightwatch-test-coverage-example