ava-ts icon indicating copy to clipboard operation
ava-ts copied to clipboard

Coverage with NYC

Open wbhob opened this issue 7 years ago • 10 comments

I deleted the template because I have a simple question: how do I output coverage with ava-ts?

wbhob avatar Jan 25 '18 02:01 wbhob

Hey @wbhob. Excellent point...

I played around and tried a bunch of stuff, but the bad news is I am currently not able to get working coverage reports either 😕

Some of the code transparently added by TypeScript or NYC just crashs with TypeError: Promise resolver undefined is not a function.

So this is an unsolved issue as of now.

andywer avatar Jan 26 '18 09:01 andywer

I got this working! Here's my .nycrc

{
  "extension": [
    ".ts",
    ".tsx"
  ],
  "include": ["src/**/*.ts"],
  "reporter": [
    "text",
    "html"
  ],
  "cache": true,
  "sourceMap": false,
  "instrument": false
}

Then I run

nyc ava-ts tests/ --verbose

I haven't had any issues with this method whatsoever. :)

jack-guy avatar Jan 28 '18 03:01 jack-guy

Thanks for sharing, @harangue! :)

Runs without crashing for me, too, but I don't get any coverage in my test project... (Source files are matched by src/**/*.ts in my project as well)

bildschirmfoto 2018-01-28 um 10 35 02

andywer avatar Jan 28 '18 09:01 andywer

Yeah @andywer, it seems I spoke too soon. I got it to run test coverage for all of my files once, somehow, but never again after that. I've been looking at this blog post to try to uncover what's wrong but I'm afraid I don't understand all of the mechanics of how ava reports to instanbul.

jack-guy avatar Jan 28 '18 16:01 jack-guy

Hmm, here's my nyc config now:

{
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "**/*.d.ts"
    ],
    "extension": [
      ".ts"
    ],
    "require": [
      "ts-node/register"
    ],
    "reporter": [
      "html",
      "text"
    ],
    "sourceMap": false,
    "instrument": true,
    "all": true
}

This seems to find all of my files (the require option is necessary in addition to the all key), but does not register my coverage for any except one of the files.

jack-guy avatar Jan 28 '18 16:01 jack-guy

in my case NYC is ignoring the coverage from tests

$ nyc ava-ts tests --verbose

  √ OptionalMap.ts » Set value adds an entry
  √ OptionalMap.ts » Initializer adds entries
  √ OptionalMap.ts » Get valid optionals
  √ OptionalMap.ts » Setting values increments the size
  √ OptionalMap.ts » Clear method removes entries
  √ OptionalMap.ts » Delete drops entry
  √ OptionalMap.ts » Entries iterator
  √ OptionalMap.ts » Values iterator
  √ OptionalMap.ts » Keys iterator
  √ OptionalMap.ts » For each iterator
  √ Optional.ts » If value is present
  √ Optional.ts » Unsafe get value
  √ Optional.ts » Safe get orElse value
  √ Optional.ts » Throw exception on no value
  √ Optional.ts » Safe get callback

  15 tests passed

----------|----------|----------|----------|----------|-------------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files |        0 |        0 |        0 |        0 |                   |
----------|----------|----------|----------|----------|-------------------|
Done in 14.63s.

sigmasoldi3r avatar Aug 05 '18 10:08 sigmasoldi3r

@sigmasoldi3r Ava supports .ts files now (and coverage reports are working for me too).

jack-guy avatar Aug 19 '18 00:08 jack-guy

@jack-guy yes but if you are using babel 7 + typescript then you are still tends on ava-ts. I didn't find different solution. Can you be more explicit about support of ts files?

creaux avatar Nov 20 '18 07:11 creaux

When I exclude:

"exclude": [
      "**/*.d.ts"
    ],

I am seeing this error:

TSError: ⨯ Unable to compile TypeScript
src/app.ts (84,29): Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

dougmolineux avatar Dec 18 '18 18:12 dougmolineux

@dougmolineux Still hard to tell if this has to do with AVA-TS or just TypeScript... Are you talking about an exclude in the tsconfig.json or in the ava config in the package.json?

andywer avatar Dec 19 '18 03:12 andywer