can't find source file when use istanbul to report TypeScript coverage
LiJinyao opened this issue · 2 comments
Step to reproduce the bug
platform: windwos 7
I have created an repo to reproduce this bug: https://github.com/LiJinyao/bug-power-assert
Bug
I want use Mocha, power-assert in my TypeScript project, when I use Chai, istanbul could generate Coverage HTML report, when I switch to power-assert, istanbul could only report coverage but cant generate HTML report with same config and exit with error. And if there is an error in test, the mocha will also broke.
It sames a path issue in power-assert.
I use nyc to report the coverage.
Is there anyone have experience to set up a TypeScript test environment?
@LiJinyao Thank you for reporting, and creating repro case.
I git-cloned your repo and saw coverage report causes an error as you reported.
I think it's nothing to do with power-assert since your product code (App.ts
) is not transpiled with espower-typescript (it only affects to test files).
The"file not found" error seems to be caused by paths in sourcemaps that are not absolute.
We can fix it by adding sourceRoot
to sourcemap producer, in this case TypeScript compiler.
diff --git a/tsconfig.json b/tsconfig.json
index 1ee04e1..2ef99ca 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -4,6 +4,7 @@
"module": "commonjs",
"allowJs": true,
"sourceMap": true,
+ "sourceRoot": ".",
"outDir": "build",
"moduleResolution": "Node",
"lib": ["es6", "dom"]
This patch works for me (MacOS, Node8).
Would you try this patch?