coverage results for typescript are non-deterministic
See original GitHub issueLink to bug demonstration repository
demo repo: https://github.com/Kosta-Github/ts-nyc-issue
the typescript setup described in nyc-config-typescript has been followed
Expected Behavior
running one of the 2 provided test scripts several times should always result in the same (correct) output/result
Observed Behavior
Sometimes the result looks like this and the generated HTML coverage report looks OK:
-------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------|----------|----------|----------|----------|-------------------|
All files | 80 | 50 | 66.67 | 80 | |
func.ts | 83.33 | 50 | 100 | 83.33 | 8 |
nested_1.ts | 100 | 100 | 100 | 100 | |
nested_2.ts | 50 | 100 | 0 | 50 | 2 |
-------------|----------|----------|----------|----------|-------------------|
=============================== Coverage summary ===============================
Statements : 80% ( 8/10 )
Branches : 50% ( 1/2 )
Functions : 66.67% ( 2/3 )
Lines : 80% ( 8/10 )
================================================================================
And sometimes the result looks like this:
-------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-------------|----------|----------|----------|----------|-------------------|
All files | 40 | 50 | 66.67 | 80 | |
func.ts | 50 | 50 | 100 | 100 | 5 |
nested_1.ts | 50 | 100 | 100 | 100 | |
nested_2.ts | 0 | 100 | 0 | 0 | 2 |
-------------|----------|----------|----------|----------|-------------------|
=============================== Coverage summary ===============================
Statements : 40% ( 4/10 )
Branches : 50% ( 1/2 )
Functions : 66.67% ( 2/3 )
Lines : 80% ( 4/5 )
================================================================================
And in this case the generated HTML files contain this error message:
Cannot read property 'start' of undefined
TypeError: Cannot read property 'start' of undefined
at Object.keys.forEach.stName (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-reports/lib/html/annotator.js:53:31)
at Array.forEach ()
at annotateStatements (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-reports/lib/html/annotator.js:49:33)
at Object.annotateSourceCode (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-reports/lib/html/annotator.js:239:9)
at HtmlReport.onDetail (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-reports/lib/html/index.js:265:27)
at LcovReport.(anonymous function) [as onDetail] (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-reports/lib/lcov/index.js:23:23)
at Visitor.(anonymous function) [as onDetail] (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-lib-report/lib/tree.js:34:30)
at ReportNode.Node.visit (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-lib-report/lib/tree.js:114:17)
at getChildren.forEach.child (/Users/kosta/devel/misc/ts-nyc-issue/node_modules/istanbul-lib-report/lib/tree.js:118:15)
at Array.forEach ()
Troubleshooting steps
- still occurring when I put
cache: falsein my nyc config
Environment Information
$ npx envinfo@latest --preset nyc
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Memory: 1.20 GB / 16.00 GB
Binaries:
Node: 10.16.0 - /usr/local/opt/node@10/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.10.1 - /usr/local/opt/node@10/bin/npm
npmPackages:
nyc: ^14.1.1 => 14.1.1
ts-node: ^8.3.0 => 8.3.0
typescript: ^3.5.3 => 3.5.3
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:19 (8 by maintainers)
Top Results From Across the Web
TypeScript is a waste of time. Change my mind.
A discussion on whether using TypeScript is overrated. ... To report results that generalize to the population of public bugs, ...
Read more >Writing unit tests in TypeScript - Chirag Rupani - Medium
We are using 'node' in 'testEnvironment' since we are executing tests on Node (which makes it faster), else we would be using default...
Read more >typescript-coverage-report - npm
Node command tool to generate TypeScript coverage report.. Latest version: 0.7.0, last published: a month ago.
Read more >Automatically Assessing and Extending Code Coverage for ...
code coverage while minimizing the total test execution time. Our evaluation results show that TESA can increase the num-.
Read more >10 Insights from Adopting TypeScript at Scale | Bloomberg LP
Tests can be written in TypeScript and code coverage is accurately expressed in terms of the original TypeScript code. It just works.
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

Yes
I believe to use
"all": trueyou need to configure therequireoptions on nyc instead of mocha. TBH I have not downloaded your repository I’m busy currently but this looks like something I’ve seen with babel transpilation.CC @JaKXz my knowledge of TS is very limited but I think this might be an issue where the instrumentation for
nyc --allis not being processed by ts-node/register where the instrumentation for files required by actual tests is being processed by ts-node/register, causing a mismatch.