From 6a109029e1238d7b6561b0a1ef6b59643cfe5048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Wed, 23 Jun 2021 17:52:52 +0200 Subject: [PATCH 1/4] test: Add Next 11 to integration tests --- packages/nextjs/package.json | 6 +--- packages/nextjs/test/integration/.eslintrc | 4 +++ .../test/integration/components/Layout.tsx | 7 ++-- .../nextjs/test/integration/next-env.d.ts | 1 + packages/nextjs/test/integration/package.json | 2 +- packages/nextjs/test/run-integration-tests.sh | 36 +++++++++++++++++++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 packages/nextjs/test/integration/.eslintrc create mode 100755 packages/nextjs/test/run-integration-tests.sh diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index c774dcd92cfe..0bda85daffc5 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -55,11 +55,7 @@ "test": "run-s test:unit test:integration", "test:watch": "jest --watch", "test:unit": "jest", - "test:integration": "run-s test:integration:clean test:integration:build test:integration:server test:integration:client", - "test:integration:clean": "cd test/integration && rimraf node_modules .next .env.local", - "test:integration:build": "cd test/integration && yarn --no-lockfile && yarn build", - "test:integration:server": "cd test/integration && node test/server.js --silent", - "test:integration:client": "cd test/integration && node test/client.js --silent", + "test:integration": "test/run-integration-tests.sh", "pack": "npm pack", "vercel:branch": "source vercel/set-up-branch-for-test-app-use.sh", "vercel:project": "source vercel/make-project-use-current-branch.sh", diff --git a/packages/nextjs/test/integration/.eslintrc b/packages/nextjs/test/integration/.eslintrc new file mode 100644 index 000000000000..c3796c8047dd --- /dev/null +++ b/packages/nextjs/test/integration/.eslintrc @@ -0,0 +1,4 @@ +{ + "root": true, + "extends": "next" +} diff --git a/packages/nextjs/test/integration/components/Layout.tsx b/packages/nextjs/test/integration/components/Layout.tsx index 2258a320b804..e7c168830ccb 100644 --- a/packages/nextjs/test/integration/components/Layout.tsx +++ b/packages/nextjs/test/integration/components/Layout.tsx @@ -27,13 +27,16 @@ const Layout = ({ children, title = 'This is the default title' }: Props) => ( Users List {' '} - | Users API + |{' '} + + Users API + {children} ); diff --git a/packages/nextjs/test/integration/next-env.d.ts b/packages/nextjs/test/integration/next-env.d.ts index 7b7aa2c7727d..c6643fda12ff 100644 --- a/packages/nextjs/test/integration/next-env.d.ts +++ b/packages/nextjs/test/integration/next-env.d.ts @@ -1,2 +1,3 @@ /// /// +/// diff --git a/packages/nextjs/test/integration/package.json b/packages/nextjs/test/integration/package.json index 95e2604e01b5..4fceff5c8d0c 100644 --- a/packages/nextjs/test/integration/package.json +++ b/packages/nextjs/test/integration/package.json @@ -7,7 +7,6 @@ }, "dependencies": { "@sentry/nextjs": "file:../../", - "next": "10.x", "react": "^17.0.1", "react-dom": "^17.0.1" }, @@ -16,6 +15,7 @@ "@types/puppeteer": "^5.4.3", "@types/react": "^17.0.6", "@types/react-dom": "^17.0.5", + "eslint-config-next": "^11.0.1", "nock": "^13.1.0", "puppeteer": "^9.1.1", "typescript": "^4.2.4", diff --git a/packages/nextjs/test/run-integration-tests.sh b/packages/nextjs/test/run-integration-tests.sh new file mode 100755 index 000000000000..d32b69ed2dc8 --- /dev/null +++ b/packages/nextjs/test/run-integration-tests.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +for version in 10 11; do + echo "[next@$version] Running integration tests" + + pushd "$(dirname "$0")/integration" > /dev/null + rm -rf node_modules .next .env.local 2> /dev/null || true + yarn --no-lockfile + yarn add "next@$version" + yarn build + + EXIT_CODE=0 + node test/server.js --silent || EXIT_CODE=$? + if [ $EXIT_CODE -eq 0 ] + then + echo "[next@$version] Server integration tests passed." + else + echo "[next@$version] Server integration tests failed." + exit 1 + fi + + EXIT_CODE=0 + node test/client.js --silent || EXIT_CODE=$? + if [ $EXIT_CODE -eq 0 ] + then + echo "[next@$version] Client integration tests passed." + else + echo "[next@$version] Client integration tests failed." + exit 1 + fi + + yarn remove next + popd > /dev/null +done; \ No newline at end of file From db3f0150beb0abd107b675db29abaff4ac215aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 24 Jun 2021 10:37:03 +0200 Subject: [PATCH 2/4] Run tests only on supported node versions --- packages/nextjs/package.json | 1 + packages/nextjs/test/integration/package.json | 1 - packages/nextjs/test/run-integration-tests.sh | 34 +++++++++++++------ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 0bda85daffc5..575bdb5baaec 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -30,6 +30,7 @@ "@sentry/types": "6.7.2", "@types/webpack": "^5.28.0", "eslint": "7.20.0", + "eslint-config-next": "^11.0.1", "next": "10.1.3", "rimraf": "3.0.2" }, diff --git a/packages/nextjs/test/integration/package.json b/packages/nextjs/test/integration/package.json index 4fceff5c8d0c..ab31ecd91300 100644 --- a/packages/nextjs/test/integration/package.json +++ b/packages/nextjs/test/integration/package.json @@ -15,7 +15,6 @@ "@types/puppeteer": "^5.4.3", "@types/react": "^17.0.6", "@types/react-dom": "^17.0.5", - "eslint-config-next": "^11.0.1", "nock": "^13.1.0", "puppeteer": "^9.1.1", "typescript": "^4.2.4", diff --git a/packages/nextjs/test/run-integration-tests.sh b/packages/nextjs/test/run-integration-tests.sh index d32b69ed2dc8..92a1c958ee3f 100755 --- a/packages/nextjs/test/run-integration-tests.sh +++ b/packages/nextjs/test/run-integration-tests.sh @@ -3,8 +3,17 @@ set -e for version in 10 11; do - echo "[next@$version] Running integration tests" - + NODE_VERSION=$(node -v) + NODE_MAJOR=$(echo $NODE_VERSION | cut -c2- | cut -d. -f1) + + # Next 10 requires at least Node v10 + if [ "$NODE_MAJOR" -lt "10" ]; then + echo "[next] Next.js is not compatible with Node versions older than v10. Current version $NODE_VERSION" + exit 0 + fi + + echo "[next@$version] Running integration tests on $NODE_VERSION" + pushd "$(dirname "$0")/integration" > /dev/null rm -rf node_modules .next .env.local 2> /dev/null || true yarn --no-lockfile @@ -21,16 +30,21 @@ for version in 10 11; do exit 1 fi - EXIT_CODE=0 - node test/client.js --silent || EXIT_CODE=$? - if [ $EXIT_CODE -eq 0 ] - then - echo "[next@$version] Client integration tests passed." + # Next 11 requires at least Node v12 + if [ "$NODE_VERSION" -ge "12" ]; then + EXIT_CODE=0 + node test/client.js --silent || EXIT_CODE=$? + if [ $EXIT_CODE -eq 0 ] + then + echo "[next@$version] Client integration tests passed." + else + echo "[next@$version] Client integration tests failed." + exit 1 + fi else - echo "[next@$version] Client integration tests failed." - exit 1 + echo "[next$version] Not compatible with Node $NODE_VERSION" fi yarn remove next popd > /dev/null -done; \ No newline at end of file +done; From f60143001b63b430fcb11fd73f27c19deffb29d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 24 Jun 2021 12:21:35 +0200 Subject: [PATCH 3/4] Run both next versions on both webpack variants --- .../test/integration/next10.config.template | 15 ++++ .../test/integration/next11.config.template | 13 +++ packages/nextjs/test/integration/package.json | 2 + packages/nextjs/test/run-integration-tests.sh | 82 ++++++++++++------- 4 files changed, 84 insertions(+), 28 deletions(-) create mode 100644 packages/nextjs/test/integration/next10.config.template create mode 100644 packages/nextjs/test/integration/next11.config.template diff --git a/packages/nextjs/test/integration/next10.config.template b/packages/nextjs/test/integration/next10.config.template new file mode 100644 index 000000000000..3e5125d5e8c7 --- /dev/null +++ b/packages/nextjs/test/integration/next10.config.template @@ -0,0 +1,15 @@ +const { withSentryConfig } = require('@sentry/nextjs'); + +// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5 +const moduleExports = { + future: { + webpack5: %RUN_WEBPACK_5% + } +}; + +const SentryWebpackPluginOptions = { + dryRun: true, + silent: true, +}; + +module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions); diff --git a/packages/nextjs/test/integration/next11.config.template b/packages/nextjs/test/integration/next11.config.template new file mode 100644 index 000000000000..b2bc36a9c14b --- /dev/null +++ b/packages/nextjs/test/integration/next11.config.template @@ -0,0 +1,13 @@ +const { withSentryConfig } = require('@sentry/nextjs'); + +// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5 +const moduleExports = { + webpack5: %RUN_WEBPACK_5% +}; + +const SentryWebpackPluginOptions = { + dryRun: true, + silent: true, +}; + +module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions); diff --git a/packages/nextjs/test/integration/package.json b/packages/nextjs/test/integration/package.json index ab31ecd91300..e6de098ec2b1 100644 --- a/packages/nextjs/test/integration/package.json +++ b/packages/nextjs/test/integration/package.json @@ -1,5 +1,6 @@ { "name": "with-typescript", + "license": "BSD-3-Clause", "scripts": { "dev": "next", "build": "next build", @@ -15,6 +16,7 @@ "@types/puppeteer": "^5.4.3", "@types/react": "^17.0.6", "@types/react-dom": "^17.0.5", + "eslint-config-next": "^11.0.1", "nock": "^13.1.0", "puppeteer": "^9.1.1", "typescript": "^4.2.4", diff --git a/packages/nextjs/test/run-integration-tests.sh b/packages/nextjs/test/run-integration-tests.sh index 92a1c958ee3f..3eca482f0112 100755 --- a/packages/nextjs/test/run-integration-tests.sh +++ b/packages/nextjs/test/run-integration-tests.sh @@ -2,49 +2,75 @@ set -e -for version in 10 11; do +function cleanup { + echo "[nextjs] Cleaning up..." + mv next.config.js.bak next.config.js + yarn remove next > /dev/null 2>&1 || true + echo "[nextjs] Test run complete" +} + +trap cleanup EXIT + +cd "$(dirname "$0")/integration" + +for NEXTJS_VERSION in 10 11; do NODE_VERSION=$(node -v) - NODE_MAJOR=$(echo $NODE_VERSION | cut -c2- | cut -d. -f1) + NODE_MAJOR=$(echo "$NODE_VERSION" | cut -c2- | cut -d. -f1) # Next 10 requires at least Node v10 if [ "$NODE_MAJOR" -lt "10" ]; then - echo "[next] Next.js is not compatible with Node versions older than v10. Current version $NODE_VERSION" + 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" -eq "10" ]; then + echo "[nextjs$NEXTJS_VERSION] Not compatible with Node $NODE_VERSION" exit 0 fi - echo "[next@$version] Running integration tests on $NODE_VERSION" + echo "[nextjs@$NEXTJS_VERSION] Running integration tests on $NODE_VERSION" - pushd "$(dirname "$0")/integration" > /dev/null + echo "[nextjs@$NEXTJS_VERSION] Preparing environment..." + mv next.config.js next.config.js.bak rm -rf node_modules .next .env.local 2> /dev/null || true - yarn --no-lockfile - yarn add "next@$version" - yarn build - - EXIT_CODE=0 - node test/server.js --silent || EXIT_CODE=$? - if [ $EXIT_CODE -eq 0 ] - then - echo "[next@$version] Server integration tests passed." - else - echo "[next@$version] Server integration tests failed." - exit 1 - fi - # Next 11 requires at least Node v12 - if [ "$NODE_VERSION" -ge "12" ]; then + echo "[nextjs@$NEXTJS_VERSION] Installing dependencies..." + yarn --no-lockfile --silent > /dev/null 2>&1 + yarn add "next@$NEXTJS_VERSION" > /dev/null 2>&1 + + for RUN_WEBPACK_5 in false true; do + [ "$RUN_WEBPACK_5" == true ] && + WEBPACK_VERSION=5 || + WEBPACK_VERSION=4 + + if [ "$NEXTJS_VERSION" -eq "10" ]; then + sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" < next10.config.template > next.config.js + else + sed "s/%RUN_WEBPACK_5%/$RUN_WEBPACK_5/g" < next11.config.template > next.config.js + fi + + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Building..." + yarn build | grep "Using webpack" + EXIT_CODE=0 - node test/client.js --silent || EXIT_CODE=$? + node test/server.js --silent || EXIT_CODE=$? if [ $EXIT_CODE -eq 0 ] then - echo "[next@$version] Client integration tests passed." + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests passed" else - echo "[next@$version] Client integration tests failed." + echo "[nextjs@$NEXTJS_VERSION | webpack@$WEBPACK_VERSION] Server integration tests failed" exit 1 fi - else - echo "[next$version] Not compatible with Node $NODE_VERSION" - fi - yarn remove next - popd > /dev/null + EXIT_CODE=0 + node test/client.js --silent || 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; From 78e9beca2cdc7a341482c6bb9e484e4929f3caa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Thu, 24 Jun 2021 12:35:05 +0200 Subject: [PATCH 4/4] Solve eslint silliness --- packages/nextjs/package.json | 1 - packages/nextjs/test/integration/.eslintrc | 4 ---- packages/nextjs/test/integration/next.config.js | 6 +++++- packages/nextjs/test/integration/next10.config.template | 4 ++-- packages/nextjs/test/integration/next11.config.template | 5 ++++- packages/nextjs/test/integration/package.json | 1 - packages/nextjs/test/run-integration-tests.sh | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 packages/nextjs/test/integration/.eslintrc diff --git a/packages/nextjs/package.json b/packages/nextjs/package.json index 575bdb5baaec..0bda85daffc5 100644 --- a/packages/nextjs/package.json +++ b/packages/nextjs/package.json @@ -30,7 +30,6 @@ "@sentry/types": "6.7.2", "@types/webpack": "^5.28.0", "eslint": "7.20.0", - "eslint-config-next": "^11.0.1", "next": "10.1.3", "rimraf": "3.0.2" }, diff --git a/packages/nextjs/test/integration/.eslintrc b/packages/nextjs/test/integration/.eslintrc deleted file mode 100644 index c3796c8047dd..000000000000 --- a/packages/nextjs/test/integration/.eslintrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "root": true, - "extends": "next" -} diff --git a/packages/nextjs/test/integration/next.config.js b/packages/nextjs/test/integration/next.config.js index df9a42bbf943..9569096fa9ab 100644 --- a/packages/nextjs/test/integration/next.config.js +++ b/packages/nextjs/test/integration/next.config.js @@ -1,6 +1,10 @@ const { withSentryConfig } = require('@sentry/nextjs'); -const moduleExports = {}; +const moduleExports = { + eslint: { + ignoreDuringBuilds: true, + } +}; const SentryWebpackPluginOptions = { dryRun: true, silent: true, diff --git a/packages/nextjs/test/integration/next10.config.template b/packages/nextjs/test/integration/next10.config.template index 3e5125d5e8c7..e9e52049a4f3 100644 --- a/packages/nextjs/test/integration/next10.config.template +++ b/packages/nextjs/test/integration/next10.config.template @@ -3,8 +3,8 @@ const { withSentryConfig } = require('@sentry/nextjs'); // NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5 const moduleExports = { future: { - webpack5: %RUN_WEBPACK_5% - } + webpack5: %RUN_WEBPACK_5%, + }, }; const SentryWebpackPluginOptions = { diff --git a/packages/nextjs/test/integration/next11.config.template b/packages/nextjs/test/integration/next11.config.template index b2bc36a9c14b..5de08b436a67 100644 --- a/packages/nextjs/test/integration/next11.config.template +++ b/packages/nextjs/test/integration/next11.config.template @@ -2,7 +2,10 @@ const { withSentryConfig } = require('@sentry/nextjs'); // NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5 const moduleExports = { - webpack5: %RUN_WEBPACK_5% + webpack5: %RUN_WEBPACK_5%, + eslint: { + ignoreDuringBuilds: true, + }, }; const SentryWebpackPluginOptions = { diff --git a/packages/nextjs/test/integration/package.json b/packages/nextjs/test/integration/package.json index e6de098ec2b1..8450b808f1ad 100644 --- a/packages/nextjs/test/integration/package.json +++ b/packages/nextjs/test/integration/package.json @@ -16,7 +16,6 @@ "@types/puppeteer": "^5.4.3", "@types/react": "^17.0.6", "@types/react-dom": "^17.0.5", - "eslint-config-next": "^11.0.1", "nock": "^13.1.0", "puppeteer": "^9.1.1", "typescript": "^4.2.4", diff --git a/packages/nextjs/test/run-integration-tests.sh b/packages/nextjs/test/run-integration-tests.sh index 3eca482f0112..f306825a5d97 100755 --- a/packages/nextjs/test/run-integration-tests.sh +++ b/packages/nextjs/test/run-integration-tests.sh @@ -4,7 +4,7 @@ set -e function cleanup { echo "[nextjs] Cleaning up..." - mv next.config.js.bak next.config.js + mv next.config.js.bak next.config.js 2> /dev/null || true yarn remove next > /dev/null 2>&1 || true echo "[nextjs] Test run complete" }