I'd like to run our tests on multiple versions of React in CI, if we can.
--prefix config option that we can use to change (I believe) the location where it looks for package.json and node_modules.So we may be able to use these 2 features in combination to do something like this in our Travis config:
env:
- NPM_PREFIX=react-15
- NPM_PREFIX=react-16
install:
- npm install --prefix=$NPM_PREFIX
It seems a little hacky, and there would probably be some bugs to work out. But it might work.
We've got this set up on React Redux if you want to steal some ideas: https://github.com/reduxjs/react-redux/tree/master/test @cellog set it up for us.
Ah, I see. Instead of using a build matrix you copy all of the source files into a dir with a package.json that specifies the version of React you want to test against. That's a great approach, and doesn't feel quite as hacky. It also seems like it'd be a little more portable if we decide to switch to yarn in the future instead of npm.
Quick chime in: this was the only way I found to do it that didn't have the npm equivalent of dll hell. If the way you implement it is similar, let me know, I would be willing to abstract that into an external package for testing against multiple versions of external deps
I got a quick start on this in the multi-versions branch, but nowhere near finished yet. The basic idea was to install different versions of React + their dependencies in the /react directory, then use a REACT_VERSION environment variable in the Jest config to setup modulePaths to find React in the right place.
This approach required me to remove react and react-dom from each dir in packages because Jest gives precedence to the local node_modules dir. This caused a few other things to break.
I wonder if there's a good way to tell Jest to search modulePaths before the local node_modules. That would be great in this case.
I resolved it using yarn with jest:
Dang, this is a bit late.
But here's how I switch between versions for testing:
#!/bin/bash
# ./test.sh
cd ${PROJECT_FOLDER:-./test}
# switch to v15
sed -i -E 's/"react": ".*",/"react": "^15.0.0",/' package.json
npm install
react-scripts test --env=jsdom
# switch to v16.6
sed -i -E 's/"react": ".*",/"react": "16.6.0",/' package.json
npm install
react-scripts test --env=jsdom
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Quick chime in: this was the only way I found to do it that didn't have the npm equivalent of dll hell. If the way you implement it is similar, let me know, I would be willing to abstract that into an external package for testing against multiple versions of external deps