I am trying to setup test environment for a react project written in typescript. I have done it before for react but with ES6.
Following is how the relevant parts of my package.json look like -
"scripts": {
"test": "NODE_ENV=test jest",
"build": "webpack --mode production",
"start": "webpack-dev-server --open --mode development"
},
"jest": {
"moduleNameMapper": {
"\\.(css)$": "jest-css-modules"
},
"transform": {
"\\.(ts|tsx)$": "ts-jest"
},
"testRegex": ".test.(ts|tsx?)$",
"moduleFileExensions": ["ts", "tsx", "js", "jsx", "json", "node"]
},
I would like to mention that I am counting on ts transpiler and not configured babel at all.
Following are the dependencies I have included -
"dependencies": {
"@types/jest": "^23.1.4",
"@types/react": "^16.4.5",
"@types/react-dom": "^16.0.6",
"@types/react-redux": "^6.0.3",
"@types/redux": "^3.6.0",
"deep-freeze": "0.0.1",
"jest": "^23.2.0",
"jest-css-modules": "^1.1.0",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"ts-jest": "^23.0.0",
"webpack": "^4.12.2"
},
"devDependencies": {
"awesome-typescript-loader": "^5.2.0",
"css-loader": "^0.28.11",
"html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"style-loader": "^0.21.0",
"typescript": "^2.9.2",
"typings-for-css-modules-loader": "^1.7.0",
"url-loader": "^1.0.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4"
}
I am unable to understand following error when I run npm run test
as I have already installed and specified ts-jest in transform -
Validation Error:
Module ts-jest in the transform option was not found.
<rootDir> is: /Users/rahul/ot/Lab/webpack-playlist
Following is how tsconfig.json looks like
{
"compilerOptions": {
"jsx": "react",
"noImplicitAny": true,
"sourceMap": true,
"target": "es5"
}
}
Not sure how I can I resolve the error above.
I also tried configuring ts-jest in tsconfig.json like below but it still gave same error -
// tsconfig.json
"jest": {
"globals": {
"ts-jest": {
"tsConfigFile": "tsconfig.jest.json"
}
}
}
// tsconfig.jest.json
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "commonjs"
}
}