Skip to content

test: pack and install runtime when running Next.js e2e tests #2554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions tests/netlify-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import execa from 'execa'
import fs from 'fs-extra'
import { Span } from 'next/src/trace'
import { tmpdir } from 'node:os'
import path from 'path'
import { NextInstance } from './base'

Expand All @@ -14,6 +15,31 @@ type NetlifyDeployResponse = {
logs: string
}

async function packNextRuntimeImpl() {
const runtimePackDir = await fs.mkdtemp(path.join(tmpdir(), 'next-runtime-pack'))

const { stdout } = await execa(
'npm',
['pack', '--json', '--ignore-scripts', `--pack-destination=${runtimePackDir}`],
{ cwd: process.env.RUNTIME_DIR || `${process.cwd()}/../next-runtime` },
)
const [{ filename, name }] = JSON.parse(stdout)

return {
runtimePackageName: name,
runtimePackageTarballPath: path.join(runtimePackDir, filename),
}
}

let packNextRuntimePromise: ReturnType<typeof packNextRuntimeImpl> | null = null
function packNextRuntime() {
if (!packNextRuntimePromise) {
packNextRuntimePromise = packNextRuntimeImpl()
}

return packNextRuntimePromise
}

export class NextDeployInstance extends NextInstance {
private _cliOutput: string
private _buildId: string
Expand Down Expand Up @@ -45,8 +71,10 @@ export class NextDeployInstance extends NextInstance {
await fs.rename(nodeModules, nodeModulesBak)
}

const { runtimePackageName, runtimePackageTarballPath } = await packNextRuntime()

// install dependencies
await execa('npm', ['i', '--legacy-peer-deps'], {
await execa('npm', ['i', runtimePackageTarballPath, '--legacy-peer-deps'], {
cwd: this.testDir,
stdio: 'inherit',
})
Expand All @@ -68,10 +96,7 @@ export class NextDeployInstance extends NextInstance {
publish = ".next"

[[plugins]]
package = "${path.relative(
this.testDir,
process.env.RUNTIME_DIR || `${process.cwd()}/../next-runtime`,
)}"
package = "${runtimePackageName}"
`

await fs.writeFile(path.join(this.testDir, 'netlify.toml'), toml)
Expand Down
Loading