Unverified Commit c765fadf authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update CI test setup (#46138

This updates our CI testing flow to only run against LTS Node.js version
on PRs and then run against the maintenance Node.js version when cutting
a release. This will allow speeding up PR test runs to get feedback
faster and remove un-necessary duplicate testing as it's very rare a
change breaks the maintenance Node.js version but not the LTS version.
parent 888384c5
......@@ -11,6 +11,8 @@ env:
TURBO_VERSION: 1.6.3
RUST_TOOLCHAIN: nightly-2022-11-04
PNPM_VERSION: 7.24.3
NODE_MAINTENANCE_VERSION: 16
NODE_LTS_VERSION: 18
jobs:
check-examples:
......@@ -127,7 +129,12 @@ jobs:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- run: ./scripts/check-manifests.js
- run: pnpm lint
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: pnpm lint-no-typescript
if: ${{needs.build.outputs.docsChange != 'nope'}}
rust-check:
runs-on: ubuntu-latest
......@@ -259,8 +266,9 @@ jobs:
- run: node run-tests.js --type unit
if: ${{needs.build.outputs.docsChange == 'nope'}}
testDev:
name: Test Development
# run LTS matrix always and maintenance tests during a release
testDevLTS:
name: Test Development Node.js LTS
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 35
......@@ -270,8 +278,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [16, 18]
group: [1, 2, 3, 4]
node: [18]
group: [1, 2, 3, 4, 5]
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
......@@ -293,22 +301,60 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=dev TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type development --timings -g ${{ matrix.group }}/4 >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=dev TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type development --timings -g ${{ matrix.group }}/5 >> /proc/1/fd/1"
name: Run test/development
if: ${{needs.build.outputs.docsChange == 'nope'}}
# env:
# RECORD_REPLAY_METADATA_TEST_RUN_TITLE: testDev / Group ${{ matrix.group }}
# RECORD_ALL_CONTENT: 1
# RECORD_REPLAY: 1
# RECORD_REPLAY_TEST_METRICS: 1
# RECORD_REPLAY_WEBHOOK_URL: ${{ secrets.RECORD_REPLAY_WEBHOOK_URL }}
# - uses: replayio/action-upload@v0.4.5
# if: always()
# with:
# api-key: rwk_iKsQnEoQwKd31WAJxgN9ARPFuAlyXlVrDH4uhYpRnti
# public: true
# filter: ${{ 'function($v) { $v.metadata.test.result = "failed" }' }}
- name: Upload test trace
if: always()
uses: actions/upload-artifact@v3
with:
name: test-trace
if-no-files-found: ignore
retention-days: 2
path: |
test/traces
testDevMaintenance:
name: Test Development Node.js Maintenance
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 35
env:
NEXT_TELEMETRY_DISABLED: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
strategy:
fail-fast: false
matrix:
node: [16]
group: [1, 2, 3, 4, 5]
# we can't use "matrix" context in job level "if" so we have
# to create a separate job which can skip
if: ${{ needs.build.outputs.isRelease == 'true' }}
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
timeout-minutes: 5
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=dev TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type development --timings -g ${{ matrix.group }}/5 >> /proc/1/fd/1"
name: Run test/development
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -320,8 +366,8 @@ jobs:
path: |
test/traces
testDevE2E:
name: Test Development (E2E)
testDevE2ELTS:
name: Test Development (E2E) Node.js LTS
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 35
......@@ -331,8 +377,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [16, 18]
group: [1, 2, 3, 4, 5, 6, 7]
node: [18]
group: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
......@@ -354,21 +400,58 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=dev TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/7 >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=dev TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/8 >> /proc/1/fd/1"
name: Run test/e2e (dev)
if: ${{needs.build.outputs.docsChange == 'nope'}}
# RECORD_REPLAY_METADATA_TEST_RUN_TITLE: testDevE2E / Group ${{ matrix.group }} / Node ${{ matrix.node }}
# RECORD_ALL_CONTENT: 1
# RECORD_REPLAY: 1
# RECORD_REPLAY_TEST_METRICS: 1
# RECORD_REPLAY_WEBHOOK_URL: ${{ secrets.RECORD_REPLAY_WEBHOOK_URL }}
# - uses: replayio/action-upload@v0.4.5
# if: always()
# with:
# api-key: rwk_iKsQnEoQwKd31WAJxgN9ARPFuAlyXlVrDH4uhYpRnti
# public: true
# filter: ${{ 'function($v) { $v.metadata.test.result = "failed" }' }}
- name: Upload test trace
if: always()
uses: actions/upload-artifact@v3
with:
name: test-trace
if-no-files-found: ignore
retention-days: 2
path: |
test/traces
testDevE2EMaintenance:
name: Test Development (E2E) Node.js Maintenance
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 35
env:
NEXT_TELEMETRY_DISABLED: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
strategy:
fail-fast: false
matrix:
node: [16]
group: [1, 2, 3, 4, 5, 6, 7, 8]
if: ${{ needs.build.outputs.isRelease == 'true' }}
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
timeout-minutes: 5
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=dev TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/8 >> /proc/1/fd/1"
name: Run test/e2e (dev)
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -380,8 +463,8 @@ jobs:
path: |
test/traces
testProd:
name: Test Production
testProdLTS:
name: Test Production Node.js LTS
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 15
......@@ -391,8 +474,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [16, 18]
group: [1, 2, 3]
node: [18]
group: [1, 2, 3, 4, 5]
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
......@@ -414,25 +497,51 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type production --timings -g ${{ matrix.group }}/3 >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type production --timings -g ${{ matrix.group }}/5 >> /proc/1/fd/1"
name: Run test/production
if: ${{needs.build.outputs.docsChange == 'nope'}}
# env:
# RECORD_REPLAY_METADATA_TEST_RUN_TITLE: testProd / Group ${{ matrix.group }} / Node ${{ matrix.node }}
# RECORD_ALL_CONTENT: 1
# RECORD_REPLAY: 1
# RECORD_REPLAY_TEST_METRICS: 1
# RECORD_REPLAY_WEBHOOK_URL: ${{ secrets.RECORD_REPLAY_WEBHOOK_URL }}
# - uses: replayio/action-upload@v0.4.5
# if: always()
# with:
# api-key: rwk_iKsQnEoQwKd31WAJxgN9ARPFuAlyXlVrDH4uhYpRnti
# public: true
# filter: ${{ 'function($v) { $v.metadata.test.result = "failed" }' }}
testProdMaintenance:
name: Test Production Node.js Maintenance
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 15
env:
NEXT_TELEMETRY_DISABLED: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
strategy:
fail-fast: false
matrix:
node: [16]
group: [1, 2, 3, 4, 5]
if: ${{ needs.build.outputs.isRelease == 'true' }}
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
timeout-minutes: 5
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
testProdE2E:
name: Test Production (E2E)
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type production --timings -g ${{ matrix.group }}/5 >> /proc/1/fd/1"
name: Run test/production
if: ${{needs.build.outputs.docsChange == 'nope'}}
testProdE2ELTS:
name: Test Production (E2E) Node.js LTS
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 35
......@@ -442,8 +551,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [16, 18]
group: [1, 2, 3, 4, 5, 6, 7]
node: [18]
group: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
......@@ -465,21 +574,49 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/7 >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/8 >> /proc/1/fd/1"
name: Run test/e2e (production)
if: ${{needs.build.outputs.docsChange == 'nope'}}
# RECORD_REPLAY_METADATA_TEST_RUN_TITLE: testProdE2E / Group ${{ matrix.group }} / Node ${{ matrix.node }}
# RECORD_ALL_CONTENT: 1
# RECORD_REPLAY: 1
# RECORD_REPLAY_TEST_METRICS: 1
# RECORD_REPLAY_WEBHOOK_URL: ${{ secrets.RECORD_REPLAY_WEBHOOK_URL }}
# - uses: replayio/action-upload@v0.4.5
# if: always()
# with:
# api-key: rwk_iKsQnEoQwKd31WAJxgN9ARPFuAlyXlVrDH4uhYpRnti
# public: true
# filter: ${{ 'function($v) { $v.metadata.test.result = "failed" }' }}
testProdE2EMaintenance:
name: Test Production (E2E) Node.js Maintenance
runs-on: ubuntu-latest
needs: [build, build-native-test]
timeout-minutes: 35
env:
NEXT_TELEMETRY_DISABLED: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
strategy:
fail-fast: false
matrix:
node: [16]
group: [1, 2, 3, 4, 5, 6, 7, 8]
# run LTS matrix always and maintenance tests during a release
if: ${{ needs.build.outputs.isRelease == 'true' }}
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
timeout-minutes: 5
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ matrix.node }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e --timings -g ${{ matrix.group }}/8 >> /proc/1/fd/1"
name: Run test/e2e (production)
if: ${{needs.build.outputs.docsChange == 'nope'}}
testCNA:
name: Test Create Next App
......@@ -489,7 +626,6 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
TEST_TIMINGS_TOKEN: ${{ secrets.TEST_TIMINGS_TOKEN }}
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
......@@ -514,7 +650,7 @@ jobs:
- run: echo "CNA_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.js --type cna --always-canary --exec echo 'yup')" >> $GITHUB_OUTPUT; echo "EOF" >> $GITHUB_OUTPUT
id: cna-change
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_CNA=1 xvfb-run node run-tests.js test/integration/create-next-app/index.test.ts test/integration/create-next-app/templates.test.ts >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_CNA=1 xvfb-run node run-tests.js test/integration/create-next-app/index.test.ts test/integration/create-next-app/templates.test.ts >> /proc/1/fd/1"
if: ${{ needs.build.outputs.docsChange == 'nope' && steps.cna-change.outputs.CNA_CHANGE == 'yup' }}
- name: Upload test trace
......@@ -554,7 +690,7 @@ jobs:
- run: echo "CODEMOD_CHANGE<<EOF" >> $GITHUB_OUTPUT; echo "$(node scripts/run-for-change.js --type next-codemod --always-canary --exec echo 'yup')" >> $GITHUB_OUTPUT; echo "EOF" >> $GITHUB_OUTPUT
id: codemodChange
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && cd ./packages/next-codemod && pnpm build && pnpm test >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && cd ./packages/next-codemod && pnpm build && pnpm test >> /proc/1/fd/1"
if: ${{ needs.build.outputs.docsChange == 'nope' && steps.codemodChange.outputs.CODEMOD_CHANGE == 'yup' }}
testIntegration:
......@@ -595,6 +731,9 @@ jobs:
23,
24,
25,
26,
27,
28,
]
steps:
- run: echo "${{needs.build.outputs.docsChange}}"
......@@ -617,21 +756,8 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --timings -g ${{ matrix.group }}/25 >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --timings -g ${{ matrix.group }}/28 >> /proc/1/fd/1"
if: ${{needs.build.outputs.docsChange == 'nope'}}
# env:
# RECORD_REPLAY_METADATA_TEST_RUN_TITLE: testIntegration / Group ${{ matrix.group }}
# RECORD_ALL_CONTENT: 1
# RECORD_REPLAY: 1
# RECORD_REPLAY_TEST_METRICS: 1
# RECORD_REPLAY_WEBHOOK_URL: ${{ secrets.RECORD_REPLAY_WEBHOOK_URL }}
# - uses: replayio/action-upload@v0.4.5
# if: always()
# with:
# api-key: rwk_iKsQnEoQwKd31WAJxgN9ARPFuAlyXlVrDH4uhYpRnti
# public: true
# filter: ${{ 'function($v) { $v.metadata.test.result = "failed" }' }}
- name: Upload test trace
if: always()
......@@ -693,8 +819,10 @@ jobs:
checkPrecompiled,
testIntegration,
testUnit,
testDev,
testProd,
testDevLTS,
testProdLTS,
testDevE2ELTS,
testprode2elts,
]
steps:
- run: exit 0
......@@ -721,7 +849,7 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && BROWSERNAME=firefox NEXT_TEST_JOB=1 TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js test/integration/production/test/index.test.js >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_MAINTENANCE_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && BROWSERNAME=firefox NEXT_TEST_JOB=1 TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js test/integration/production/test/index.test.js >> /proc/1/fd/1"
if: ${{needs.build.outputs.docsChange == 'nope'}}
testSafari:
......@@ -750,11 +878,11 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start BROWSER_NAME=safari node run-tests.js -c 1 test/integration/production/test/index.test.js test/e2e/basepath.test.ts && DEVICE_NAME='iPhone XR' node run-tests.js -c 1 test/production/prerender-prefetch/index.test.ts >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v{{ env.NODE_LTS_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && NEXT_TEST_JOB=1 NEXT_TEST_MODE=start BROWSER_NAME=safari node run-tests.js -c 1 test/integration/production/test/index.test.js test/e2e/basepath.test.ts && DEVICE_NAME='iPhone XR' node run-tests.js -c 1 test/production/prerender-prefetch/index.test.ts >> /proc/1/fd/1"
if: ${{needs.build.outputs.docsChange == 'nope'}}
testFirefoxNode18:
name: Test Firefox Node.js 18
testFirefoxNodeLTS:
name: Test Firefox Node.js LTS
runs-on: ubuntu-latest
needs: [build, testFirefox, build-native-test]
timeout-minutes: 10
......@@ -775,7 +903,7 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v18 | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && BROWSER_NAME=firefox NEXT_TEST_JOB=1 TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js test/integration/production/test/index.test.js >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && node -v && npm i -g pnpm@${PNPM_VERSION} > /dev/null && BROWSER_NAME=firefox NEXT_TEST_JOB=1 TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js test/integration/production/test/index.test.js >> /proc/1/fd/1"
if: ${{needs.build.outputs.docsChange == 'nope'}}
publishRelease:
......@@ -848,7 +976,7 @@ jobs:
- run: RESET_VC_PROJECT=true node scripts/reset-vercel-project.mjs
name: Reset test project
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && npm i -g pnpm@${PNPM_VERSION} > /dev/null && VERCEL_TEST_TOKEN=${{ secrets.VERCEL_TEST_TOKEN }} VERCEL_TEST_TEAM=vtest314-next-e2e-tests NEXT_TEST_JOB=1 NEXT_TEST_MODE=deploy TEST_TIMINGS_TOKEN=${{ secrets.TEST_TIMINGS_TOKEN }} xvfb-run node run-tests.js --type e2e >> /proc/1/fd/1"
name: Run test/e2e (deploy)
- name: Upload test trace
......@@ -1041,7 +1169,7 @@ jobs:
name: next-swc-test-binary
path: packages/next-swc/native
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v16 | FORCE=1 bash && node -v && node ./scripts/setup-wasm.mjs && npm i -g pnpm@${PNPM_VERSION} > /dev/null && TEST_WASM=true xvfb-run node run-tests.js test/integration/production/test/index.test.js test/e2e/streaming-ssr/index.test.ts >> /proc/1/fd/1"
- run: docker run --rm -v $(pwd):/work mcr.microsoft.com/playwright:v1.28.1-focal /bin/bash -c "cd /work && curl -s https://install-node.vercel.app/v${{ env.NODE_LTS_VERSION }} | FORCE=1 bash && node -v && node ./scripts/setup-wasm.mjs && npm i -g pnpm@${PNPM_VERSION} > /dev/null && TEST_WASM=true xvfb-run node run-tests.js test/integration/production/test/index.test.js test/e2e/streaming-ssr/index.test.ts >> /proc/1/fd/1"
if: ${{needs.build.outputs.docsChange == 'nope'}}
# Build binaries for publishing
......
import {
check,
findAllTelemetryEvents,
findPort,
killApp,
launchApp,
nextBuild,
nextLint,
} from 'next-test-utils'
import fs from 'fs-extra'
import path from 'path'
const appDir = path.join(__dirname, '..')
describe('config telemetry', () => {
it('detects rewrites, headers, and redirects for next build', async () => {
await fs.rename(
path.join(appDir, 'next.config.custom-routes'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.custom-routes')
)
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(stderr).pop()
expect(event1).toMatch(/"headersCount": 1/)
expect(event1).toMatch(/"rewritesCount": 2/)
expect(event1).toMatch(/"redirectsCount": 1/)
expect(event1).toMatch(/"middlewareCount": 0/)
})
it('detects i18n and image configs for session start', async () => {
await fs.rename(
path.join(appDir, 'next.config.i18n-images'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.i18n-images')
)
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"i18nEnabled": true/)
expect(event1).toMatch(/"locales": "en,nl,fr"/)
expect(event1).toMatch(/"localeDomainsCount": 2/)
expect(event1).toMatch(/"localeDetectionEnabled": true/)
expect(event1).toMatch(/"imageEnabled": true/)
expect(event1).toMatch(/"imageFutureEnabled": true/)
expect(event1).toMatch(/"imageDomainsCount": 2/)
expect(event1).toMatch(/"imageRemotePatternsCount": 1/)
expect(event1).toMatch(/"imageSizes": "64,128,256,512,1024"/)
expect(event1).toMatch(/"imageFormats": "image\/avif,image\/webp"/)
expect(event1).toMatch(/"trailingSlashEnabled": false/)
expect(event1).toMatch(/"reactStrictMode": false/)
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": false/)
await fs.rename(
path.join(appDir, 'next.config.i18n-images'),
path.join(appDir, 'next.config.js')
)
let stderr2 = ''
let app = await launchApp(appDir, await findPort(), {
onStderr(msg) {
stderr2 += msg || ''
},
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await check(() => stderr2, /NEXT_CLI_SESSION_STARTED/)
await killApp(app)
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.i18n-images')
)
const event2 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr2)
.pop()
expect(event2).toMatch(/"i18nEnabled": true/)
expect(event2).toMatch(/"locales": "en,nl,fr"/)
expect(event2).toMatch(/"localeDomainsCount": 2/)
expect(event2).toMatch(/"localeDetectionEnabled": true/)
expect(event2).toMatch(/"imageDomainsCount": 2/)
expect(event2).toMatch(/"imageRemotePatternsCount": 1/)
expect(event2).toMatch(/"imageSizes": "64,128,256,512,1024"/)
expect(event2).toMatch(/"trailingSlashEnabled": false/)
expect(event2).toMatch(/"reactStrictMode": false/)
})
it('emits telemetry for lint during build', async () => {
await fs.writeFile(
path.join(appDir, '.eslintrc'),
`{ "root": true, "extends": "next" }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(path.join(appDir, '.eslintrc'))
const event1 = /NEXT_LINT_CHECK_COMPLETED[\s\S]+?{([\s\S}]+?)^}/m
.exec(stderr)
.pop()
expect(event1).toMatch(/"durationInSeconds": [\d]{1,}/)
expect(event1).toMatch(/"eslintVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"lintedFilesCount": [\d]{1,}/)
expect(event1).toMatch(/"lintFix": false/)
expect(event1).toMatch(/"buildLint": true/)
expect(event1).toMatch(/"nextEslintPluginVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"nextEslintPluginErrorsCount": \d{1,}/)
expect(event1).toMatch(/"nextEslintPluginWarningsCount": \d{1,}/)
expect(event1).toMatch(`"nextRulesEnabled": {`)
expect(event1).toMatch(/"@next\/next\/.+?": "(off|warn|error)"/)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'build-lint',
invocationCount: 1,
})
})
it(`emits telemetry for lint during build when '--no-lint' is specified`, async () => {
const { stderr } = await nextBuild(appDir, ['--no-lint'], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const events = findAllTelemetryEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(events).toContainEqual({
featureName: 'build-lint',
invocationCount: 0,
})
})
it(`emits telemetry for lint during build when 'ignoreDuringBuilds' is specified`, async () => {
const nextConfig = path.join(appDir, 'next.config.js')
await fs.writeFile(
nextConfig,
`module.exports = { eslint: { ignoreDuringBuilds: true } }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(nextConfig)
const events = findAllTelemetryEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(events).toContainEqual({
featureName: 'build-lint',
invocationCount: 0,
})
})
it('emits telemetry for `next lint`', async () => {
await fs.writeFile(
path.join(appDir, '.eslintrc'),
`{ "root": true, "extends": "next" }`
)
const { stderr } = await nextLint(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(path.join(appDir, '.eslintrc'))
const event1 = /NEXT_LINT_CHECK_COMPLETED[\s\S]+?{([\s\S]+?)^}/m
.exec(stderr)
.pop()
expect(event1).toMatch(/"durationInSeconds": [\d]{1,}/)
expect(event1).toMatch(/"eslintVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"lintedFilesCount": [\d]{1,}/)
expect(event1).toMatch(/"lintFix": false/)
expect(event1).toMatch(/"buildLint": false/)
expect(event1).toMatch(/"nextEslintPluginVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"nextEslintPluginErrorsCount": \d{1,}/)
expect(event1).toMatch(/"nextEslintPluginWarningsCount": \d{1,}/)
expect(event1).toMatch(`"nextRulesEnabled": {`)
expect(event1).toMatch(/"@next\/next\/.+?": "(off|warn|error)"/)
})
it('emits telemery for usage of optimizeFonts, image, script & dynamic', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'optimizeFonts',
invocationCount: 1,
},
{
featureName: 'next/image',
invocationCount: 2,
},
{
featureName: 'next/script',
invocationCount: 1,
},
{
featureName: 'next/dynamic',
invocationCount: 1,
},
])
)
})
it('emits telemetry for usage of swc', async () => {
await fs.remove(path.join(appDir, 'next.config.js'))
await fs.remove(path.join(appDir, 'jsconfig.json'))
await fs.rename(
path.join(appDir, 'next.config.swc'),
path.join(appDir, 'next.config.js')
)
await fs.rename(
path.join(appDir, 'jsconfig.swc'),
path.join(appDir, 'jsconfig.json')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.swc')
)
await fs.rename(
path.join(appDir, 'jsconfig.json'),
path.join(appDir, 'jsconfig.swc')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'swcLoader',
invocationCount: 1,
},
{
featureName: 'swcMinify',
invocationCount: 1,
},
{
featureName: 'swcRelay',
invocationCount: 1,
},
{
featureName: 'swcStyledComponents',
invocationCount: 1,
},
{
featureName: 'swcReactRemoveProperties',
invocationCount: 1,
},
{
featureName: 'swcExperimentalDecorators',
invocationCount: 1,
},
{
featureName: 'swcRemoveConsole',
invocationCount: 1,
},
{
featureName: 'swcImportSource',
invocationCount: 0,
},
])
)
})
it('emits telemetry for usage of `optimizeCss`', async () => {
await fs.rename(
path.join(appDir, 'next.config.optimize-css'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.optimize-css')
)
const events = findAllTelemetryEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(events).toContainEqual({
featureName: 'experimental/optimizeCss',
invocationCount: 1,
})
})
it('emits telemetry for usage of `nextScriptWorkers`', async () => {
await fs.rename(
path.join(appDir, 'next.config.next-script-workers'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.next-script-workers')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'experimental/nextScriptWorkers',
invocationCount: 1,
})
})
it('emits telemetry for usage of middleware', async () => {
await fs.writeFile(
path.join(appDir, 'middleware.js'),
`export function middleware () { }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(path.join(appDir, 'middleware.js'))
const buildOptimizedEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_OPTIMIZED'
)
expect(buildOptimizedEvents).toContainEqual(
expect.objectContaining({
middlewareCount: 1,
})
)
})
it('emits telemetry for usage of swc plugins', async () => {
await fs.remove(path.join(appDir, 'next.config.js'))
await fs.remove(path.join(appDir, 'package.json'))
await fs.rename(
path.join(appDir, 'next.config.swc-plugins'),
path.join(appDir, 'next.config.js')
)
await fs.rename(
path.join(appDir, 'package.swc-plugins'),
path.join(appDir, 'package.json')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.swc-plugins')
)
await fs.rename(
path.join(appDir, 'package.json'),
path.join(appDir, 'package.swc-plugins')
)
const pluginDetectedEvents = findAllTelemetryEvents(
stderr,
'NEXT_SWC_PLUGIN_DETECTED'
)
expect(pluginDetectedEvents).toEqual([
{
pluginName: 'swc-plugin-coverage-instrument',
pluginVersion: '0.0.6',
},
{
pluginName: '@swc/plugin-relay',
pluginVersion: '0.2.0',
},
{
pluginName: '/test/absolute_path/plugin.wasm',
},
])
})
it('emits telemetry for usage of next/legacy/image', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'next/legacy/image',
invocationCount: 2,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'next/image',
invocationCount: 2,
})
})
it('emits telemetry for usage of @vercel/og', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'vercelImageGeneration',
invocationCount: 1,
})
})
it('emits telemetry for transpilePackages', async () => {
await fs.rename(
path.join(appDir, 'next.config.transpile-packages'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.transpile-packages')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'transpilePackages',
invocationCount: 1,
})
})
it('emits telemetry for middleware related options', async () => {
await fs.rename(
path.join(appDir, 'next.config.middleware-options'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.middleware-options')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'skipMiddlewareUrlNormalize',
invocationCount: 1,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'skipTrailingSlashRedirect',
invocationCount: 1,
})
})
})
......@@ -9,9 +9,6 @@ import {
killApp,
waitFor,
nextBuild,
nextLint,
check,
findAllTelemetryEvents,
} from 'next-test-utils'
const appDir = path.join(__dirname, '..')
......@@ -404,772 +401,4 @@ describe('Telemetry CLI', () => {
expect(stderr).toMatch(/isSrcDir.*?true/)
})
const setupAppDir = async () => {
await fs.writeFile(
path.join(__dirname, '../next.config.js'),
'module.exports = { experimental: { appDir: true } }'
)
await fs.mkdir(path.join(__dirname, '../app'))
await fs.writeFile(
path.join(__dirname, '../app/layout.js'),
`
export default function RootLayout({ children }) {
return <html>
<head/>
<body>{children}</body>
</html>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/hello/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/hello/page.js'),
'export default function Page() { return "hello world" }'
)
return async function teardownAppDir() {
await fs.remove(path.join(__dirname, '../app'))
await fs.remove(path.join(__dirname, '../next.config.js'))
}
}
it('detects --turbo correctly for `next dev`', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await waitFor(1000)
if (app) {
await killApp(app)
}
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
} finally {
await teardown()
}
})
it('detects --turbo correctly for `next dev` stopped', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await app.kill('SIGTERM')
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe(
false
)
} finally {
await teardown()
}
})
it('detects correctly for `next dev` stopped (no turbo)', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await app.kill('SIGTERM')
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe(
false
)
} finally {
await teardown()
}
})
it('should detect app page counts', async () => {
const teardown = await setupAppDir()
try {
await fs.ensureFile(path.join(__dirname, '../app/ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/ssr/page.js'),
`
export const revalidate = 0
export default function Page() {
return <p>ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/edge-ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/edge-ssr/page.js'),
`
export const runtime = 'experimental-edge'
export default function Page() {
return <p>edge-ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/app-ssg/[slug]/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js'),
`
export function generateStaticParams() {
return [
{ slug: 'post-1' },
{ slug: 'post-2' },
]
}
export default function Page() {
return <p>ssg page</p>
}
`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"staticPropsPageCount": 2/)
expect(event1).toMatch(/"serverPropsPageCount": 2/)
expect(event1).toMatch(/"ssrPageCount": 3/)
expect(event1).toMatch(/"staticPageCount": 4/)
expect(event1).toMatch(/"totalPageCount": 11/)
expect(event1).toMatch(/"totalAppPagesCount": 4/)
expect(event1).toMatch(/"serverAppPagesCount": 2/)
expect(event1).toMatch(/"edgeRuntimeAppCount": 1/)
expect(event1).toMatch(/"edgeRuntimePagesCount": 2/)
const event2 = /NEXT_BUILD_COMPLETED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event2).toMatch(/"totalAppPagesCount": 4/)
} finally {
await teardown()
}
})
it('detect reportWebVitals correctly for `next build`', async () => {
// Case 1: When _app.js does not exist.
let build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
let event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(build.stderr)
.pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
// Case 2: When _app.js exist with reportWebVitals function.
await fs.utimes(
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
new Date(),
new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withreportwebvitals.empty')
)
event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(build.stderr).pop()
expect(event1).toMatch(/hasReportWebVitals.*?true/)
// Case 3: When _app.js exist without reportWebVitals function.
await fs.utimes(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
new Date(),
new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty')
)
event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(build.stderr).pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
})
it('detects rewrites, headers, and redirects for next build', async () => {
await fs.rename(
path.join(appDir, 'next.config.custom-routes'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.custom-routes')
)
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(stderr).pop()
expect(event1).toMatch(/"headersCount": 1/)
expect(event1).toMatch(/"rewritesCount": 2/)
expect(event1).toMatch(/"redirectsCount": 1/)
expect(event1).toMatch(/"middlewareCount": 0/)
})
it('detects i18n and image configs for session start', async () => {
await fs.rename(
path.join(appDir, 'next.config.i18n-images'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.i18n-images')
)
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"i18nEnabled": true/)
expect(event1).toMatch(/"locales": "en,nl,fr"/)
expect(event1).toMatch(/"localeDomainsCount": 2/)
expect(event1).toMatch(/"localeDetectionEnabled": true/)
expect(event1).toMatch(/"imageEnabled": true/)
expect(event1).toMatch(/"imageFutureEnabled": true/)
expect(event1).toMatch(/"imageDomainsCount": 2/)
expect(event1).toMatch(/"imageRemotePatternsCount": 1/)
expect(event1).toMatch(/"imageSizes": "64,128,256,512,1024"/)
expect(event1).toMatch(/"imageFormats": "image\/avif,image\/webp"/)
expect(event1).toMatch(/"trailingSlashEnabled": false/)
expect(event1).toMatch(/"reactStrictMode": false/)
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": false/)
await fs.rename(
path.join(appDir, 'next.config.i18n-images'),
path.join(appDir, 'next.config.js')
)
let stderr2 = ''
let app = await launchApp(appDir, await findPort(), {
onStderr(msg) {
stderr2 += msg || ''
},
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await waitFor(1000)
await killApp(app)
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.i18n-images')
)
const event2 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr2)
.pop()
expect(event2).toMatch(/"i18nEnabled": true/)
expect(event2).toMatch(/"locales": "en,nl,fr"/)
expect(event2).toMatch(/"localeDomainsCount": 2/)
expect(event2).toMatch(/"localeDetectionEnabled": true/)
expect(event2).toMatch(/"imageDomainsCount": 2/)
expect(event2).toMatch(/"imageRemotePatternsCount": 1/)
expect(event2).toMatch(/"imageSizes": "64,128,256,512,1024"/)
expect(event2).toMatch(/"trailingSlashEnabled": false/)
expect(event2).toMatch(/"reactStrictMode": false/)
})
it('emits telemetry for lint during build', async () => {
await fs.writeFile(
path.join(appDir, '.eslintrc'),
`{ "root": true, "extends": "next" }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(path.join(appDir, '.eslintrc'))
const event1 = /NEXT_LINT_CHECK_COMPLETED[\s\S]+?{([\s\S}]+?)^}/m
.exec(stderr)
.pop()
expect(event1).toMatch(/"durationInSeconds": [\d]{1,}/)
expect(event1).toMatch(/"eslintVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"lintedFilesCount": [\d]{1,}/)
expect(event1).toMatch(/"lintFix": false/)
expect(event1).toMatch(/"buildLint": true/)
expect(event1).toMatch(/"nextEslintPluginVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"nextEslintPluginErrorsCount": \d{1,}/)
expect(event1).toMatch(/"nextEslintPluginWarningsCount": \d{1,}/)
expect(event1).toMatch(`"nextRulesEnabled": {`)
expect(event1).toMatch(/"@next\/next\/.+?": "(off|warn|error)"/)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'build-lint',
invocationCount: 1,
})
})
it(`emits telemetry for lint during build when '--no-lint' is specified`, async () => {
const { stderr } = await nextBuild(appDir, ['--no-lint'], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const events = findAllTelemetryEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(events).toContainEqual({
featureName: 'build-lint',
invocationCount: 0,
})
})
it(`emits telemetry for lint during build when 'ignoreDuringBuilds' is specified`, async () => {
const nextConfig = path.join(appDir, 'next.config.js')
await fs.writeFile(
nextConfig,
`module.exports = { eslint: { ignoreDuringBuilds: true } }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(nextConfig)
const events = findAllTelemetryEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(events).toContainEqual({
featureName: 'build-lint',
invocationCount: 0,
})
})
it('emits telemetry for `next lint`', async () => {
await fs.writeFile(
path.join(appDir, '.eslintrc'),
`{ "root": true, "extends": "next" }`
)
const { stderr } = await nextLint(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(path.join(appDir, '.eslintrc'))
const event1 = /NEXT_LINT_CHECK_COMPLETED[\s\S]+?{([\s\S]+?)^}/m
.exec(stderr)
.pop()
expect(event1).toMatch(/"durationInSeconds": [\d]{1,}/)
expect(event1).toMatch(/"eslintVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"lintedFilesCount": [\d]{1,}/)
expect(event1).toMatch(/"lintFix": false/)
expect(event1).toMatch(/"buildLint": false/)
expect(event1).toMatch(/"nextEslintPluginVersion": ".*?\..*?\..*?"/)
expect(event1).toMatch(/"nextEslintPluginErrorsCount": \d{1,}/)
expect(event1).toMatch(/"nextEslintPluginWarningsCount": \d{1,}/)
expect(event1).toMatch(`"nextRulesEnabled": {`)
expect(event1).toMatch(/"@next\/next\/.+?": "(off|warn|error)"/)
})
it('emits telemery for usage of optimizeFonts, image, script & dynamic', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'optimizeFonts',
invocationCount: 1,
},
{
featureName: 'next/image',
invocationCount: 2,
},
{
featureName: 'next/script',
invocationCount: 1,
},
{
featureName: 'next/dynamic',
invocationCount: 1,
},
])
)
})
it('emits telemetry for usage of swc', async () => {
await fs.remove(path.join(appDir, 'next.config.js'))
await fs.remove(path.join(appDir, 'jsconfig.json'))
await fs.rename(
path.join(appDir, 'next.config.swc'),
path.join(appDir, 'next.config.js')
)
await fs.rename(
path.join(appDir, 'jsconfig.swc'),
path.join(appDir, 'jsconfig.json')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.swc')
)
await fs.rename(
path.join(appDir, 'jsconfig.json'),
path.join(appDir, 'jsconfig.swc')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toEqual(
expect.arrayContaining([
{
featureName: 'swcLoader',
invocationCount: 1,
},
{
featureName: 'swcMinify',
invocationCount: 1,
},
{
featureName: 'swcRelay',
invocationCount: 1,
},
{
featureName: 'swcStyledComponents',
invocationCount: 1,
},
{
featureName: 'swcReactRemoveProperties',
invocationCount: 1,
},
{
featureName: 'swcExperimentalDecorators',
invocationCount: 1,
},
{
featureName: 'swcRemoveConsole',
invocationCount: 1,
},
{
featureName: 'swcImportSource',
invocationCount: 0,
},
])
)
})
it('emits telemetry for usage of `optimizeCss`', async () => {
await fs.rename(
path.join(appDir, 'next.config.optimize-css'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.optimize-css')
)
const events = findAllTelemetryEvents(stderr, 'NEXT_BUILD_FEATURE_USAGE')
expect(events).toContainEqual({
featureName: 'experimental/optimizeCss',
invocationCount: 1,
})
})
it('emits telemetry for usage of `nextScriptWorkers`', async () => {
await fs.rename(
path.join(appDir, 'next.config.next-script-workers'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.next-script-workers')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'experimental/nextScriptWorkers',
invocationCount: 1,
})
})
it('emits telemetry for usage of middleware', async () => {
await fs.writeFile(
path.join(appDir, 'middleware.js'),
`export function middleware () { }`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.remove(path.join(appDir, 'middleware.js'))
const buildOptimizedEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_OPTIMIZED'
)
expect(buildOptimizedEvents).toContainEqual(
expect.objectContaining({
middlewareCount: 1,
})
)
})
it('emits telemetry for usage of swc plugins', async () => {
await fs.remove(path.join(appDir, 'next.config.js'))
await fs.remove(path.join(appDir, 'package.json'))
await fs.rename(
path.join(appDir, 'next.config.swc-plugins'),
path.join(appDir, 'next.config.js')
)
await fs.rename(
path.join(appDir, 'package.swc-plugins'),
path.join(appDir, 'package.json')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.swc-plugins')
)
await fs.rename(
path.join(appDir, 'package.json'),
path.join(appDir, 'package.swc-plugins')
)
const pluginDetectedEvents = findAllTelemetryEvents(
stderr,
'NEXT_SWC_PLUGIN_DETECTED'
)
expect(pluginDetectedEvents).toEqual([
{
pluginName: 'swc-plugin-coverage-instrument',
pluginVersion: '0.0.6',
},
{
pluginName: '@swc/plugin-relay',
pluginVersion: '0.2.0',
},
{
pluginName: '/test/absolute_path/plugin.wasm',
},
])
})
it('emits telemetry for usage of next/legacy/image', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'next/legacy/image',
invocationCount: 2,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'next/image',
invocationCount: 2,
})
})
it('emits telemetry for usage of @vercel/og', async () => {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'vercelImageGeneration',
invocationCount: 1,
})
})
it('emits telemetry for transpilePackages', async () => {
await fs.rename(
path.join(appDir, 'next.config.transpile-packages'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.transpile-packages')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'transpilePackages',
invocationCount: 1,
})
})
it('emits telemetry for middleware related options', async () => {
await fs.rename(
path.join(appDir, 'next.config.middleware-options'),
path.join(appDir, 'next.config.js')
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.middleware-options')
)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'skipMiddlewareUrlNormalize',
invocationCount: 1,
})
expect(featureUsageEvents).toContainEqual({
featureName: 'skipTrailingSlashRedirect',
invocationCount: 1,
})
})
})
import path from 'path'
import fs from 'fs-extra'
import { check, findPort, killApp, launchApp, nextBuild } from 'next-test-utils'
const appDir = path.join(__dirname, '..')
const setupAppDir = async () => {
await fs.writeFile(
path.join(__dirname, '../next.config.js'),
'module.exports = { experimental: { appDir: true } }'
)
await fs.mkdir(path.join(__dirname, '../app'))
await fs.writeFile(
path.join(__dirname, '../app/layout.js'),
`
export default function RootLayout({ children }) {
return <html>
<head/>
<body>{children}</body>
</html>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/hello/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/hello/page.js'),
'export default function Page() { return "hello world" }'
)
return async function teardownAppDir() {
await fs.remove(path.join(__dirname, '../app'))
await fs.remove(path.join(__dirname, '../next.config.js'))
}
}
describe('page features telemetry', () => {
it('detects --turbo correctly for `next dev`', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await killApp(app)
}
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
} finally {
await teardown()
}
})
it('detects --turbo correctly for `next dev` stopped', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await app.kill('SIGTERM')
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe(
false
)
} finally {
await teardown()
}
})
it('detects correctly for `next dev` stopped (no turbo)', async () => {
let port = await findPort()
let stderr = ''
const teardown = await setupAppDir()
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
if (app) {
await app.kill('SIGTERM')
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": true/)
expect(await fs.pathExists(path.join(appDir, '.next/_events.json'))).toBe(
false
)
} finally {
await teardown()
}
})
it('should detect app page counts', async () => {
const teardown = await setupAppDir()
try {
await fs.ensureFile(path.join(__dirname, '../app/ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/ssr/page.js'),
`
export const revalidate = 0
export default function Page() {
return <p>ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/edge-ssr/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/edge-ssr/page.js'),
`
export const runtime = 'experimental-edge'
export default function Page() {
return <p>edge-ssr page</p>
}
`
)
await fs.ensureFile(path.join(__dirname, '../app/app-ssg/[slug]/page.js'))
await fs.writeFile(
path.join(__dirname, '../app/app-ssg/[slug]/page.js'),
`
export function generateStaticParams() {
return [
{ slug: 'post-1' },
{ slug: 'post-2' },
]
}
export default function Page() {
return <p>ssg page</p>
}
`
)
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
const event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event1).toMatch(/"staticPropsPageCount": 2/)
expect(event1).toMatch(/"serverPropsPageCount": 2/)
expect(event1).toMatch(/"ssrPageCount": 3/)
expect(event1).toMatch(/"staticPageCount": 4/)
expect(event1).toMatch(/"totalPageCount": 11/)
expect(event1).toMatch(/"totalAppPagesCount": 4/)
expect(event1).toMatch(/"serverAppPagesCount": 2/)
expect(event1).toMatch(/"edgeRuntimeAppCount": 1/)
expect(event1).toMatch(/"edgeRuntimePagesCount": 2/)
const event2 = /NEXT_BUILD_COMPLETED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
expect(event2).toMatch(/"totalAppPagesCount": 4/)
} finally {
await teardown()
}
})
it('detect reportWebVitals correctly for `next build`', async () => {
// Case 1: When _app.js does not exist.
let build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
let event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/
.exec(build.stderr)
.pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
// Case 2: When _app.js exist with reportWebVitals function.
await fs.utimes(
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
new Date(),
new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withreportwebvitals.empty')
)
event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(build.stderr).pop()
expect(event1).toMatch(/hasReportWebVitals.*?true/)
// Case 3: When _app.js exist without reportWebVitals function.
await fs.utimes(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
new Date(),
new Date()
)
await fs.rename(
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty'),
path.join(appDir, 'pages', '_app.js')
)
build = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
await fs.rename(
path.join(appDir, 'pages', '_app.js'),
path.join(appDir, 'pages', '_app_withoutreportwebvitals.empty')
)
event1 = /NEXT_BUILD_OPTIMIZED[\s\S]+?{([\s\S]+?)}/.exec(build.stderr).pop()
expect(event1).toMatch(/hasReportWebVitals.*?false/)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment