Unverified Commit e23dac0c authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

fix: added support for tests to add resolutions for deps (#55398)

Some tests may depend on `latest` to help us catch problems earlier. This adds support for the `resolutions` field for tests to allow pinning of deps that may be problematic upstream.
parent cd1a50f1
...@@ -22,6 +22,12 @@ createNextDescribe( ...@@ -22,6 +22,12 @@ createNextDescribe(
'styled-components': 'latest', 'styled-components': 'latest',
'server-only': 'latest', 'server-only': 'latest',
}, },
resolutions: {
'@babel/core': '7.22.18',
'@babel/parser': '7.22.16',
'@babel/types': '7.22.17',
'@babel/traverse': '7.22.18',
},
}, },
({ next, isNextDev, isNextStart, isTurbopack }) => { ({ next, isNextDev, isNextStart, isTurbopack }) => {
if (isNextDev && !isTurbopack) { if (isNextDev && !isTurbopack) {
......
...@@ -31,6 +31,7 @@ async function setPnpmResolutionMode(cwd) { ...@@ -31,6 +31,7 @@ async function setPnpmResolutionMode(cwd) {
async function createNextInstall({ async function createNextInstall({
parentSpan = null, parentSpan = null,
dependencies = null, dependencies = null,
resolutions = null,
installCommand = null, installCommand = null,
packageJson = {}, packageJson = {},
dirSuffix = '', dirSuffix = '',
...@@ -148,6 +149,8 @@ async function createNextInstall({ ...@@ -148,6 +149,8 @@ async function createNextInstall({
...packageJson, ...packageJson,
dependencies: combinedDependencies, dependencies: combinedDependencies,
private: true, private: true,
// Add resolutions if provided.
...(resolutions ? { resolutions } : {}),
}, },
null, null,
2 2
...@@ -158,7 +161,10 @@ async function createNextInstall({ ...@@ -158,7 +161,10 @@ async function createNextInstall({
if (installCommand) { if (installCommand) {
const installString = const installString =
typeof installCommand === 'function' typeof installCommand === 'function'
? installCommand({ dependencies: combinedDependencies }) ? installCommand({
dependencies: combinedDependencies,
resolutions,
})
: installCommand : installCommand
console.log('running install command', installString) console.log('running install command', installString)
......
...@@ -28,6 +28,7 @@ export type PackageJson = { ...@@ -28,6 +28,7 @@ export type PackageJson = {
export interface NextInstanceOpts { export interface NextInstanceOpts {
files: FileRef | string | { [filename: string]: string | FileRef } files: FileRef | string | { [filename: string]: string | FileRef }
dependencies?: { [name: string]: string } dependencies?: { [name: string]: string }
resolutions?: { [name: string]: string }
packageJson?: PackageJson packageJson?: PackageJson
nextConfig?: NextConfig nextConfig?: NextConfig
installCommand?: InstallCommand installCommand?: InstallCommand
...@@ -56,6 +57,7 @@ export class NextInstance { ...@@ -56,6 +57,7 @@ export class NextInstance {
protected buildCommand?: string protected buildCommand?: string
protected startCommand?: string protected startCommand?: string
protected dependencies?: PackageJson['dependencies'] = {} protected dependencies?: PackageJson['dependencies'] = {}
protected resolutions?: PackageJson['resolutions']
protected events: { [eventName: string]: Set<any> } = {} protected events: { [eventName: string]: Set<any> } = {}
public testDir: string public testDir: string
protected isStopping: boolean = false protected isStopping: boolean = false
...@@ -168,6 +170,7 @@ export class NextInstance { ...@@ -168,6 +170,7 @@ export class NextInstance {
process.env.NEXT_TEST_VERSION || process.env.NEXT_TEST_VERSION ||
require('next/package.json').version, require('next/package.json').version,
}, },
...(this.resolutions ? { resolutions: this.resolutions } : {}),
scripts: { scripts: {
// since we can't get the build id as a build artifact, make it // since we can't get the build id as a build artifact, make it
// available under the static files // available under the static files
...@@ -196,6 +199,7 @@ export class NextInstance { ...@@ -196,6 +199,7 @@ export class NextInstance {
this.testDir = await createNextInstall({ this.testDir = await createNextInstall({
parentSpan: rootSpan, parentSpan: rootSpan,
dependencies: finalDependencies, dependencies: finalDependencies,
resolutions: this.resolutions ?? null,
installCommand: this.installCommand, installCommand: this.installCommand,
packageJson: this.packageJson, packageJson: this.packageJson,
dirSuffix: this.dirSuffix, dirSuffix: this.dirSuffix,
......
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