Empty istanbul (nyc) report while coverage files are filled properly with Selenium

Viewed 422

The web app is written in python + typescript and uses Selenium for the font-end tests. I've tried to follow this answer to setup the test coverage analysis. The simplified pipeline is:

  1. After TS --> JS conversion the code is instrumented with nyc nyc instrument ./dist/js_cov/ ./dist/js/ --embed-source true
  2. Selenium runs some tests and stores the output in the .nyc_output folder. The files are generated correctly with coverage info inside e.g.
{"path/vars.bundle.js":{"path":"path/vars.bundle.js""statementMap":{"0":{"start":{"line":1,"column":9},"end":{"line":550,"column":1}},...

I've also checked that in the browser console window.__coverage__ looks well with the list of files and coverage results.

  1. I expect nyc report --cwd . to show the coverage result, but the report is always empty. Neither files nor coverage results are shown.
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------

nyc merge works fine and create a general coverage file for all the tests, bu the report is still empty

What could be the problem that causes an empty report?

1 Answers

I ran into something very similar trying to get coverage using playwright on our application. The nyc report --cwd . was key to getting it to output correctly. Where ever you run that from you should have the .nyc_output folder directly under it. While that worked I still had bad paths when trying to lookup individual files and had to override node_modules/istanbul-lib-report/lib/context.js directly and rewrite the defaultSourceLookup function to correct the path.

Related