Skip to content

Commit 645f220

Browse files
committed
test: collect build logs in Vercel e2e tests (like we do in our own e2e tests)
1 parent 960ef04 commit 645f220

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

tests/netlify-deploy.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import { tmpdir } from 'node:os'
66
import path from 'path'
77
import { NextInstance } from './base'
88

9-
type NetlifyDeployResponse = {
10-
name: string
11-
site_id: string
12-
site_name: string
13-
deploy_id: string
14-
deploy_url: string
15-
logs: string
16-
}
17-
189
async function packNextRuntimeImpl() {
1910
const runtimePackDir = await fs.mkdtemp(path.join(tmpdir(), 'opennextjs-netlify-pack'))
2011

@@ -133,7 +124,7 @@ export class NextDeployInstance extends NextInstance {
133124

134125
const deployRes = await execa(
135126
'npx',
136-
['netlify', 'deploy', '--build', '--json', '--message', deployTitle ?? ''],
127+
['netlify', 'deploy', '--build', '--message', deployTitle ?? ''],
137128
{
138129
cwd: this.testDir,
139130
reject: false,
@@ -142,17 +133,29 @@ export class NextDeployInstance extends NextInstance {
142133

143134
if (deployRes.exitCode !== 0) {
144135
throw new Error(
145-
`Failed to deploy project ${deployRes.stdout} ${deployRes.stderr} (${deployRes.exitCode})`,
136+
`Failed to deploy project (${deployRes.exitCode}) ${deployRes.stdout} ${deployRes.stderr} `,
146137
)
147138
}
148139

149140
try {
150-
const data: NetlifyDeployResponse = JSON.parse(deployRes.stdout)
151-
this._url = data.deploy_url
141+
const [url] = new RegExp(/https:.+\.netlify\.app/gm).exec(deployRes.stdout) || []
142+
if (!url) {
143+
throw new Error('Could not extract the URL from the build logs')
144+
}
145+
const [deployID] = new URL(url).host.split('--')
146+
this._url = url
152147
this._parsedUrl = new URL(this._url)
153-
this._deployId = data.deploy_id
154-
require('console').log(`Deployment URL: ${data.deploy_url}`)
155-
require('console').log(`Logs: ${data.logs}`)
148+
this._deployId = deployID
149+
this._cliOutput = deployRes.stdout + deployRes.stdout
150+
require('console').log(`Deployment URL: ${this._url}`)
151+
152+
const [buildLogsUrl] =
153+
new RegExp(/https:\/\/app\.netlify\.com\/sites\/.+\/deploys\/[0-9a-f]+/gm).exec(
154+
deployRes.stdout,
155+
) || []
156+
if (buildLogsUrl) {
157+
require('console').log(`Logs: ${buildLogsUrl}`)
158+
}
156159
} catch (err) {
157160
console.error(err)
158161
throw new Error(`Failed to parse deploy output: ${deployRes.stdout}`)

0 commit comments

Comments
 (0)