Skip to content

Commit 2bd7c8f

Browse files
authored
Merge branch 'main' into rs/frp-761-imiddleware-locale
2 parents af173a6 + b6ccbb5 commit 2bd7c8f

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

tests/netlify-deploy.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import execa from 'execa'
33
import fs from 'fs-extra'
44
import { Span } from 'next/src/trace'
5+
import { tmpdir } from 'node:os'
56
import path from 'path'
67
import { NextInstance } from './base'
78

@@ -14,6 +15,31 @@ type NetlifyDeployResponse = {
1415
logs: string
1516
}
1617

18+
async function packNextRuntimeImpl() {
19+
const runtimePackDir = await fs.mkdtemp(path.join(tmpdir(), 'next-runtime-pack'))
20+
21+
const { stdout } = await execa(
22+
'npm',
23+
['pack', '--json', '--ignore-scripts', `--pack-destination=${runtimePackDir}`],
24+
{ cwd: process.env.RUNTIME_DIR || `${process.cwd()}/../next-runtime` },
25+
)
26+
const [{ filename, name }] = JSON.parse(stdout)
27+
28+
return {
29+
runtimePackageName: name,
30+
runtimePackageTarballPath: path.join(runtimePackDir, filename),
31+
}
32+
}
33+
34+
let packNextRuntimePromise: ReturnType<typeof packNextRuntimeImpl> | null = null
35+
function packNextRuntime() {
36+
if (!packNextRuntimePromise) {
37+
packNextRuntimePromise = packNextRuntimeImpl()
38+
}
39+
40+
return packNextRuntimePromise
41+
}
42+
1743
export class NextDeployInstance extends NextInstance {
1844
private _cliOutput: string
1945
private _buildId: string
@@ -45,8 +71,10 @@ export class NextDeployInstance extends NextInstance {
4571
await fs.rename(nodeModules, nodeModulesBak)
4672
}
4773

74+
const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime()
75+
4876
// install dependencies
49-
await execa('npm', ['i', '--legacy-peer-deps'], {
77+
await execa('npm', ['i', runtimePackageTarballPath, '--legacy-peer-deps'], {
5078
cwd: this.testDir,
5179
stdio: 'inherit',
5280
})
@@ -68,10 +96,7 @@ export class NextDeployInstance extends NextInstance {
6896
publish = ".next"
6997
7098
[[plugins]]
71-
package = "${path.relative(
72-
this.testDir,
73-
process.env.RUNTIME_DIR || `${process.cwd()}/../next-runtime`,
74-
)}"
99+
package = "${runtimePackageName}"
75100
`
76101

77102
await fs.writeFile(path.join(this.testDir, 'netlify.toml'), toml)

tests/utils/fixture.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ async function installDependencies(cwd: string) {
5454
export const getFixtureSourceDirectory = (fixture: string) =>
5555
fileURLToPath(new URL(`../fixtures/${fixture}`, import.meta.url))
5656

57+
// https://github.com/vercel/next.js/pull/67539 added more imports to "globals" modules which does have a side effect at import time
58+
// that defines NOT configurable global property ( https://github.com/vercel/next.js/blob/ba3959bb46f4d0e92403304579b8fb30d3ecc3d1/packages/next/src/server/web/globals.ts#L87-L107 ).
59+
// Running multiple fixtures in the same process then would evaluate copy of that module
60+
// and attempt to redefine that not configurable property which result in an error. We can't delete that property either, so
61+
// this "patch" to Object.defineProperty is making that property configurable when running our tests to avoid that error.
62+
const originalDefineProperty = Object.defineProperty
63+
Object.defineProperty = function (target, property, descriptor) {
64+
if (property === '__import_unsupported' && descriptor?.configurable === false) {
65+
descriptor.configurable = true
66+
}
67+
68+
return originalDefineProperty.call(this, target, property, descriptor)
69+
}
70+
5771
/**
5872
* Copies a fixture to a temp folder on the system and runs the tests inside.
5973
* @param fixture name of the folder inside the fixtures folder

0 commit comments

Comments
 (0)