Skip to content

Commit 8433df5

Browse files
authored
test: pack and install runtime when running Next.js e2e tests (#2554)
1 parent 2b71395 commit 8433df5

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-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)

0 commit comments

Comments
 (0)