Skip to content

Commit

Permalink
test: pack and install runtime when running Next.js e2e tests (#2554)
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored Jul 25, 2024
1 parent 2b71395 commit 8433df5
Showing 1 changed file with 30 additions and 5 deletions.
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

0 comments on commit 8433df5

Please sign in to comment.