-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathrun-integration-tests.sh
executable file
·150 lines (122 loc) · 5.88 KB
/
run-integration-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
source test/integration_test_utils.sh
set -e
START_TIME=$(date -R)
function cleanup {
echo "[nextjs] Cleaning up..."
mv next.config.js.bak next.config.js 2>/dev/null || true
rm -rf node_modules 2>/dev/null || true
# Delete yarn's cached versions of sentry packages added during this test run, since every test run installs multiple
# copies of each package. Without this, the cache can balloon in size quickly if integration tests are being run
# multiple times in a row.
find "$(yarn cache dir)" -iname "npm-@sentry*" -newermt "$START_TIME" -mindepth 1 -maxdepth 1 -exec rm -rf {} \;
echo "[nextjs] Test run complete"
}
trap cleanup EXIT
cd "$(dirname "$0")/integration"
NODE_VERSION=$(node -v)
NODE_MAJOR=$(echo "$NODE_VERSION" | cut -c2- | cut -d. -f1)
echo "Running integration tests on Node $NODE_VERSION"
# make a backup of our config file so we can restore it when we're done
mv next.config.js next.config.js.bak
for NEXTJS_VERSION in 10 11 12 13; do
# export this to the env so that we can behave differently depending on which version of next we're testing, without
# having to pass this value from function to function to function to the one spot, deep in some callstack, where we
# actually need it
export NEXTJS_VERSION=$NEXTJS_VERSION
export NODE_MAJOR=$NODE_MAJOR
# Next 10 requires at least Node v10
if [ "$NODE_MAJOR" -lt "10" ]; then
echo "[nextjs] Next.js is not compatible with versions of Node older than v10. Current version $NODE_VERSION"
exit 0
fi
# Next.js v11 requires at least Node v12
if [ "$NODE_MAJOR" -lt "12" ] && [ "$NEXTJS_VERSION" -ge "11" ]; then
echo "[nextjs@$NEXTJS_VERSION] Not compatible with Node $NODE_MAJOR"
exit 0
fi
# Next.js v13 requires at least Node v14
if [ "$NODE_MAJOR" -lt "14" ] && [ "$NEXTJS_VERSION" -ge "13" ]; then
echo "[nextjs@$NEXTJS_VERSION] Not compatible with Node $NODE_MAJOR"
exit 0
fi
echo "[nextjs@$NEXTJS_VERSION] Preparing environment..."
rm -rf node_modules .next .env.local 2>/dev/null || true
echo "[nextjs@$NEXTJS_VERSION] Installing dependencies..."
# set the desired version of next long enough to run yarn, and then restore the old version (doing the restoration now
# rather than during overall cleanup lets us look for "latest" in every loop)
cp package.json package.json.bak
if [[ $(uname) == "Darwin" ]]; then
sed -i "" /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
else
sed -i /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
fi
# Next.js v13 requires React 18.2.0
if [ "$NEXTJS_VERSION" -eq "13" ]; then
npm i --save [email protected] [email protected]
fi
# We have to use `--ignore-engines` because sucrase claims to need Node 12, even though tests pass just fine on Node
# 10
yarn --no-lockfile --ignore-engines --silent >/dev/null 2>&1
# if applicable, use local versions of `@sentry/cli` and/or `@sentry/webpack-plugin` (these commands no-op unless
# LINKED_CLI_REPO and/or LINKED_PLUGIN_REPO are set)
linkcli && linkplugin
mv -f package.json.bak package.json 2>/dev/null || true
SHOULD_RUN_WEBPACK_5=(true)
# Only run Webpack 4 tests for Next 10 and Next 11
if [ "$NEXTJS_VERSION" -eq "10" ] || [ "$NEXTJS_VERSION" -eq "11" ]; then
SHOULD_RUN_WEBPACK_5+=(false)
fi
for RUN_WEBPACK_5 in ${SHOULD_RUN_WEBPACK_5[*]}; do
[ "$RUN_WEBPACK_5" == true ] &&
WEBPACK_VERSION=5 ||
WEBPACK_VERSION=4
# Node v18 only with Webpack 5 and above
# https://github.com/webpack/webpack/issues/14532#issuecomment-947513562
# Context: https://github.com/vercel/next.js/issues/30078#issuecomment-947338268
if [ "$NODE_MAJOR" -gt "17" ] && [ "$WEBPACK_VERSION" -eq "4" ]; then
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Node $NODE_MAJOR not compatible with Webpack $WEBPACK_VERSION"
exit 0
fi
if [ "$NODE_MAJOR" -gt "17" ] && [ "$NEXTJS_VERSION" -eq "10" ]; then
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Node $NODE_MAJOR not compatible with Webpack $WEBPACK_VERSION"
exit 0
fi
# next 10 defaults to webpack 4 and next 11 defaults to webpack 5, but each can use either based on settings
if [ "$NEXTJS_VERSION" -eq "10" ]; then
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next10.config.template >next.config.js
elif [ "$NEXTJS_VERSION" -eq "11" ]; then
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next11.config.template >next.config.js
elif [ "$NEXTJS_VERSION" -eq "12" ]; then
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next12.config.template >next.config.js
elif [ "$NEXTJS_VERSION" -eq "13" ]; then
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.config.template >next.config.js
fi
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."
yarn build
# if the user hasn't passed any args, use the default one, which restricts each test to only outputting success and
# failure messages
args=$*
if [[ ! $args ]]; then
args="--silent"
fi
# we keep this updated as we run the tests, so that if it's ever non-zero, we can bail
EXIT_CODE=0
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running server tests with options: $args"
node test/server.js $args || EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed"
else
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests failed"
exit 1
fi
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running client tests with options: $args"
node test/client.js $args || EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests passed"
else
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests failed"
exit 1
fi
done
done