Skip to content

Commit be99114

Browse files
committed
Separate appDir tests.
1 parent add1f41 commit be99114

File tree

5 files changed

+156
-119
lines changed

5 files changed

+156
-119
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
const moduleExports = {
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
},
7+
experimental: {
8+
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
9+
},
10+
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
11+
sentry: {
12+
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
13+
// TODO (v8): This can come out in v8, because this option will get a default value
14+
hideSourceMaps: false,
15+
excludeServerRoutes: ['/api/excludedEndpoints/excludedWithString', /\/api\/excludedEndpoints\/excludedWithRegExp/],
16+
},
17+
};
18+
19+
const SentryWebpackPluginOptions = {
20+
dryRun: true,
21+
silent: true,
22+
};
23+
24+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
25+

packages/nextjs/test/integration/next13.config.template

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ const moduleExports = {
44
eslint: {
55
ignoreDuringBuilds: true,
66
},
7-
experimental: {
8-
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later.
9-
},
107
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'],
118
sentry: {
129
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts`
@@ -22,3 +19,4 @@ const SentryWebpackPluginOptions = {
2219
};
2320

2421
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
22+

packages/nextjs/test/integration/test/client/appDirTracingPageloadClientcomponent.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { test, expect } from '@playwright/test';
44
test('should create a pageload transaction when the `app` directory is used with a client component.', async ({
55
page,
66
}) => {
7-
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
8-
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
7+
if (process.env.USE_APPDIR !== 'true') {
98
return;
109
}
1110

packages/nextjs/test/integration/test/client/appDirTracingPageloadServercomponent.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { test, expect } from '@playwright/test';
44
test('should create a pageload transaction when the `app` directory is used with a server component.', async ({
55
page,
66
}) => {
7-
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) {
8-
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later.
7+
if (process.env.USE_APPDIR !== 'true') {
98
return;
109
}
1110

packages/nextjs/test/run-integration-tests.sh

Lines changed: 128 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -31,133 +31,149 @@ echo "Running integration tests on Node $NODE_VERSION"
3131
# make a backup of our config file so we can restore it when we're done
3232
mv next.config.js next.config.js.bak
3333

34-
for NEXTJS_VERSION in 10 11 12 13; do
35-
36-
# export this to the env so that we can behave differently depending on which version of next we're testing, without
37-
# having to pass this value from function to function to function to the one spot, deep in some callstack, where we
38-
# actually need it
39-
export NEXTJS_VERSION=$NEXTJS_VERSION
40-
export NODE_MAJOR=$NODE_MAJOR
41-
42-
# Next 10 requires at least Node v10
43-
if [ "$NODE_MAJOR" -lt "10" ]; then
44-
echo "[nextjs] Next.js is not compatible with versions of Node older than v10. Current version $NODE_VERSION"
45-
exit 0
46-
fi
47-
48-
# Next.js v11 requires at least Node v12
49-
if [ "$NODE_MAJOR" -lt "12" ] && [ "$NEXTJS_VERSION" -ge "11" ]; then
50-
echo "[nextjs@$NEXTJS_VERSION] Not compatible with Node $NODE_MAJOR"
51-
exit 0
52-
fi
53-
54-
# Next.js v13 requires at least Node v14
55-
if [ "$NODE_MAJOR" -lt "14" ] && [ "$NEXTJS_VERSION" -ge "13" ]; then
56-
echo "[nextjs@$NEXTJS_VERSION] Not compatible with Node $NODE_MAJOR"
57-
exit 0
58-
fi
59-
60-
echo "[nextjs@$NEXTJS_VERSION] Preparing environment..."
61-
rm -rf node_modules .next .env.local 2>/dev/null || true
62-
63-
echo "[nextjs@$NEXTJS_VERSION] Installing dependencies..."
64-
# set the desired version of next long enough to run yarn, and then restore the old version (doing the restoration now
65-
# rather than during overall cleanup lets us look for "latest" in every loop)
66-
cp package.json package.json.bak
67-
if [[ $(uname) == "Darwin" ]]; then
68-
sed -i "" /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
69-
else
70-
sed -i /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
71-
fi
72-
73-
# Next.js v13 requires React 18.2.0
74-
if [ "$NEXTJS_VERSION" -eq "13" ]; then
75-
76-
fi
77-
# We have to use `--ignore-engines` because sucrase claims to need Node 12, even though tests pass just fine on Node
78-
# 10
79-
yarn --no-lockfile --ignore-engines --silent >/dev/null 2>&1
80-
# if applicable, use local versions of `@sentry/cli` and/or `@sentry/webpack-plugin` (these commands no-op unless
81-
# LINKED_CLI_REPO and/or LINKED_PLUGIN_REPO are set)
82-
linkcli && linkplugin
83-
mv -f package.json.bak package.json 2>/dev/null || true
84-
85-
SHOULD_RUN_WEBPACK_5=(true)
86-
# Only run Webpack 4 tests for Next 10 and Next 11
87-
if [ "$NEXTJS_VERSION" -eq "10" ] || [ "$NEXTJS_VERSION" -eq "11" ]; then
88-
SHOULD_RUN_WEBPACK_5+=(false)
89-
fi
90-
91-
for RUN_WEBPACK_5 in ${SHOULD_RUN_WEBPACK_5[*]}; do
92-
[ "$RUN_WEBPACK_5" == true ] &&
93-
WEBPACK_VERSION=5 ||
94-
WEBPACK_VERSION=4
95-
96-
if [ "$NODE_MAJOR" -gt "17" ]; then
97-
# Node v17+ does not work with NextJS 10 and 11 because of their legacy openssl use
98-
# Ref: https://github.com/vercel/next.js/issues/30078
99-
if [ "$NEXTJS_VERSION" -lt "12" ]; then
100-
echo "[nextjs@$NEXTJS_VERSION Node $NODE_MAJOR not compatible with NextJS $NEXTJS_VERSION"
101-
# Continues the 2nd enclosing loop, which is the outer loop that iterates over the NextJS version
102-
continue 2
103-
fi
34+
# for NEXTJS_VERSION in 10 11 12 13; do
35+
for NEXTJS_VERSION in 13; do
36+
for USE_APPDIR in true false; do
37+
if ([ "$NEXTJS_VERSION" -lt "13" ] || [ "$NODE_MAJOR" -lt "16" ]) && [ "$USE_APPDIR" == true ]; then
38+
# Next.js < 13 do not support appDir
39+
continue
40+
fi
10441

105-
# Node v18 only with Webpack 5 and above
106-
# https://github.com/webpack/webpack/issues/14532#issuecomment-947513562
107-
# Context: https://github.com/vercel/next.js/issues/30078#issuecomment-947338268
108-
if [ "$WEBPACK_VERSION" -eq "4" ]; then
109-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Node $NODE_MAJOR not compatible with Webpack $WEBPACK_VERSION"
110-
# Continues the 1st enclosing loop, which is the inner loop that iterates over the Webpack version
111-
continue
112-
fi
42+
# export this to the env so that we can behave differently depending on which version of next we're testing, without
43+
# having to pass this value from function to function to function to the one spot, deep in some callstack, where we
44+
# actually need it
45+
export NEXTJS_VERSION=$NEXTJS_VERSION
46+
export NODE_MAJOR=$NODE_MAJOR
47+
export USE_APPDIR=$USE_APPDIR
48+
49+
# Next 10 requires at least Node v10
50+
if [ "$NODE_MAJOR" -lt "10" ]; then
51+
echo "[nextjs] Next.js is not compatible with versions of Node older than v10. Current version $NODE_VERSION"
52+
exit 0
53+
fi
11354

55+
# Next.js v11 requires at least Node v12
56+
if [ "$NODE_MAJOR" -lt "12" ] && [ "$NEXTJS_VERSION" -ge "11" ]; then
57+
echo "[nextjs@$NEXTJS_VERSION] Not compatible with Node $NODE_MAJOR"
58+
exit 0
11459
fi
11560

116-
# next 10 defaults to webpack 4 and next 11 defaults to webpack 5, but each can use either based on settings
117-
if [ "$NEXTJS_VERSION" -eq "10" ]; then
118-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next10.config.template >next.config.js
119-
elif [ "$NEXTJS_VERSION" -eq "11" ]; then
120-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next11.config.template >next.config.js
121-
elif [ "$NEXTJS_VERSION" -eq "12" ]; then
122-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next12.config.template >next.config.js
123-
elif [ "$NEXTJS_VERSION" -eq "13" ]; then
124-
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.config.template >next.config.js
61+
# Next.js v13 requires at least Node v14
62+
if [ "$NODE_MAJOR" -lt "14" ] && [ "$NEXTJS_VERSION" -ge "13" ]; then
63+
echo "[nextjs@$NEXTJS_VERSION] Not compatible with Node $NODE_MAJOR"
64+
exit 0
12565
fi
12666

127-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."
128-
yarn build
67+
echo "[nextjs@$NEXTJS_VERSION] Preparing environment..."
68+
rm -rf node_modules .next .env.local 2>/dev/null || true
12969

130-
# if the user hasn't passed any args, use the default one, which restricts each test to only outputting success and
131-
# failure messages
132-
args=$*
133-
if [[ ! $args ]]; then
134-
args="--silent"
70+
echo "[nextjs@$NEXTJS_VERSION] Installing dependencies..."
71+
# set the desired version of next long enough to run yarn, and then restore the old version (doing the restoration now
72+
# rather than during overall cleanup lets us look for "latest" in every loop)
73+
cp package.json package.json.bak
74+
if [[ $(uname) == "Darwin" ]]; then
75+
sed -i "" /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
76+
else
77+
sed -i /"next.*latest"/s/latest/"${NEXTJS_VERSION}.x"/ package.json
13578
fi
13679

137-
# we keep this updated as we run the tests, so that if it's ever non-zero, we can bail
138-
EXIT_CODE=0
80+
# Next.js v13 requires React 18.2.0
81+
if [ "$NEXTJS_VERSION" -eq "13" ]; then
82+
83+
fi
84+
# We have to use `--ignore-engines` because sucrase claims to need Node 12, even though tests pass just fine on Node
85+
# 10
86+
yarn --no-lockfile --ignore-engines --silent >/dev/null 2>&1
87+
# if applicable, use local versions of `@sentry/cli` and/or `@sentry/webpack-plugin` (these commands no-op unless
88+
# LINKED_CLI_REPO and/or LINKED_PLUGIN_REPO are set)
89+
linkcli && linkplugin
90+
mv -f package.json.bak package.json 2>/dev/null || true
91+
92+
SHOULD_RUN_WEBPACK_5=(true)
93+
# Only run Webpack 4 tests for Next 10 and Next 11
94+
if [ "$NEXTJS_VERSION" -eq "10" ] || [ "$NEXTJS_VERSION" -eq "11" ]; then
95+
SHOULD_RUN_WEBPACK_5+=(false)
96+
fi
13997

140-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running server tests with options: $args"
141-
(cd .. && yarn test:integration:server) || EXIT_CODE=$?
98+
for RUN_WEBPACK_5 in ${SHOULD_RUN_WEBPACK_5[*]}; do
99+
[ "$RUN_WEBPACK_5" == true ] &&
100+
WEBPACK_VERSION=5 ||
101+
WEBPACK_VERSION=4
102+
103+
if [ "$NODE_MAJOR" -gt "17" ]; then
104+
# Node v17+ does not work with NextJS 10 and 11 because of their legacy openssl use
105+
# Ref: https://github.com/vercel/next.js/issues/30078
106+
if [ "$NEXTJS_VERSION" -lt "12" ]; then
107+
echo "[nextjs@$NEXTJS_VERSION Node $NODE_MAJOR not compatible with NextJS $NEXTJS_VERSION"
108+
# Continues the 2nd enclosing loop, which is the outer loop that iterates over the NextJS version
109+
continue 2
110+
fi
111+
112+
# Node v18 only with Webpack 5 and above
113+
# https://github.com/webpack/webpack/issues/14532#issuecomment-947513562
114+
# Context: https://github.com/vercel/next.js/issues/30078#issuecomment-947338268
115+
if [ "$WEBPACK_VERSION" -eq "4" ]; then
116+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Node $NODE_MAJOR not compatible with Webpack $WEBPACK_VERSION"
117+
# Continues the 1st enclosing loop, which is the inner loop that iterates over the Webpack version
118+
continue
119+
fi
142120

143-
if [ $EXIT_CODE -eq 0 ]; then
144-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed"
145-
else
146-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests failed"
147-
exit 1
148-
fi
121+
fi
122+
123+
# next 10 defaults to webpack 4 and next 11 defaults to webpack 5, but each can use either based on settings
124+
if [ "$NEXTJS_VERSION" -eq "10" ]; then
125+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next10.config.template >next.config.js
126+
elif [ "$NEXTJS_VERSION" -eq "11" ]; then
127+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next11.config.template >next.config.js
128+
elif [ "$NEXTJS_VERSION" -eq "12" ]; then
129+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next12.config.template >next.config.js
130+
elif [ "$NEXTJS_VERSION" -eq "13" ]; then
131+
if [ "$USE_APPDIR" == true ]; then
132+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.appdir.config.template >next.config.js
133+
else
134+
sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" <next13.config.template >next.config.js
135+
fi
136+
fi
137+
138+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..."
139+
yarn build
140+
141+
# if the user hasn't passed any args, use the default one, which restricts each test to only outputting success and
142+
# failure messages
143+
args=$*
144+
if [[ ! $args ]]; then
145+
args="--silent"
146+
fi
147+
148+
# we keep this updated as we run the tests, so that if it's ever non-zero, we can bail
149+
EXIT_CODE=0
150+
151+
if [ "$USE_APPDIR" == true ]; then
152+
echo "Skipping server tests for appdir"
153+
else
154+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running server tests with options: $args"
155+
(cd .. && yarn test:integration:server) || EXIT_CODE=$?
156+
fi
149157

150-
if [ "$NODE_MAJOR" -lt "14" ]; then
151-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Skipping client tests on Node $NODE_MAJOR"
152-
else
153-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running client tests with options: $args"
154-
(cd .. && yarn test:integration:client) || EXIT_CODE=$?
155158
if [ $EXIT_CODE -eq 0 ]; then
156-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests passed"
159+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed"
157160
else
158-
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests failed"
161+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests failed"
159162
exit 1
160163
fi
161-
fi
164+
165+
if [ "$NODE_MAJOR" -lt "14" ]; then
166+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Skipping client tests on Node $NODE_MAJOR"
167+
else
168+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Running client tests with options: $args"
169+
(cd .. && yarn test:integration:client) || EXIT_CODE=$?
170+
if [ $EXIT_CODE -eq 0 ]; then
171+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests passed"
172+
else
173+
echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Client integration tests failed"
174+
exit 1
175+
fi
176+
fi
177+
done
162178
done
163179
done

0 commit comments

Comments
 (0)