always result in unknown coverage report when using nyc
ruiming opened this issue · 4 comments
After writing test, I use below two script to start my test:
"test1": "nyc mocha --compilers ts:espower-typescript/guess 'test/*.ts' --require source-map-support/register --timeout=10000",
"test2": "nyc mocha --require ts-node/register 'test/*.ts' --require source-map-support/register --timeout=10000"
My test file did not includes power-assert in order to make test2
works.
Both of the two script works well with all test passed. However, test1
will always result in unknown coverage report while test2
work as expected with generating correct coverage report.
@teppeis I had created a repo: https://github.com/ruiming/nyc_test
@teppeis I also have same problem at https://github.com/Narazaka/routes-generator.js/tree/nyc (nyc branch).
It seems to be problem of path resolving.
nyc mocha
succeeds in both --compilers ts:ts-node-register
and --compilers ts:espower-typescript/guess
, but in the latter, coverage html says "no such file or directory, open 'D:\make\devel\lib\routes-generator.ts'" and lcov.info says SF:D:\make\devel\lib\routes-generator.ts
.
The real path is not D:\make\devel\lib\routes-generator.ts
but D:\make\devel\routes-generator\lib\routes-generator.ts
.
espower-typescript seems to make project root path '/path/to/project' to '/path/to'.
The full error in html:
Unable to lookup source: D:\make\devel\lib\routes-generator.ts(ENOENT: no such file or directory, open 'D:\make\devel\lib\routes-generator.ts') Error: Unable to lookup source: D:\make\devel\lib\routes-generator.ts(ENOENT: no such file or directory, open 'D:\make\devel\lib\routes-generator.ts') at Context.defaultSourceLookup [as sourceFinder] (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\context.js:15:15) at Context.getSource (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\context.js:74:17) at Object.annotateSourceCode (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-reports\lib\html\annotator.js:172:38) at HtmlReport.onDetail (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-reports\lib\html\index.js:217:39) at Visitor.(anonymous function) [as onDetail] (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\tree.js:34:30) at ReportNode.Node.visit (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\tree.js:123:17) at D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\tree.js:116:23 at Array.forEach (native) at visitChildren (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\tree.js:115:32) at ReportNode.Node.visit (D:\make\devel\routes-generator\node_modules\nyc\node_modules\istanbul-lib-report\lib\tree.js:126:5)
Fixed by adding sourceRoot
option to compilerOptions
in tsconfig.json.