vscode-jest does not seem to work with ts-jest and transform config for use with TypeScript

Created on 3 Jul 2018  路  9Comments  路  Source: jest-community/vscode-jest

Environment

node -v: 10.5
npm -v: 6.1
VSCode: 1.24.1
Jest: 23.2
ts-jest: 23.0
Operating system: Windows 10 1709

transform config in jest.config.js

    transform: {
        "^.+\\.tsx?$": "ts-jest"
    },
    testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
    moduleFileExtensions: [
        "tsx",
        "ts",
        "js",
        "jsx",
        "json",
        "node"
    ],

Most helpful comment

In my case using it with craco, "jest.pathToJest": "npm run test --" worked

All 9 comments

please provide more info:

  • what is your jest.pathToJest and jest.pathToConfig settings?
  • what is your jest or react-script version
  • please elaborate "does not work"
  • It is recommended to provide a simple sample repo so it will be easier for us to diagnose your problem
  • I have not configured jest.pathToJest and jest.pathToConfig specifically.
  • not a react context at all
  • Jest version updated above
  • "does not work" refers to the extension running Jest in a way that it complains about all the "import" statements in the sources. This would not happen if the transform config as mentioned above would be used.

Is the extension _supposed_ to handle TypeScript projects? This might be a missing feature and not a bug.

  • yes, it should be able to handle typescript projects.
  • For the plugin to use your config, you will have to specify it in jest.pathToConfig.
  • Also, there is a jest 23.x compatibility issue right now (see #341), you will most likely have to downgrade to 22.x until next vscode-jest release.
  • great news :-)
  • I'll try that out
  • and that as well :-)

Thanks!

@connectdotz I would assume for the standard case that would be just
pathToConfig: "<rootDir>/tsconfig.json" ? thx

@connectdotz I don't get it to work. also, even in the 22 version of Jest I can't find the pathToConfig option in the docs. is this not supposed to go into jest.config.js ? thank you.

@marcelh-gh

  • yes if your config is in jest.config.js and it is in root directory then you don't need to specify jest.pathToConfig.
  • you might need to set jest.pathToJest to help the plugin find your jest binary if your environment is not "typical"... is this the multi-root project you referred in #342? then you will most likely have to specify both settings
  • how do you run jest test on command line? from where you run it?
  • these settings are vscode-jest settings, not jest, and they should be specified in .vscode/settings.json. You can use relative path, but not token.
  • anyway, as you can see there could be many things, this kind of back and forth is really inefficient... I don't mind taking a closer look if you can take the time to create a sample repo.

vscode-jest 2.9.0 has shipped with jest 23.x support and more, which should address this issue. Feel free to reopen if otherwise.

In my case using it with craco, "jest.pathToJest": "npm run test --" worked

Was this page helpful?
0 / 5 - 0 ratings