I am using Babel Jest to transpile my code for testing purposes. I can't get how to use path relative to the project root.
For example, if in a test file I import a module with: /imports/ui/myModule
Jest throws an error
Cannot find module
'/Users/me/dev/myProject/Users/me/dev/myProject/imports/ui/myModule' from 'test.jsx'`
But if I import a module with a relative path like: ../../ui/myModule
it works.
My .babelrc
:
{
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"babel-root-slash-import"
],
"presets": [
"es2015",
"react",
"stage-0"
],
"env": {
"test": {
"plugins": [
"transform-decorators-legacy",
"transform-class-properties",
"babel-root-slash-import"
],
"presets": [
"es2015",
"react",
"stage-0"
]
}
}
}
My Jest config is:
"jest": {
"roots": ["<rootDir>/imports/tests/jest"]
},