Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-jest fails to work with TS 3.7.2 #1288

Closed
MichalLytek opened this issue Nov 10, 2019 · 7 comments
Closed

ts-jest fails to work with TS 3.7.2 #1288

MichalLytek opened this issue Nov 10, 2019 · 7 comments

Comments

@MichalLytek
Copy link

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
Copy link

jasonkuhrt commented Nov 12, 2019

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
Copy link
Author

MichalLytek commented Dec 8, 2019

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

@ahnpnl
Copy link
Collaborator

ahnpnl commented Dec 8, 2019

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

@ChrisLahaye
Copy link

ChrisLahaye commented Dec 11, 2019

@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
Copy link
Author

@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
Copy link

frck006 commented Jan 15, 2020

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
Copy link
Collaborator

ahnpnl commented Jan 15, 2020

please do these following steps:

  • Create a tsconfig.spec.json which extends tsconfig.json
  • Specifying ts-jest config to use that tsconfig.spec.json
  • Add module: commonjs and target: es2020 (don't use target: esnext) to this tsconfig.spec.json.
  • Clear jest cache
  • Rerun tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants