mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-28 17:35:42 +08:00
Add test cases for PUBLIC_URL and relative path (#1519)
* Add test cases to evaluate increased CI time * Add positive test cases * Add negative cases * Test default behavior * Exit on failure * Fix test
This commit is contained in:
@@ -142,6 +142,55 @@ create_react_app --scripts-version=$scripts_path test-app
|
||||
# let's make sure all npm scripts are in the working state.
|
||||
# ******************************************************************************
|
||||
|
||||
function verify_env_url {
|
||||
# Backup package.json because we're going to make it dirty
|
||||
cp package.json package.json.orig
|
||||
|
||||
# Test default behavior
|
||||
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 0 || exit 1
|
||||
|
||||
# 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
|
||||
# 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
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
# Test absolute url build
|
||||
sed "2s/.*/ \"homepage\": \"https:\/\/www.example.net\/testingpath\",/" package.json > tmp && mv tmp package.json
|
||||
|
||||
npm run 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
|
||||
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
|
||||
|
||||
# Restore package.json
|
||||
rm package.json
|
||||
mv package.json.orig package.json
|
||||
}
|
||||
|
||||
# Enter the app directory
|
||||
cd test-app
|
||||
|
||||
@@ -162,6 +211,9 @@ CI=true npm test
|
||||
# Test the server
|
||||
npm start -- --smoke-test
|
||||
|
||||
# Test environment handling
|
||||
verify_env_url
|
||||
|
||||
# ******************************************************************************
|
||||
# Finally, let's check that everything still works after ejecting.
|
||||
# ******************************************************************************
|
||||
@@ -195,6 +247,8 @@ npm test -- --watch=no
|
||||
# Test the server
|
||||
npm start -- --smoke-test
|
||||
|
||||
# Test environment handling
|
||||
verify_env_url
|
||||
|
||||
# Cleanup
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user