Adding tests to CRA example yields an error
akutruff opened this issue · 6 comments
When trying to setup CRA example for tests, I set package.json
to:
"scripts": {
"start": "cross-env SKIP_PREFLIGHT_CHECK=true craco start",
"build": "cross-env SKIP_PREFLIGHT_CHECK=true craco build",
"test": "cross-env SKIP_PREFLIGHT_CHECK=true craco test"
},
I also added the jest.config.ts
to the directory and added jest dependencies.
Edit: in general, adding tests to a project where the tests and the projects live in the same directory is causing issues. I added a basic TypeScript library with jest tests and those break under GitHub CI.
I get the following failure when trying to run the tests.
node ➜ /workspaces/mono-repo-test/examples/cra (master ✗) $ yarn test
yarn run v1.22.15
$ cross-env SKIP_PREFLIGHT_CHECK=true craco test
The following changes are being made to your tsconfig.json file:
- compilerOptions.paths must not be set (aliased imports are not supported)
● Validation Error:
Watch plugin jest-watch-typeahead/filename cannot be found. Make sure the watchPlugins configuration option points to an existing node module.
Configuration Documentation:
https://jestjs.io/docs/configuration.html
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Hey @akutruff, this looks like facebook/create-react-app#11043.
I also added the jest.config.ts to the directory and added jest dependencies.
With CRA you shouldn't have to manually add jest
— react-scripts test
(or in this case craco test
) should come with everything you need.
FWIW, everything is working fine for me locally. Maybe run yarn why jest-watch-typeahead
to see where the dependency the error complains about is located in the monorepo. This is what I get:
❯ yarn why jest-watch-typeahead
yarn why v1.22.0
[1/4] Why do we have the module "jest-watch-typeahead"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "jest-watch-typeahead@0.6.1"
info Reasons this module exists
- "_project_#@nighttrax#cra-example#react-scripts" depends on it
- Hoisted from "_project_#@nighttrax#cra-example#react-scripts#jest-watch-typeahead"
Thanks for looking into this and the repo.
package.json
has yarn run build
for the test script which doesn't execute tests, it just builds it right?
"scripts": {
"start": "cross-env SKIP_PREFLIGHT_CHECK=true craco start",
"build": "cross-env SKIP_PREFLIGHT_CHECK=true craco build",
"test": "yarn run build"
},
@akutruff yes, all of the test
scripts here just build the respective package because that's the main objective of this repo - building packages in a monorepo. The jest example covers running actual tests in a monorepo.
P.S.: the script name is test
because it's run in CI and building is what I'm testing for. I should change this because it is confusing...
I tried to take this as far as I could, but I still can't get the Button component to resolve. The jest module resolver customization isn't making sense to me unfortunately.