Skip to content

Tests are passing but coverage is zero #2104

@hamzahamidi

Description

@hamzahamidi
Contributor

🐛 Bug Report

I'm developing a small library ( just an index.ts and index.spec.ts for tests) and apparently jest is ignoring the coverage from index.ts although the tests are passing!
image

To Reproduce

Steps to reproduce the behavior:

npm init
npm i -D webpack webpack-cli @webpack-cli/init

Init the project with default typescript settings:

webpack init
npm i -D jest typescript  ts-jest @types/jest
npx ts-jest config:init
npm run test -- --collect-coverage

This the structure of the project:

image

jest.config:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'jsdom',
  roots: [
    "<rootDir>/src"
  ]
};

Expected behavior

Collect coverage

Link to repo (highly encouraged)

Debug log:

# content of ts-jest.log :

envinfo

System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    Node: 12.18.1 - ~/.nvm/versions/node/v12.18.1/bin/node

Npm packages:
    jest: 26.6.1
    ts-jest: 26.4.3
    typescript: 4.0.5
    "@babel/core": "^7.12.3",
    "@babel/preset-env": "^7.12.1",
    "@types/jest": "^26.0.15",

Activity

hamzahamidi

hamzahamidi commented on Nov 4, 2020

@hamzahamidi
ContributorAuthor

I was able to solve this by changing the name of the file (index.ts)

ahnpnl

ahnpnl commented on Nov 4, 2020

@ahnpnl
Collaborator

Duplicate with #2090

You need to clear jest cache first before running the tests.

added and removed
Needs RepoNeed a minimium repository to reproduce the problem
on Nov 4, 2020
added a commit that references this issue on Nov 8, 2020
dee8231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @hamzahamidi@ahnpnl

      Issue actions

        Tests are passing but coverage is zero · Issue #2104 · kulshekhar/ts-jest