Skip to content

Commit b9d679a

Browse files
Timergaearon
authored andcommitted
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
1 parent ac39a46 commit b9d679a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tasks/e2e-simple.sh

+54
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,55 @@ create_react_app --scripts-version=$scripts_path test-app
142142
# let's make sure all npm scripts are in the working state.
143143
# ******************************************************************************
144144

145+
function verify_env_url {
146+
# Backup package.json because we're going to make it dirty
147+
cp package.json package.json.orig
148+
149+
# Test default behavior
150+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 0 || exit 1
151+
152+
# Test relative path build
153+
awk -v n=2 -v s=" \"homepage\": \".\"," 'NR == n {print s} {print}' package.json > tmp && mv tmp package.json
154+
155+
npm run build
156+
# Disabled until this can be tested
157+
# grep -F -R --exclude=*.map "../../static/" build/ -q; test $? -eq 0 || exit 1
158+
grep -F -R --exclude=*.map "\"./static/" build/ -q; test $? -eq 0 || exit 1
159+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
160+
161+
PUBLIC_URL="/anabsolute" npm run build
162+
grep -F -R --exclude=*.map "/anabsolute/static/" build/ -q; test $? -eq 0 || exit 1
163+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
164+
165+
# Test absolute path build
166+
sed "2s/.*/ \"homepage\": \"\/testingpath\",/" package.json > tmp && mv tmp package.json
167+
168+
npm run build
169+
grep -F -R --exclude=*.map "/testingpath/static/" build/ -q; test $? -eq 0 || exit 1
170+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
171+
172+
PUBLIC_URL="https://www.example.net/overridetest" npm run build
173+
grep -F -R --exclude=*.map "https://www.example.net/overridetest/static/" build/ -q; test $? -eq 0 || exit 1
174+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
175+
grep -F -R --exclude=*.map "testingpath/static" build/ -q; test $? -eq 1 || exit 1
176+
177+
# Test absolute url build
178+
sed "2s/.*/ \"homepage\": \"https:\/\/www.example.net\/testingpath\",/" package.json > tmp && mv tmp package.json
179+
180+
npm run build
181+
grep -F -R --exclude=*.map "/testingpath/static/" build/ -q; test $? -eq 0 || exit 1
182+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
183+
184+
PUBLIC_URL="https://www.example.net/overridetest" npm run build
185+
grep -F -R --exclude=*.map "https://www.example.net/overridetest/static/" build/ -q; test $? -eq 0 || exit 1
186+
grep -F -R --exclude=*.map "\"/static/" build/ -q; test $? -eq 1 || exit 1
187+
grep -F -R --exclude=*.map "testingpath/static" build/ -q; test $? -eq 1 || exit 1
188+
189+
# Restore package.json
190+
rm package.json
191+
mv package.json.orig package.json
192+
}
193+
145194
# Enter the app directory
146195
cd test-app
147196

@@ -162,6 +211,9 @@ CI=true npm test
162211
# Test the server
163212
npm start -- --smoke-test
164213

214+
# Test environment handling
215+
verify_env_url
216+
165217
# ******************************************************************************
166218
# Finally, let's check that everything still works after ejecting.
167219
# ******************************************************************************
@@ -195,6 +247,8 @@ npm test -- --watch=no
195247
# Test the server
196248
npm start -- --smoke-test
197249

250+
# Test environment handling
251+
verify_env_url
198252

199253
# Cleanup
200254
cleanup

0 commit comments

Comments
 (0)