|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +function cleanup { |
| 6 | + echo "[nextjs] Cleaning up..." |
| 7 | + mv next.config.js.bak next.config.js 2> /dev/null || true |
| 8 | + yarn remove next > /dev/null 2>&1 || true |
| 9 | + echo "[nextjs] Test run complete" |
| 10 | +} |
| 11 | + |
| 12 | +trap cleanup EXIT |
| 13 | + |
| 14 | +cd "$(dirname "$0")/integration" |
| 15 | + |
| 16 | +for NEXTJS_VERSION in 10 11; do |
| 17 | + NODE_VERSION=$(node -v) |
| 18 | + NODE_MAJOR=$(echo "$NODE_VERSION" | cut -c2- | cut -d. -f1) |
| 19 | + |
| 20 | + # Next 10 requires at least Node v10 |
| 21 | + if [ "$NODE_MAJOR" -lt "10" ]; then |
| 22 | + echo "[nextjs] Next.js is not compatible with versions of Node older than v10. Current version $NODE_VERSION" |
| 23 | + exit 0 |
| 24 | + fi |
| 25 | + |
| 26 | + # Next.js v11 requires at least Node v12 |
| 27 | + if [ "$NODE_MAJOR" -lt "12" ] && [ "$NEXTJS_VERSION" -eq "10" ]; then |
| 28 | + echo "[nextjs$NEXTJS_VERSION] Not compatible with Node $NODE_VERSION" |
| 29 | + exit 0 |
| 30 | + fi |
| 31 | + |
| 32 | + echo "[nextjs@$NEXTJS_VERSION] Running integration tests on $NODE_VERSION" |
| 33 | + |
| 34 | + echo "[nextjs@$NEXTJS_VERSION] Preparing environment..." |
| 35 | + mv next.config.js next.config.js.bak |
| 36 | + rm -rf node_modules .next .env.local 2> /dev/null || true |
| 37 | + |
| 38 | + echo "[nextjs@$NEXTJS_VERSION] Installing dependencies..." |
| 39 | + yarn --no-lockfile --silent > /dev/null 2>&1 |
| 40 | + yarn add "next@$NEXTJS_VERSION" > /dev/null 2>&1 |
| 41 | + |
| 42 | + for RUN_WEBPACK_5 in false true; do |
| 43 | + [ "$RUN_WEBPACK_5" == true ] && |
| 44 | + WEBPACK_VERSION=5 || |
| 45 | + WEBPACK_VERSION=4 |
| 46 | + |
| 47 | + if [ "$NEXTJS_VERSION" -eq "10" ]; then |
| 48 | + sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" < next10.config.template > next.config.js |
| 49 | + else |
| 50 | + sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" < next11.config.template > next.config.js |
| 51 | + fi |
| 52 | + |
| 53 | + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..." |
| 54 | + yarn build | grep "Using webpack" |
| 55 | + |
| 56 | + EXIT_CODE=0 |
| 57 | + node test/server.js --silent || EXIT_CODE=$? |
| 58 | + if [ $EXIT_CODE -eq 0 ] |
| 59 | + then |
| 60 | + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed" |
| 61 | + else |
| 62 | + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests failed" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + EXIT_CODE=0 |
| 67 | + node test/client.js --silent || EXIT_CODE=$? |
| 68 | + if [ $EXIT_CODE -eq 0 ] |
| 69 | + then |
| 70 | + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests passed" |
| 71 | + else |
| 72 | + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests failed" |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | + done |
| 76 | +done; |
0 commit comments