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

Coverage reports don't include TS files unless explicitly compiled #742

Closed
lumaxis opened this issue Dec 8, 2017 · 9 comments
Closed

Coverage reports don't include TS files unless explicitly compiled #742

lumaxis opened this issue Dec 8, 2017 · 9 comments

Comments

@lumaxis
Copy link

lumaxis commented Dec 8, 2017

Expected Behavior

When running nyc with mocha which is using ts-node to transpile TypeScript files on the fly, TypeScript files should be part of the coverage report.

Observed Behavior

nyc is only generating coverage output for the only .js file in my project:

-------------|----------|----------|----------|----------|----------------|
File         |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
-------------|----------|----------|----------|----------|----------------|
All files    |    52.37 |    29.71 |    75.61 |    52.37 |                |
 file.js     |    52.37 |    29.71 |    75.61 |    52.37 |... 759,764,766 |
-------------|----------|----------|----------|----------|----------------|

=============================== Coverage summary ===============================
Statements   : 52.37% ( 210/401 )
Branches     : 29.71% ( 71/239 )
Functions    : 75.61% ( 31/41 )
Lines        : 52.37% ( 210/401 )

It however works when I first manually compile all my files using tsc and then it even shows the actual .ts files, not only the .js files.

Forensic Information

Operating System: macOS 10.13.1
Environment Information: https://gist.github.com/lumaxis/cd33c2bbf98dab6e4f5dcc9ff6bf5984

.nycrc

{
    "all": true,
    "cache": false,
    "exclude": [
        "coverage",
        "**/editor.js",
        "**/gulpfile.js",
        "**/tasks.js",
        "**/test/**",
        "**/*_test.js"
    ],
    "extensions": [
        ".js",
        ".ts"
    ],
    "report-dir": "./coverage",
    "reporter": [
        "cobertura",
        "html",
        "text",
        "text-summary"
    ],
    "temp-directory": "./coverage/.nyc_output"
}

mocha.opts

--exit
--reporter spec
--require dotenv/config
--require ts-node/register
--slow 200
--timeout 4000
@lumaxis
Copy link
Author

lumaxis commented Feb 20, 2018

I think I solved this by reducing the config file to

{
    "cache": true,
    "extensions": [
        ".ts"
    ],
    "report-dir": "./coverage",
    "reporter": [
        "cobertura",
        "html",
        "text",
        "text-summary"
    ],
    "temp-directory": "./coverage/.nyc_output"
}

Especially removing "all": true and "extensions": [ ".js" ] seemed to be important. Not sure why it is mentioned in https://istanbul.js.org/docs/tutorials/typescript/ but it appears I need neither them nor source-map-support/register to get a working mocha & TypeScript setup.

@bcoe
Copy link
Member

bcoe commented Jun 15, 2018

Please see microsoft/TypeScript#24993, I'm interested in overhauling our TypeScript support and would love your feedback and requirements.

@stale
Copy link

stale bot commented Jan 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 6, 2019
@kleinfreund
Copy link

@lumaxis The extension configuration key for nyc is extension, not extensions which is very confusing. Could you update your posts so that other people have a chance to solve this issue, please?

@lumaxis
Copy link
Author

lumaxis commented Jan 28, 2019

@kleinfreund Wow 🤦🏼‍♂️ I never noticed that …
It might be that none of what I wrote above is actually valid anymore of I were to repeat it with the changed object key, so not sure editing my original post is very helpful in that way.
Unfortunately, I don't currently work on a project using istanbul/nyc anymore so I can't easily verify my issue.

@kleinfreund
Copy link

@lumaxis Oh, it is relevant. I need the following in my package.json for nyc to recognize the TypeScript source files I’m testing with ava.

"nyc": {
  "extension": [
    ".ts"
  ]
}

@lumaxis
Copy link
Author

lumaxis commented Jan 28, 2019

Sure, that's still valuable information but I don't think it's wise for me to edit my original post.
If I edit my example, my described results would not reproduce anymore.

@bcoe
Copy link
Member

bcoe commented Jan 28, 2019

@kleinfreund seems like maybe we could add another tutorial to https://istanbul.js.org/ and/or a note in the README about needing to support .ts extensions?

I'd argue this specific issue can be closed though; want to go ahead and open an issue if you think it's worthwhile, or heck, would happily take a pull request.

@bcoe bcoe closed this as completed Jan 28, 2019
@JaKXz
Copy link
Member

JaKXz commented Jan 29, 2019

@lumaxis would you mind trying something like this? istanbuljs/istanbuljs#282

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

No branches or pull requests

4 participants