Skip to content

Commit ba1d3b3

Browse files
authored
test: next.js repo tests adjustments (#3168)
1 parent 67775ff commit ba1d3b3

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

.github/workflows/test-e2e.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ jobs:
124124
echo "version=$NODE_VERSION" >> $GITHUB_OUTPUT
125125
echo "Node version for 'next@${{ matrix.version_spec.selector }}' is '$NODE_VERSION'"
126126
127+
- name: Decide default bundler
128+
id: decide-default-bundler
129+
shell: bash
130+
run: |
131+
# we run tests with default bundler for given Next.js version
132+
# some tests have webpack/turbopack specific assertions or skips
133+
# so we need to set IS_WEBPACK_TEST, IS_TURBOPACK_TEST env vars accordingly
134+
# to ensure tests assert behavior of the default bundler
135+
DEFAULT_BUNDLER="webpack"
136+
if [ "${{ matrix.version_spec.selector }}" = "canary" ]; then
137+
# this is not ideal, because we set turbopack default just when explicitly using canary tag as target
138+
# but next@canary are still on 15 major, so we can't yet use major version of resolved next version
139+
# as condition
140+
DEFAULT_BUNDLER="turbopack"
141+
fi
142+
echo "default_bundler=$DEFAULT_BUNDLER" >> $GITHUB_OUTPUT
143+
echo "Default bundler for 'next@${{ matrix.version_spec.selector }}' is '$DEFAULT_BUNDLER'"
144+
127145
- name: setup node
128146
uses: actions/setup-node@v5
129147
with:
@@ -218,6 +236,9 @@ jobs:
218236
# one job may wait for deploys in other jobs (only one deploy may be in progress for
219237
# a given alias at a time), resulting in cascading timeouts.
220238
DEPLOY_ALIAS: vercel-next-e2e-${{ matrix.version_spec.selector }}-${{ matrix.group }}
239+
NEXT_RESOLVED_VERSION: ${{ matrix.version_spec.version }}
240+
IS_WEBPACK_TEST: ${{ steps.decide-default-bundler.outputs.default_bundler == 'webpack' && '1' || '' }}
241+
IS_TURBOPACK_TEST: ${{ steps.decide-default-bundler.outputs.default_bundler == 'turbopack' && '1' || '' }}
221242
run: node run-tests.js -g ${{ matrix.group }}/${{ needs.setup.outputs.total }} -c ${TEST_CONCURRENCY} --type e2e
222243
working-directory: ${{ env.next-path }}
223244

@@ -226,7 +247,7 @@ jobs:
226247
uses: actions/upload-artifact@v4
227248
with:
228249
name: test-result-${{matrix.version_spec.selector}}-${{ matrix.group }}
229-
path: ${{ env.next-path }}/test/test-junit-report/*.xml
250+
path: ${{ env.next-path }}/test/${{steps.decide-default-bundler.outputs.default_bundler == 'turbopack' && 'turbopack-test-junit-report' || 'test-junit-report'}}/*.xml
230251
publish-test-results:
231252
name: 'E2E Test Summary (${{matrix.version_spec.selector}})'
232253
needs:

tests/netlify-deploy.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'fs-extra'
44
import { Span } from 'next/src/trace'
55
import { tmpdir } from 'node:os'
66
import path from 'path'
7+
import { satisfies as satisfiesVersionRange } from 'semver'
78
import { NextInstance } from './base'
89

910
async function packNextRuntimeImpl() {
@@ -58,6 +59,34 @@ export class NextDeployInstance extends NextInstance {
5859

5960
const setupStartTime = Date.now()
6061

62+
const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime()
63+
64+
this.dependencies = {
65+
...(this.dependencies || {}),
66+
// add the runtime package as a dependency
67+
[runtimePackageName]: `file:${runtimePackageTarballPath}`,
68+
}
69+
70+
if (
71+
typeof this.files === 'string' &&
72+
this.files.includes('back-forward-cache') &&
73+
process.env.NEXT_RESOLVED_VERSION &&
74+
satisfiesVersionRange(process.env.NEXT_RESOLVED_VERSION, '<=15.5.4')
75+
) {
76+
require('console').log('Pinning @types/react(-dom) for back-forward-cache test fixture')
77+
// back-forward-cache test fixture is failing types checking because:
78+
// - @types/react(-dom) types are not pinned
79+
// - fixture uses react `unstable_Activity` export which since fixture was introduced is no longer unstable
80+
// and types were updated for that and no longer provide types for that export (instead provide for `Activity`)
81+
// this adds the pinning of types to version of types that still had `unstable_Activity` type
82+
this.dependencies['@types/react'] = '19.1.1'
83+
this.dependencies['@types/react-dom'] = '19.1.2'
84+
}
85+
86+
if (!this.buildCommand && this.buildArgs && this.buildArgs.length > 0) {
87+
this.buildCommand = `next build ${this.buildArgs.join(' ')}`
88+
}
89+
6190
// create the test site
6291
await super.createTestDir({ parentSpan, skipInstall: true })
6392

@@ -70,10 +99,13 @@ export class NextDeployInstance extends NextInstance {
7099
await fs.rename(nodeModules, nodeModulesBak)
71100
}
72101

73-
const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime()
74-
75102
// install dependencies
76-
await execa('npm', ['i', runtimePackageTarballPath, '--legacy-peer-deps'], {
103+
// --force is used to match behavior of `pnpm install --strict-peer-dependencies=false` used by Vercel
104+
// there is a test fixture that have `@babel/preset-flow` as a dependency which has a peer dependency of `@babel/core@^7.0.0-0`,
105+
// but `@babel/core` is not specified as dependency, so we need to automatically attempt to install peer dependencies
106+
// but also not fail in case of peer dependency versions not matching for other fixtures, so `--legacy-peer-deps` is not good option here
107+
// https://github.com/vercel/next.js/blob/7453d200579512a6574f9c53edd716e5cc01615c/test/e2e/babel/index.test.js#L7-L9
108+
await execa('npm', ['install', '--force'], {
77109
cwd: this.testDir,
78110
stdio: 'inherit',
79111
})

0 commit comments

Comments
 (0)