kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
https://kulshekhar.github.io/ts-jest
MIT License
6.95k stars 451 forks source link

ts-jest fails to work with TS 3.7.2 #1288

Closed MichalLytek closed 4 years ago

MichalLytek commented 4 years ago

Issue :

When I've updated my deps, the tests stopped working. I have a custom monorepo setup with TS references, Jest projects and ttypescript compiler to rewrite @paths on compile.

 FAIL  packages/core/tests/functional/bar.ts
  ● Test suite failed to run

    Cannot find module '@typegraphql/core' from 'bar.ts'  

    > 1 | import { bar } from "@typegraphql/core";        
        | ^
      2 | 
      3 | describe("bar", () => {
      4 |   it("should return 'bar'", () => {

      at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:259:17)

When I've downgraded the TS deps to 3.6.3, it works as earlier:

 PASS  tests/functional/bar.ts
 PASS  tests/functional/foo.ts

Test Suites: 2 passed, 2 total
Tests:       2 passed, 2 total

I've created two branches that you can checkout and reproduce: https://github.com/MichalLytek/type-graphql/tree/ts-jest-3.7.2 https://github.com/MichalLytek/type-graphql/tree/ts-jest-3.6.3

Expected behavior :

It should work as before upgrade.

Minimal repo :

https://github.com/MichalLytek/type-graphql/tree/ts-jest-3.7.2 https://github.com/MichalLytek/type-graphql/tree/ts-jest-3.6.3

git clone
npm i (on root folder)
npm run bootstrap
cd packages/core
npx jest --watch
jasonkuhrt commented 4 years ago

Hey @MichalLytek :)

I'm hitting a similar-seeming issue. In my project I do not have this error in VSCode, just from ts-jest.

image

But It might not be related as I downgraded to 3.6 and still have this error. My case doesn't seem to be tied to 3.7.

MichalLytek commented 4 years ago

I think we can close the issue now - ts-jest v24.2.0 works for me with TS v3.7.3 😉

ahnpnl commented 4 years ago

Thanks, this is strange. Perhaps that is the error of ts < 3.7.3 ?

ChrisLahaye commented 4 years ago

@MichalLytek Can you try removing your lock file and run yarn install again. Jest released a minor upgrade from 24.8.0 to 24.9.0 which breaks ts-jest for me. What about you?

MichalLytek commented 4 years ago

@ChrisLahaye I've removed the lock, bootstraped the monorepo, everything works ok 💪

"ts-jest": "^24.2.0",
"typescript": "~3.7.3",
"jest": "^24.9.0",
frck006 commented 4 years ago

Hi, I have always the problem:

image

Here, my tsconfig:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "lib": [
      "esnext",
      "esnext.asynciterable",
      "dom"
    ],
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noImplicitAny": false,
    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "~/*": [
        "./*"
      ],
      "@/*": [
        "./*"
      ]
    },
    "types": [
      "@types/node",
      "@types/jest",
      "@nuxt/types", 
      "@nuxtjs/vuetify"
    ]
  },
  "include": ["**/*.ts", "**/*.vue"],
  "exclude": [
    "node_modules",
  ]  
  // "files": ["ts-shim.d.ts"]
}

jest.config:

const config = {
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js'
  },
  // preset: 'ts-jest',
  // testEnvironment: 'node',
  // modulePathIgnorePatterns: ['<rootDir>/cypress/'],
  moduleFileExtensions: ['js', 'json', 'ts', 'vue'],
  transform: { // The order is important. Vue must comme first.
    // '^.+\\.js$': 'babel-jest',
    // process TypeScript files
    '^.+\\.ts$': 'ts-jest',
    // process *.vue files with vue-jest
    '.*\\.(vue)$': 'vue-jest'
  },
  // verbose: true,
  testMatch: [
    '**/test/**/*.spec.+(ts|tsx|js)'
  ],
  testPathIgnorePatterns: [
    '<rootDir>/node_modules/',
    '<rootDir>/components/example/',
    '<rootDir>/cypress/'
  ],
  transformIgnorePatterns: ['<rootDir>/node_modules/'],
  // serializer for snapshots
  snapshotSerializers: [
    'jest-serializer-vue'
  ]
}
module.export = config

Package.json:

  "devDependencies": {
    "@babel/core": "^7.7.7",
    "@babel/preset-env": "^7.7.7",
    "@babel/preset-typescript": "^7.8.3",
    "@mdi/font": "^4.7.95",
    "@nuxt/typescript-build": "^0.5.5",
    "@nuxt/typescript-runtime": "^0.3.6",
    "@nuxtjs/auth": "^4.8.5",
    "@nuxtjs/axios": "^5.9.2",
    "@nuxtjs/eslint-config-typescript": "^1.0.0",
    "@nuxtjs/proxy": "^1.3.3",
    "@nuxtjs/pwa": "^3.0.0-beta.19",
    "@nuxtjs/vuetify": "^1.9.1",
    "@types/jest": "^24.0.25",
    "@types/lodash.overargs": "^4.7.6",
    "@vue/test-utils": "^1.0.0-beta.30",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^24.9.0",
    "cross-env": "^6.0.3",
    "cypress": "^3.8.1",
    "cypress-jest-adapter": "^0.1.1",
    "eslint": "^6.8.0",
    "eslint-loader": "^3.0.3",
    "eslint-plugin-cypress": "^2.8.1",
    "eslint-plugin-jest": "^23.3.0",
    "eslint-plugin-json": "^2.0.1",
    "eslint-plugin-nuxt": "^0.5.0",
    "eslint-plugin-vue": "^6.1.2",
    "eslint-plugin-vuetify": "^1.0.0-beta.5",
    "intro.js": "^2.9.3",
    "jest": "^24.9.0",
    "jest-serializer-vue": "^2.0.2",
    "loadash": "^1.0.0",
    "npm-check-updates": "^4.0.1",
    "nuxt": "^2.11.0",
    "nuxt-env": "^0.1.0",
    "nuxt-property-decorator": "^2.5.0",
    "sass": "^1.24.1",
    "sass-loader": "^8.0.0",
    "ts-jest": "^24.3.0",
    "ts-node": "^8.5.4",
    "typedoc": "^0.15.6",
    "vue-eslint-parser": "^7.0.0",
    "vue-grid-layout": "^2.3.7",
    "vue-i18n": "^8.15.3",
    "vue-jest": "^3.0.5",
    "vue-json-component": "^0.3.0",
    "vue-meta": "^2.3.1",
    "vue-property-decorator": "^8.3.0",
    "vuedraggable": "^2.23.2",
    "vuetify": "2.1.15",
    "vuetify-toast-snackbar": "^0.6.1",
    "vuex-class": "^0.3.2",
    "vuex-persistedstate": "^2.7.0"
  }
ahnpnl commented 4 years ago

please do these following steps: