Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nyc-config-typescript: bug in code coverage #523

Open
YoDaMa opened this issue Jan 31, 2020 · 5 comments
Open

nyc-config-typescript: bug in code coverage #523

YoDaMa opened this issue Jan 31, 2020 · 5 comments

Comments

@YoDaMa
Copy link

YoDaMa commented Jan 31, 2020

When using the @istanbuljs/nyc-config-typescript to extend the coverage from nyc for a typescript project written in mocha, there's a bug.

If I run a test where I'm not extending from the @istanbuljs/nyc-config-typescript, then I get proper code coverage results through nyc. Here's an example printout (I'm setting code coverage thresholds all to 100 in my nyc configurations).

My script in my package.json that I'm running:

"scripts": {
        "unittest": "tsc && nyc --reporter lcov --reporter text --check-coverage true mocha test/_*_test.js"
}

And here's the nyc configuration I have in my package.json:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "check-coverage": true,
    "statements": 100,
    "lines": 100,
    "functions": 100,
    "branches": 100
  },

The result:

  88 passing (186ms)

ERROR: Coverage for lines (0%) does not meet global threshold (100%)
ERROR: Coverage for functions (0%) does not meet global threshold (100%)
ERROR: Coverage for branches (0%) does not meet global threshold (100%)
ERROR: Coverage for statements (0%) does not meet global threshold (100%)
--------------------------|---------|----------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------File                      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------All files                 |       0 |        0 |       0 |       0 |
 mqtt                     |       0 |      100 |     100 |       0 |
  index.js                |       0 |      100 |     100 |       0 | 13
 mqtt/src                 |       0 |        0 |       0 |       0 |
  mqtt_base.ts            |       0 |        0 |       0 |       0 | ...,68,73,75,79-81,83,85,86,91,97,103,106,109,114,115,118,125-131,133,134,139,144,145,151,156,159,160,164,169,170,173,178,179,182,187,188,191,196,197,199,200,207,212,226-228,231,232,237-240,242-244,247-251,255-261,265-270,272-274,276-278,280,285,287
  mqtt_translate_error.ts |       0 |        0 |       0 |       0 | 6,33,34,37-39,42,43,45,46,48,49,51,52,54,55,57,58,60,61,63,64,66,67,69,72,76,79,80
--------------------------|---------|----------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------npm ERR! code ELIFECYCLE

Now I remove the extends line:

  "nyc": {
    "all": true,
    "check-coverage": true,
    "statements": 100,
    "lines": 100,
    "functions": 100,
    "branches": 100
  },

And running the same command I get:

  88 passing (213ms)

ERROR: Coverage for lines (96.86%) does not meet global threshold (100%)
ERROR: Coverage for functions (91.3%) does not meet global threshold (100%)
ERROR: Coverage for branches (97.14%) does not meet global threshold (100%)
ERROR: Coverage for statements (96.95%) does not meet global threshold (100%)
--------------------------|---------|----------|---------|---------|-------------------
File                      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|-------------------
All files                 |   96.95 |    97.14 |    91.3 |   96.86 |
 mqtt                     |       0 |      100 |     100 |       0 |
  index.js                |       0 |      100 |     100 |       0 | 13
 mqtt/src                 |   97.55 |    97.14 |    91.3 |   97.47 |
  mqtt_base.ts            |   96.85 |    95.65 |   90.91 |   96.77 | 73,75,118,139
  mqtt_translate_error.ts |     100 |      100 |     100 |     100 |
--------------------------|---------|----------|---------|---------|-------------------

AKA, coverage is working. What's the issue here?

The code I'm testing is from the following: https://github.com/Azure/azure-iot-sdk-node/tree/master/common/transport/mqtt

@Uzlopak
Copy link

Uzlopak commented May 15, 2020

I have the same the same issue. Very strange. When i use @istanbuljs/nyc-config-typescript with version ^0.1.3 then i have no issue.

@Uzlopak
Copy link

Uzlopak commented May 15, 2020

probable fix is #518

@Raag007
Copy link

Raag007 commented Oct 3, 2020

Hello, is there any update on this issue? We are seeing the same issue (0% coverage) when we add extends to the nyc config file.

Thanks in Advance.

@Uzlopak
Copy link

Uzlopak commented Oct 3, 2020

@Raag007
We just stay at version 0.1.3

@Raag007
Copy link

Raag007 commented Oct 4, 2020

Hello,
I added version @istanbuljs/nyc-config-typescript@^0.1.3 package and added extends to nyc config file. But, results are not accurate.

Results without extends.

`File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 4.6 0 3.03 4.6
dist/out/src 0 0 0 0
index.ts 0 0 0 0
src 4.6 0 3.03 4.6
ConsoleLogger.ts 0 0 0 0 3-83
ErrorData.ts 0 0 0 0 9-66
EventName.ts 100 100 100 100
LogData.ts 0 0 0 0 10-26
NullLogger.ts 0 100 0 0 14
ProxyLogger.ts 0 100 0 0 15-100
TelemetryLogger.ts 0 0 0 0 99-274
UserContext.ts 0 0 0 0 8-34
index.ts 0 0 0 0 `

Results with extends.

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 18.12 10.53 11.86 17.52
dist/out/src 0 0 0 0
index.ts 0 0 0 0
dist/out/src/test 0 100 0 0
Telemetry.tests.ts 0 100 0 0 6-11
src 4.6 0 3.03 4.6
ConsoleLogger.ts 0 0 0 0 3-83
ErrorData.ts 0 0 0 0 9-66
EventName.ts 100 100 100 100
LogData.ts 0 0 0 0 10-26
NullLogger.ts 0 100 0 0 14
ProxyLogger.ts 0 100 0 0 15-100
TelemetryLogger.ts 0 0 0 0 99-274
UserContext.ts 0 0 0 0 8-34
index.ts 0 0 0 0
src/test 46.67 30.77 25 45.45
AssertLogger.ts 0 0 0 0 12-116
SourceMaps.build.tests.ts 87.5 66.67 85.71 86.96 20,28,41
Telemetry.tests.ts 0 100 0 0 6-11`

Do you know why we have to use this package and why it changes the behavior of nyc code coverage?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants