e2e tests incorrectly caching react-scripts
Created by: ro-savage
This caused me a lot of grief and many many hours of lost time on PR #2285.
Yarn is caching old react-scripts when running the e2e tests, which means old versions are being used during the build process. Fine for CI where each build is on a clean machine but breaks e2e in unforeseen ways on local machines.
This might be related to yarnpkg/yarn/issues/2165
The fix was to yarn clean cache
before running the e2e tests.
One possible solution would be to add
if hash yarnpkg 2>/dev/null
then
yarn cache clean
fi
if hash npm 2>/dev/null
then
npm cache clean
fi
to each of the bash scripts.
Another would be to install using the yarn install --force
which will refetch all the packages. However I think that the install part is coming from within react-scripts
and therefore it would force everyone to install with --force
. I couldn't see an install command inside the bash scripts.
Reproduction
- Clone the create-react-app repo.
npm install
- Run
tasks/e2e-kitchensink.sh
. - Open
e2e-kitchensink.sh
and remove the linerm -rf "$temp_cli_path" "$temp_app_path" "$temp_module_path" || $CI
so that you can keep the folders. - Edit the
description
inpackages/react-scripts/package.json
. - Re-run `tasks/e2e-kitchensink.sh.
- Find the tmp folder the project is made into on the command line
-
cd
to the tmp folder - open up the
package.json
found intest-kitchensink/node_modules/react-scripts
- Check the
description
and see it hasn't changed.
This causes issues because when running e2e-kitchensink.sh
is builds a CRA in a tmp folder. It then runs npm test
internally in this folder.
This runs react-scripts test --env=jsdom
which looks up it's node_modules
to find react-scripts
so that it can run scripts/test.js
. Which is old one, meaning if you edited this file or other related files the e2e will be running the cached version not the newly modified version.