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

can't find source file when use istanbul to report TypeScript coverage #92

Closed
LiJinyao opened this issue Jul 10, 2017 · 2 comments
Closed

Comments

@LiJinyao
Copy link

LiJinyao commented Jul 10, 2017

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?

@twada
Copy link
Member

twada commented Jul 10, 2017

@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?

@LiJinyao
Copy link
Author

@twada Thanks! I get coverage work by adding "sourceRoot": "."

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

2 participants