Skip to content

Commit d3d353d

Browse files
committed
test: log deploy output on timed out deploys
1 parent 1f8ae92 commit d3d353d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

tests/netlify-deploy.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export class NextDeployInstance extends NextInstance {
3636
private _buildId: string
3737
private _deployId: string
3838
private _shouldDeleteDeploy: boolean = false
39+
private _isCurrentlyDeploying: boolean = false
40+
private _deployOutput: string = ''
3941

4042
public get buildId() {
4143
// get deployment ID via fetch since we can't access
@@ -52,6 +54,8 @@ export class NextDeployInstance extends NextInstance {
5254
return
5355
}
5456

57+
this._isCurrentlyDeploying = true
58+
5559
const setupStartTime = Date.now()
5660

5761
// create the test site
@@ -131,7 +135,7 @@ export class NextDeployInstance extends NextInstance {
131135
: testName
132136
const deployAlias = 'vercel-next-e2e'
133137

134-
const deployRes = await execa(
138+
const deployResPromise = execa(
135139
'npx',
136140
['netlify', 'deploy', '--build', '--message', deployTitle ?? '', '--alias', deployAlias],
137141
{
@@ -140,6 +144,17 @@ export class NextDeployInstance extends NextInstance {
140144
},
141145
)
142146

147+
function handleOutput(chunk) {
148+
const output = chunk.toString()
149+
this._deployOutput += output
150+
process.stdout.write(chunk)
151+
}
152+
153+
deployResPromise.stdout.on('data', handleOutput)
154+
deployResPromise.stderr.on('data', handleOutput)
155+
156+
const deployRes = await deployResPromise
157+
143158
if (deployRes.exitCode !== 0) {
144159
throw new Error(
145160
`Failed to deploy project (${deployRes.exitCode}) ${deployRes.stdout} ${deployRes.stderr} `,
@@ -168,7 +183,7 @@ export class NextDeployInstance extends NextInstance {
168183
require('console').log(`Logs: ${buildLogsUrl}`)
169184
}
170185
} catch (err) {
171-
console.error(err)
186+
require('console').error(err)
172187
throw new Error(`Failed to parse deploy output: ${deployRes.stdout}`)
173188
}
174189

@@ -181,6 +196,8 @@ export class NextDeployInstance extends NextInstance {
181196

182197
require('console').log(`Got buildId: ${this._buildId}`)
183198
require('console').log(`Setup time: ${(Date.now() - setupStartTime) / 1000.0}s`)
199+
200+
this._isCurrentlyDeploying = false
184201
}
185202

186203
public async destroy(): Promise<void> {
@@ -205,6 +222,13 @@ export class NextDeployInstance extends NextInstance {
205222
}
206223
}
207224

225+
if (this._isCurrentlyDeploying) {
226+
require('console').log('Destroying before deployment finished.')
227+
if (this._deployOutput) {
228+
require('console').log(`Deploy logs so far:\n\n${this._deployOutput}\n\n`)
229+
}
230+
}
231+
208232
await super.destroy()
209233
}
210234

0 commit comments

Comments
 (0)