2

How does one setup istanbuls nyc to run test coverage via cypress tests on angular transpiled code?

I transpile the code via ng build, it appears in the build/client/ directory, I also transpile my cypress tests and they appear in the build/cypress/. I then run the cypress tests in build/cypress/ via the command:

npx tsc --project tsconfig.client.test.json
npx ng build
npx nyc --nycrc-path=./.nycrc.client.json cypress run --config reporter=spec

My .nycrc.client.json file:

{
    "branches": 0,
    "lines": 0,
    "functions": 0,
    "statements": 0,
    "check-coverage": true,
    "exclude-after-remap": false,
    "reporter": ["text", "html"],
    "clean": true,
    "cache": false,
    "all": true
    "report-dir": "./results/coverage/client",
    "include": [
        "build/client/**/*.js",
        "build/cypress/**/*.js"
    ],
    "exclude": [
        "build/client/es2015-polyfills.js",
        "build/client/polyfills.js",
        "build/client/runtime.js",
        "build/client/styles.js",
        "build/client/vendor.js"
    ]
}

The coverage report in the console:

------------------------------------------------------------------------------------------------------------------------------|----------|----------|----------|----------|-------------------|
File                                                                                                                          |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
------------------------------------------------------------------------------------------------------------------------------|----------|----------|----------|----------|-------------------|
All files                                                                                                                     |        0 |        0 |        0 |        0 |                   |
 webpack:                                                                                                                     |        0 |        0 |        0 |        0 |                   |
  $_lazy_route_resource lazy namespace object                                                                                 |        0 |        0 |        0 |        0 |... 58,61,62,64,65 |
 webpack:/client                                                                                                              |        0 |        0 |        0 |        0 |                   |
  main.ts                                                                                                                     |        0 |        0 |        0 |        0 |      1,9,10,13,15 |
 webpack:/client/app                                                                                                          |        0 |        0 |        0 |        0 |                   |
  app-routing.module.ts                                                                                                       |        0 |      100 |        0 |        0 |            25,147 |
  app.component.html                                                                                                          |        0 |      100 |      100 |        0 |                 1 |
  app.component.scss                                                                                                          |        0 |      100 |      100 |        0 |                 1 |
...etc.

Why is webpack involved here?

Also, it states that the test files where never used:

enter image description here

Here is the test report in from the console that shows that both were hit:

enter image description here

The html generated also for the coverage is incorrect:

All files / webpack:/client/bff/components/main-nav main-nav.component.html
0% Statements 0/1 100% Branches 0/0 100% Functions 0/0 0% Lines 0/1
Press n or j to go to the next uncovered block, b, p or k for the previous block.

Unable to lookup source: /home/karl/dev/MOP/build/client/webpack:/client/bff/components/main-nav/main-nav.component.html(ENOENT: no such file or directory, open '/home/karl/dev/MOP/build/client/webpack:/client/bff/components/main-nav/main-nav.component.html')
Error: Unable to lookup source: /home/karl/dev/MOP/build/client/webpack:/client/bff/components/main-nav/main-nav.component.html(ENOENT: no such file or directory, open '/home/karl/dev/MOP/build/client/webpack:/client/bff/components/main-nav/main-nav.component.html')
    at Context.defaultSourceLookup [as sourceFinder] (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/context.js:15:15)
    at Context.getSource (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/context.js:78:17)
    at Object.annotateSourceCode (/home/karl/dev/MOP/node_modules/istanbul-reports/lib/html/annotator.js:217:40)
    at HtmlReport.onDetail (/home/karl/dev/MOP/node_modules/istanbul-reports/lib/html/index.js:265:27)
    at Visitor.(anonymous function) [as onDetail] (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/tree.js:34:30)
    at ReportNode.Node.visit (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/tree.js:114:17)
    at getChildren.forEach.child (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/tree.js:118:15)
    at Array.forEach ()
    at ReportNode.Node.visit (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/tree.js:117:24)
    at getChildren.forEach.child (/home/karl/dev/MOP/node_modules/istanbul-lib-report/lib/tree.js:118:15)
basickarl
  • 37,187
  • 64
  • 214
  • 335

0 Answers0