'Jest: "Directory in the roots[0] option was not found"
I am trying to set up monorepo to run all of its Jest tests at once. In each package, I'm using react-app-rewired to get Babel to transpile code imported from other packages without ejecting from create-react-app, as described in this article.
react-app-rewired test
succeeds when run from each package folder, but when run from the root folder of the monorepo, I get this error
Directory /Users/Me/go/src/gitlab.com/my-org/front-end/src in the roots[0] option was not found.
There is no src
folder in my front-end
folder (the monorepo root) and I can't figure out why Jest is trying to look there.
I've tried providing rootDir
and roots
in jest.config.js
, but that doesn't seem to make a difference.
How can I get Jest to stop looking for a folder that doesn't exist?
jest.config.js (root):
module.exports = {
rootDir: ["."],
projects: [
"<rootDir>/packages/app",
"<rootDir>/packages/components",
"<rootDir>/packages/utils",
],
};
package.json (root):
{
"name": "root",
"private": true,
"workspaces": [
"packages/*"
],
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
"prettier --write"
]
},
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject",
"prettier": "prettier --check '**/*.js'",
"prettier:fix": "prettier --write '**/*.js'"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
config-overrides.js (root):
const path = require("path");
const { override, babelInclude } = require("customize-cra");
module.exports = function (config, env) {
return Object.assign(
config,
override(
babelInclude([
path.resolve("./packages/app"),
path.resolve("./packages/components"),
path.resolve("./packages/utils"),
])
)(config, env)
);
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|