Skip to content

Commit 3b9a92d

Browse files
authored
test: Run integration tests for Next 10/11 and Webpack 4/5 matrix (#3741)
test: Run integration tests for Next 10/11 and Webpack 4/5 matrix
1 parent 8161005 commit 3b9a92d

File tree

8 files changed

+120
-9
lines changed

8 files changed

+120
-9
lines changed

packages/nextjs/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@
5555
"test": "run-s test:unit test:integration",
5656
"test:watch": "jest --watch",
5757
"test:unit": "jest",
58-
"test:integration": "run-s test:integration:clean test:integration:build test:integration:server test:integration:client",
59-
"test:integration:clean": "cd test/integration && rimraf node_modules .next .env.local",
60-
"test:integration:build": "cd test/integration && yarn --no-lockfile && yarn build",
61-
"test:integration:server": "cd test/integration && node test/server.js --silent",
62-
"test:integration:client": "cd test/integration && node test/client.js --silent",
58+
"test:integration": "test/run-integration-tests.sh",
6359
"pack": "npm pack",
6460
"vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh",
6561
"vercel:project": "source vercel/make-project-use-current-branch.sh",

packages/nextjs/test/integration/components/Layout.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ const Layout = ({ children, title = 'This is the default title' }: Props) => (
2727
<Link href="/users">
2828
<a>Users List</a>
2929
</Link>{' '}
30-
| <a href="/api/users">Users API</a>
30+
|{' '}
31+
<Link href="/api/users">
32+
<a>Users API</a>
33+
</Link>
3134
</nav>
3235
</header>
3336
{children}
3437
<footer>
3538
<hr />
36-
<span>I'm here to stay (Footer)</span>
39+
<span>Im here to stay (Footer)</span>
3740
</footer>
3841
</div>
3942
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/// <reference types="next" />
22
/// <reference types="next/types/global" />
3+
/// <reference types="next/image-types/global" />

packages/nextjs/test/integration/next.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
const { withSentryConfig } = require('@sentry/nextjs');
22

3-
const moduleExports = {};
3+
const moduleExports = {
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
}
7+
};
48
const SentryWebpackPluginOptions = {
59
dryRun: true,
610
silent: true,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
4+
const moduleExports = {
5+
future: {
6+
webpack5: %RUN_WEBPACK_5%,
7+
},
8+
};
9+
10+
const SentryWebpackPluginOptions = {
11+
dryRun: true,
12+
silent: true,
13+
};
14+
15+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5
4+
const moduleExports = {
5+
webpack5: %RUN_WEBPACK_5%,
6+
eslint: {
7+
ignoreDuringBuilds: true,
8+
},
9+
};
10+
11+
const SentryWebpackPluginOptions = {
12+
dryRun: true,
13+
silent: true,
14+
};
15+
16+
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);

packages/nextjs/test/integration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "with-typescript",
3+
"license": "BSD-3-Clause",
34
"scripts": {
45
"dev": "next",
56
"build": "next build",
67
"start": "next start"
78
},
89
"dependencies": {
910
"@sentry/nextjs": "file:../../",
10-
"next": "10.x",
1111
"react": "^17.0.1",
1212
"react-dom": "^17.0.1"
1313
},
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)