question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrading to 27 breaks coverage with ts-jest preset

See original GitHub issue

🐛 Bug Report

This issue is a follow-up to the kulshekhar/ts-jest#2790

Recently I’ve upgraded to jest: 27.0.6 and ts-jest: 27.0.4 and discovered that test runs with --coverage fail because of syntax errors. Downgrading to jest: 26.6.3 and ts-jest: 26.5.6 fixes the issue. Regular test runs without coverage collection work good in both versions. It looks like jest --coverage ignores preset and tries to use babel. image

To Reproduce

Run jest --coverage in a typescript project using ts-jest preset

Here is my jest config:

jest.config.js

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  coverageThreshold: {
    global: {
      lines: 90,
      statements: 90,
      functions: 90,
      branches: 70,
    },
  },
  testMatch: ['**/*.test.ts'],
  setupFilesAfterEnv: ['./tests/jest.setup.ts'],
  collectCoverageFrom: [
    `**/src/**/*.ts`,
    `!**/src/server.ts`,
    `!**/src/gracefulShutdown.ts`,
  ],
  coverageReporters: ['text', 'cobertura'],
};
and package.json

{
  "name": "name",
  "version": "1.0.0",
  "description": "description",
  "engines": {
    "node": "^14.15.0"
  },
  "scripts": {
    "prestart": "yarn build",
    "start": "node ./dist/src/server.js",
    "start:dev": "nodemon ./src/server.ts",
    "build": "tsc",
    "lint": "eslint --quiet .",
    "test": "jest",
    "test:ci": "yarn test --coverage --reporters=default --reporters=jest-junit"
  },
  "keywords": [],
  "author": "misha@fibery.io",
  "license": "ISC",
  "private": true,
  "dependencies": {
    "date-fns": "2.23.0",
    "dotenv": "10.0.0",
    "envalid": "7.1.1",
    "got": "11.8.2"
  },
  "devDependencies": {
    "@types/jest": "26.0.24",
    "@types/node": "16.4.7",
    "@typescript-eslint/eslint-plugin": "4.28.5",
    "@typescript-eslint/parser": "4.28.5",
    "eslint": "7.31.0",
    "eslint-config-prettier": "8.3.0",
    "eslint-plugin-jest": "24.4.0",
    "eslint-plugin-node": "11.1.0",
    "husky": "4.3.8",
    "jest": "27.0.6",
    "jest-junit": "12.2.0",
    "lint-staged": ">=11.0.0",
    "nock": "13.1.1",
    "prettier": "2.3.2",
    "ts-jest": "27.0.4",
    "ts-node": "10.1.0",
    "typescript": "4.3.5"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{ts,js}": "eslint --cache --fix",
    "*.{ts,js,css,md}": "prettier --write"
  }
}

Expected behavior

Coverage collection should not throw syntax errors

Link to repl or repo (highly encouraged)

envinfo

System:
    OS: macOS 11.2.3
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.20.2 - /usr/local/bin/npm

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ahnpnlcommented, Sep 9, 2021

it is because the value for collectCoverageFrom is wrong. If I put

 "collectCoverageFrom": [
    "<rootDir>/**/*.{js,jsx,ts,tsx}"
  ],

will also work.

1reaction
ahnpnlcommented, Sep 9, 2021

hmm we did change the construction of cache key in v27 for ts-jest comparing to v26, that is the only change which is related to code coverage IMO. The repo from @MikeYermolayev I cannot reproduce the issue.

The repo from @TrejGun needs to remove the collectCoverageFrom in jest config to make it work. I think he specified the wrong collectCoverageFrom value, which isn’t related to ts-jest

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest 27: New Defaults for Jest, 2021 edition
This gives us the opportunity to remove some packages from the default distribution of Jest 28 and publish them as separately installable and ......
Read more >
From v27 to v28
Upgrading Jest from v27 to v28? This guide aims to help refactoring your configuration and tests.
Read more >
Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... Jest ships with two coverage providers: babel (default) and v8 .
Read more >
Jest 25: 🚀 Laying foundations for the future
Jest 25 is laying the groundwork for many major changes in the future. As such, we kept breaking changes to a minimum, but...
Read more >
Jest 28: Shedding weight and improving compatibility
Hopefully this makes the upgrade experience as frictionless as possible! Main breaking changes likely to impact your migration are dropped ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found