mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
Try to use Yarn in more E2E scripts (#3739)
* Try to use Yarn in more E2E scripts * Keep using npm pack * Maybe this will fix Windows? * Try this
This commit is contained in:
@@ -72,42 +72,17 @@ set -x
|
||||
cd ..
|
||||
root_path=$PWD
|
||||
|
||||
# Clear cache to avoid issues with incorrect packages being used
|
||||
if hash yarnpkg 2>/dev/null
|
||||
then
|
||||
# AppVeyor uses an old version of yarn.
|
||||
# Once updated to 0.24.3 or above, the workaround can be removed
|
||||
# and replaced with `yarnpkg cache clean`
|
||||
# Issues:
|
||||
# https://github.com/yarnpkg/yarn/issues/2591
|
||||
# https://github.com/appveyor/ci/issues/1576
|
||||
# https://github.com/facebookincubator/create-react-app/pull/2400
|
||||
# When removing workaround, you may run into
|
||||
# https://github.com/facebookincubator/create-react-app/issues/2030
|
||||
case "$(uname -s)" in
|
||||
*CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;;
|
||||
*) yarn=yarnpkg;;
|
||||
esac
|
||||
$yarn cache clean
|
||||
fi
|
||||
|
||||
if hash npm 2>/dev/null
|
||||
then
|
||||
npm i -g npm@latest
|
||||
npm cache clean || npm cache verify
|
||||
fi
|
||||
|
||||
# Prevent bootstrap, we only want top-level dependencies
|
||||
cp package.json package.json.bak
|
||||
grep -v "postinstall" package.json > temp && mv temp package.json
|
||||
npm install
|
||||
yarn
|
||||
mv package.json.bak package.json
|
||||
|
||||
# We removed the postinstall, so do it manually
|
||||
node bootstrap.js
|
||||
|
||||
cd packages/react-error-overlay/
|
||||
npm run build:prod
|
||||
yarn run build:prod
|
||||
cd ../..
|
||||
|
||||
# ******************************************************************************
|
||||
@@ -120,7 +95,7 @@ cli_path=$PWD/`npm pack`
|
||||
|
||||
# Install the CLI in a temporary location
|
||||
cd "$temp_cli_path"
|
||||
npm install "$cli_path"
|
||||
yarn add "$cli_path"
|
||||
|
||||
# ******************************************************************************
|
||||
# Test --scripts-version with a version number
|
||||
@@ -222,20 +197,20 @@ cd test-app-nested-paths-t1
|
||||
mkdir -p test-app-nested-paths-t1/aa/bb/cc/dd
|
||||
create_react_app test-app-nested-paths-t1/aa/bb/cc/dd
|
||||
cd test-app-nested-paths-t1/aa/bb/cc/dd
|
||||
npm start -- --smoke-test
|
||||
yarn start --smoke-test
|
||||
|
||||
# Testing a path that does not exist
|
||||
cd "$temp_app_path"
|
||||
create_react_app test-app-nested-paths-t2/aa/bb/cc/dd
|
||||
cd test-app-nested-paths-t2/aa/bb/cc/dd
|
||||
npm start -- --smoke-test
|
||||
yarn start --smoke-test
|
||||
|
||||
# Testing a path that is half exists
|
||||
cd "$temp_app_path"
|
||||
mkdir -p test-app-nested-paths-t3/aa
|
||||
create_react_app test-app-nested-paths-t3/aa/bb/cc/dd
|
||||
cd test-app-nested-paths-t3/aa/bb/cc/dd
|
||||
npm start -- --smoke-test
|
||||
yarn start --smoke-test
|
||||
|
||||
# Cleanup
|
||||
cleanup
|
||||
|
||||
@@ -58,7 +58,7 @@ function install_package {
|
||||
|
||||
# Install `dependencies`
|
||||
cd node_modules/$pkg/
|
||||
npm install --only=production
|
||||
yarn --production
|
||||
# Remove our packages to ensure side-by-side versions are used (which we link)
|
||||
rm -rf node_modules/{babel-preset-react-app,eslint-config-react-app,react-dev-utils,react-error-overlay,react-scripts}
|
||||
cd ../..
|
||||
@@ -84,42 +84,17 @@ set -x
|
||||
cd ..
|
||||
root_path=$PWD
|
||||
|
||||
# Clear cache to avoid issues with incorrect packages being used
|
||||
if hash yarnpkg 2>/dev/null
|
||||
then
|
||||
# AppVeyor uses an old version of yarn.
|
||||
# Once updated to 0.24.3 or above, the workaround can be removed
|
||||
# and replaced with `yarnpkg cache clean`
|
||||
# Issues:
|
||||
# https://github.com/yarnpkg/yarn/issues/2591
|
||||
# https://github.com/appveyor/ci/issues/1576
|
||||
# https://github.com/facebookincubator/create-react-app/pull/2400
|
||||
# When removing workaround, you may run into
|
||||
# https://github.com/facebookincubator/create-react-app/issues/2030
|
||||
case "$(uname -s)" in
|
||||
*CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;;
|
||||
*) yarn=yarnpkg;;
|
||||
esac
|
||||
$yarn cache clean
|
||||
fi
|
||||
|
||||
if hash npm 2>/dev/null
|
||||
then
|
||||
npm i -g npm@latest
|
||||
npm cache clean || npm cache verify
|
||||
fi
|
||||
|
||||
# Prevent bootstrap, we only want top-level dependencies
|
||||
cp package.json package.json.bak
|
||||
grep -v "postinstall" package.json > temp && mv temp package.json
|
||||
npm install
|
||||
yarn
|
||||
mv package.json.bak package.json
|
||||
|
||||
# We removed the postinstall, so do it manually
|
||||
node bootstrap.js
|
||||
|
||||
cd packages/react-error-overlay/
|
||||
npm run build:prod
|
||||
yarn build:prod
|
||||
cd ../..
|
||||
|
||||
# ******************************************************************************
|
||||
@@ -153,7 +128,7 @@ mv package.json.orig package.json
|
||||
|
||||
# Install the CLI in a temporary location
|
||||
cd "$temp_cli_path"
|
||||
npm install "$cli_path"
|
||||
yarn add "$cli_path"
|
||||
|
||||
# Install the app in a temporary location
|
||||
cd $temp_app_path
|
||||
@@ -161,7 +136,7 @@ create_react_app --scripts-version="$scripts_path" --internal-testing-template="
|
||||
|
||||
# Install the test module
|
||||
cd "$temp_module_path"
|
||||
npm install test-integrity@^2.0.1
|
||||
yarn add test-integrity@^2.0.1
|
||||
|
||||
# ******************************************************************************
|
||||
# Now that we used create-react-app to create an app depending on react-scripts,
|
||||
@@ -184,7 +159,7 @@ install_package "$temp_module_path/node_modules/test-integrity"
|
||||
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
NODE_PATH=src \
|
||||
PUBLIC_URL=http://www.example.org/spa/ \
|
||||
npm run build
|
||||
yarn build
|
||||
|
||||
# Check for expected output
|
||||
exists build/*.html
|
||||
@@ -195,14 +170,14 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
CI=true \
|
||||
NODE_PATH=src \
|
||||
NODE_ENV=test \
|
||||
npm test -- --no-cache --testPathPattern=src
|
||||
yarn test --no-cache --testPathPattern=src
|
||||
|
||||
# Test "development" environment
|
||||
tmp_server_log=`mktemp`
|
||||
PORT=3001 \
|
||||
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
NODE_PATH=src \
|
||||
nohup npm start &>$tmp_server_log &
|
||||
nohup yarn start &>$tmp_server_log &
|
||||
grep -q 'You can now view' <(tail -f $tmp_server_log)
|
||||
E2E_URL="http://localhost:3001" \
|
||||
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
@@ -225,14 +200,6 @@ E2E_FILE=./build/index.html \
|
||||
# Eject...
|
||||
echo yes | npm run eject
|
||||
|
||||
# Ensure Yarn is ran after eject; at the time of this commit, we don't run Yarn
|
||||
# after ejecting. Soon, we may only skip Yarn on Windows. Let's try to remove
|
||||
# this in the near future.
|
||||
if hash yarnpkg 2>/dev/null
|
||||
then
|
||||
yarn install --check-files
|
||||
fi
|
||||
|
||||
# ...but still link to the local packages
|
||||
install_package "$root_path"/packages/babel-preset-react-app
|
||||
install_package "$root_path"/packages/eslint-config-react-app
|
||||
@@ -246,7 +213,7 @@ install_package "$temp_module_path/node_modules/test-integrity"
|
||||
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
NODE_PATH=src \
|
||||
PUBLIC_URL=http://www.example.org/spa/ \
|
||||
npm run build
|
||||
yarn build
|
||||
|
||||
# Check for expected output
|
||||
exists build/*.html
|
||||
@@ -257,14 +224,14 @@ REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
CI=true \
|
||||
NODE_PATH=src \
|
||||
NODE_ENV=test \
|
||||
npm test -- --no-cache --testPathPattern=src
|
||||
yarn test --no-cache --testPathPattern=src
|
||||
|
||||
# Test "development" environment
|
||||
tmp_server_log=`mktemp`
|
||||
PORT=3002 \
|
||||
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
NODE_PATH=src \
|
||||
nohup npm start &>$tmp_server_log &
|
||||
nohup yarn start &>$tmp_server_log &
|
||||
grep -q 'You can now view' <(tail -f $tmp_server_log)
|
||||
E2E_URL="http://localhost:3002" \
|
||||
REACT_APP_SHELL_ENV_MESSAGE=fromtheshell \
|
||||
|
||||
@@ -57,7 +57,7 @@ function install_package {
|
||||
|
||||
# Install `dependencies`
|
||||
cd node_modules/$pkg/
|
||||
npm install --only=production
|
||||
yarn --production
|
||||
# Remove our packages to ensure side-by-side versions are used (which we link)
|
||||
rm -rf node_modules/{babel-preset-react-app,eslint-config-react-app,react-dev-utils,react-error-overlay,react-scripts}
|
||||
cd ../..
|
||||
@@ -96,39 +96,15 @@ if [ "$EXPECTED" != "$ACTUAL" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clear cache to avoid issues with incorrect packages being used
|
||||
if hash yarnpkg 2>/dev/null
|
||||
then
|
||||
# AppVeyor uses an old version of yarn.
|
||||
# Once updated to 0.24.3 or above, the workaround can be removed
|
||||
# and replaced with `yarnpkg cache clean`
|
||||
# Issues:
|
||||
# https://github.com/yarnpkg/yarn/issues/2591
|
||||
# https://github.com/appveyor/ci/issues/1576
|
||||
# https://github.com/facebookincubator/create-react-app/pull/2400
|
||||
# When removing workaround, you may run into
|
||||
# https://github.com/facebookincubator/create-react-app/issues/2030
|
||||
case "$(uname -s)" in
|
||||
*CYGWIN*|MSYS*|MINGW*) yarn=yarn.cmd;;
|
||||
*) yarn=yarnpkg;;
|
||||
esac
|
||||
$yarn cache clean
|
||||
fi
|
||||
|
||||
if hash npm 2>/dev/null
|
||||
then
|
||||
npm cache clean || npm cache verify
|
||||
fi
|
||||
|
||||
# Prevent bootstrap, we only want top-level dependencies
|
||||
cp package.json package.json.bak
|
||||
grep -v "postinstall" package.json > temp && mv temp package.json
|
||||
npm install
|
||||
yarn
|
||||
mv package.json.bak package.json
|
||||
|
||||
# We need to install create-react-app deps to test it
|
||||
cd "$root_path"/packages/create-react-app
|
||||
npm install
|
||||
yarn
|
||||
cd "$root_path"
|
||||
|
||||
# If the node version is < 6, the script should just give an error.
|
||||
@@ -153,11 +129,11 @@ node bootstrap.js
|
||||
./node_modules/.bin/eslint --max-warnings 0 packages/react-scripts/
|
||||
cd packages/react-error-overlay/
|
||||
./node_modules/.bin/eslint --max-warnings 0 src/
|
||||
npm test
|
||||
npm run build:prod
|
||||
yarn test
|
||||
yarn build:prod
|
||||
cd ../..
|
||||
cd packages/react-dev-utils/
|
||||
npm test
|
||||
yarn test
|
||||
cd ../..
|
||||
|
||||
# ******************************************************************************
|
||||
@@ -166,7 +142,7 @@ cd ../..
|
||||
# ******************************************************************************
|
||||
|
||||
# Test local build command
|
||||
npm run build
|
||||
yarn build
|
||||
# Check for expected output
|
||||
exists build/*.html
|
||||
exists build/static/js/*.js
|
||||
@@ -175,12 +151,12 @@ exists build/static/media/*.svg
|
||||
exists build/favicon.ico
|
||||
|
||||
# Run tests with CI flag
|
||||
CI=true npm test
|
||||
CI=true yarn test
|
||||
# Uncomment when snapshot testing is enabled by default:
|
||||
# exists template/src/__snapshots__/App.test.js.snap
|
||||
|
||||
# Test local start command
|
||||
npm start -- --smoke-test
|
||||
yarn start --smoke-test
|
||||
|
||||
# ******************************************************************************
|
||||
# Next, pack react-scripts and create-react-app so we can verify they work.
|
||||
@@ -216,10 +192,10 @@ cd "$temp_cli_path"
|
||||
|
||||
# Initialize package.json before installing the CLI because npm will not install
|
||||
# the CLI properly in the temporary location if it is missing.
|
||||
npm init --yes
|
||||
yarn init --yes
|
||||
|
||||
# Now we can install the CLI from the local package.
|
||||
npm install "$cli_path"
|
||||
yarn add "$cli_path"
|
||||
|
||||
# Install the app in a temporary location
|
||||
cd $temp_app_path
|
||||
@@ -240,24 +216,24 @@ function verify_env_url {
|
||||
# Test relative path build
|
||||
awk -v n=2 -v s=" \"homepage\": \".\"," 'NR == n {print s} {print}' package.json > tmp && mv tmp package.json
|
||||
|
||||
npm run build
|
||||
yarn build
|
||||
# Disabled until this can be tested
|
||||
# grep -F -R --exclude=*.map "../../static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"./static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
|
||||
|
||||
PUBLIC_URL="/anabsolute" npm run build
|
||||
PUBLIC_URL="/anabsolute" yarn build
|
||||
grep -F -R --exclude=*.map "/anabsolute/static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
|
||||
|
||||
# Test absolute path build
|
||||
sed "2s/.*/ \"homepage\": \"\/testingpath\",/" package.json > tmp && mv tmp package.json
|
||||
|
||||
npm run build
|
||||
yarn build
|
||||
grep -F -R --exclude=*.map "/testingpath/static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
|
||||
|
||||
PUBLIC_URL="https://www.example.net/overridetest" npm run build
|
||||
PUBLIC_URL="https://www.example.net/overridetest" yarn build
|
||||
grep -F -R --exclude=*.map "https://www.example.net/overridetest/static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
|
||||
grep -F -R --exclude=*.map "testingpath/static" build/ -q; test $? -eq 1 || exit 1
|
||||
@@ -265,11 +241,11 @@ function verify_env_url {
|
||||
# Test absolute url build
|
||||
sed "2s/.*/ \"homepage\": \"https:\/\/www.example.net\/testingpath\",/" package.json > tmp && mv tmp package.json
|
||||
|
||||
npm run build
|
||||
yarn build
|
||||
grep -F -R --exclude=*.map "/testingpath/static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
|
||||
|
||||
PUBLIC_URL="https://www.example.net/overridetest" npm run build
|
||||
PUBLIC_URL="https://www.example.net/overridetest" yarn build
|
||||
grep -F -R --exclude=*.map "https://www.example.net/overridetest/static/" build/ -q; test $? -eq 0 || exit 1
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
|
||||
grep -F -R --exclude=*.map "testingpath/static" build/ -q; test $? -eq 1 || exit 1
|
||||
@@ -290,7 +266,7 @@ function verify_module_scope {
|
||||
echo "import sampleJson from '../sample'" | cat - src/App.js > src/App.js.temp && mv src/App.js.temp src/App.js
|
||||
|
||||
# Make sure the build fails
|
||||
npm run build; test $? -eq 1 || exit 1
|
||||
yarn build; test $? -eq 1 || exit 1
|
||||
# TODO: check for error message
|
||||
|
||||
# Restore App.js
|
||||
@@ -302,7 +278,7 @@ function verify_module_scope {
|
||||
cd test-app
|
||||
|
||||
# Test the build
|
||||
npm run build
|
||||
yarn build
|
||||
# Check for expected output
|
||||
exists build/*.html
|
||||
exists build/static/js/*.js
|
||||
@@ -311,12 +287,12 @@ exists build/static/media/*.svg
|
||||
exists build/favicon.ico
|
||||
|
||||
# Run tests with CI flag
|
||||
CI=true npm test
|
||||
CI=true yarn test
|
||||
# Uncomment when snapshot testing is enabled by default:
|
||||
# exists src/__snapshots__/App.test.js.snap
|
||||
|
||||
# Test the server
|
||||
npm start -- --smoke-test
|
||||
yarn start --smoke-test
|
||||
|
||||
# Test environment handling
|
||||
verify_env_url
|
||||
@@ -331,21 +307,13 @@ verify_module_scope
|
||||
# Eject...
|
||||
echo yes | npm run eject
|
||||
|
||||
# Ensure Yarn is ran after eject; at the time of this commit, we don't run Yarn
|
||||
# after ejecting. Soon, we may only skip Yarn on Windows. Let's try to remove
|
||||
# this in the near future.
|
||||
if hash yarnpkg 2>/dev/null
|
||||
then
|
||||
yarnpkg install --check-files
|
||||
fi
|
||||
|
||||
# ...but still link to the local packages
|
||||
install_package "$root_path"/packages/babel-preset-react-app
|
||||
install_package "$root_path"/packages/eslint-config-react-app
|
||||
install_package "$root_path"/packages/react-dev-utils
|
||||
|
||||
# Test the build
|
||||
npm run build
|
||||
yarn build
|
||||
# Check for expected output
|
||||
exists build/*.html
|
||||
exists build/static/js/*.js
|
||||
@@ -354,15 +322,15 @@ exists build/static/media/*.svg
|
||||
exists build/favicon.ico
|
||||
|
||||
# Run tests, overring the watch option to disable it.
|
||||
# `CI=true npm test` won't work here because `npm test` becomes just `jest`.
|
||||
# `CI=true yarn test` won't work here because `yarn test` becomes just `jest`.
|
||||
# We should either teach Jest to respect CI env variable, or make
|
||||
# `scripts/test.js` survive ejection (right now it doesn't).
|
||||
npm test -- --watch=no
|
||||
yarn test --watch=no
|
||||
# Uncomment when snapshot testing is enabled by default:
|
||||
# exists src/__snapshots__/App.test.js.snap
|
||||
|
||||
# Test the server
|
||||
npm start -- --smoke-test
|
||||
yarn start --smoke-test
|
||||
|
||||
# Test environment handling
|
||||
verify_env_url
|
||||
|
||||
Reference in New Issue
Block a user