I want to measure code coverage of Angular 12 application. I have Automation test written in Selenium which runs the application deployed on another machine. I have tried the following steps using istanbul:
- set source maps to true in
angular.json
- build the app using
ng build --configuration production
- instrument the dist code using
nyc instrument --in-place dist/
- serve the dist folder locally using http-server
- Access the application in local browser
- Capture the
window.__coverage__
object from the browser - Store the object in
.nyc_output
directory as a json file - generate report using
nyc report --reporter=lcov
The generated HTML report contains coverage for dist and dist/webpack:/src etc. The files mentioned when drilled down have the error:
Unable to lookup source: /home/test/code-coverage/ui-analytics/dist/webpack:/src/main.ts (ENOENT: no such file or directory, open '/home/test/code-coverage/ui-analytics/dist/webpack:/src/main.ts')
Also, the coverage/lcov-report folder, there are weird folders created like webpack:
.
If I build without source maps, I get the report of dist folder (the minified files).
Any help will be appreciated!