Skip to content

Jest coverage collection is not working with TypeScript files #1870

@Kocal

Description

@Kocal

Version

3.0.0-rc.3

Reproduction link

https://github.com/Kocal/vue-cli-no-coverage-on-typescript-files/commits/master

Steps to reproduce

Project creation

  • Run vue ui
  • Create a new project
  • Presets: Manual
  • Check Babel, TypeScript, and Unit Testing
  • Pick a linter / formatter config: ESLint Prettier (it's probably unrelated, but this is what I chose)
  • Pick a unit testing solution: Jest
  • Create project
  • Continue without saving

Post-project creation

  • Enable Jest coverage collection from package.json: jest.collectCoverage: true
  • Create a file src/divider.ts containing export const divide = (a: number, b: number) => a / b;
  • Create a spec file tests/unit/divider.spec.ts containg test('divide', () => { expect(divide(5, 2)).toEqual(2.5) });
  • Run yarn test:unit or yarn test:unit --no-cache

And under your eyes, you will see that coverage from src/divider.ts is not collected.

What is expected?

Coverage from TypeScript files should be collected.

What is actually happening?

I investigate and this is what I found.
It really seems to be that when a file is written in TypeScript, its code coverage won't be collected.

service written in... test written in... coverage collected?
substracter TypeScript TypeScript  No
divider TypeScript JavaScript  No
multiplier JavaScript  TypeScript Yes

Here is a Travis build that show Coverage state.

I'm a bit afraid because I'm actually migrating an app which uses vuejs-templates/pwa to @vue/cli 3, but I literally lost all the code coverage... 😢


Something strange too, code coverage from .vue files is not collected. 🤔
Here is another Travis build that ran just after:

  • enable code coverage collection
  • use babel-jest for handling .js files, but it's not related I think

Thanks for your help (also you all did a great job on @vue/cli and vue ui! 🙂), do not hesitate to ask me for more info/context!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions