diff --git a/tests/netlify-deploy.ts b/tests/netlify-deploy.ts index bddec44fd1..f5cc7ced43 100644 --- a/tests/netlify-deploy.ts +++ b/tests/netlify-deploy.ts @@ -36,6 +36,8 @@ export class NextDeployInstance extends NextInstance { private _buildId: string private _deployId: string private _shouldDeleteDeploy: boolean = false + private _isCurrentlyDeploying: boolean = false + private _deployOutput: string = '' public get buildId() { // get deployment ID via fetch since we can't access @@ -52,6 +54,8 @@ export class NextDeployInstance extends NextInstance { return } + this._isCurrentlyDeploying = true + const setupStartTime = Date.now() // create the test site @@ -131,7 +135,7 @@ export class NextDeployInstance extends NextInstance { : testName const deployAlias = 'vercel-next-e2e' - const deployRes = await execa( + const deployResPromise = execa( 'npx', ['netlify', 'deploy', '--build', '--message', deployTitle ?? '', '--alias', deployAlias], { @@ -140,7 +144,18 @@ export class NextDeployInstance extends NextInstance { }, ) + const handleOutput = (chunk) => { + this._deployOutput += chunk + } + + deployResPromise.stdout.on('data', handleOutput) + deployResPromise.stderr.on('data', handleOutput) + + const deployRes = await deployResPromise + if (deployRes.exitCode !== 0) { + // clear deploy output to avoid printing it again in destroy() + this._deployOutput = '' throw new Error( `Failed to deploy project (${deployRes.exitCode}) ${deployRes.stdout} ${deployRes.stderr} `, ) @@ -168,7 +183,7 @@ export class NextDeployInstance extends NextInstance { require('console').log(`Logs: ${buildLogsUrl}`) } } catch (err) { - console.error(err) + require('console').error(err) throw new Error(`Failed to parse deploy output: ${deployRes.stdout}`) } @@ -181,6 +196,8 @@ export class NextDeployInstance extends NextInstance { require('console').log(`Got buildId: ${this._buildId}`) require('console').log(`Setup time: ${(Date.now() - setupStartTime) / 1000.0}s`) + + this._isCurrentlyDeploying = false } public async destroy(): Promise { @@ -205,6 +222,13 @@ export class NextDeployInstance extends NextInstance { } } + if (this._isCurrentlyDeploying) { + require('console').log('Destroying before deployment finished.') + if (this._deployOutput) { + require('console').log(`Deploy logs so far:\n\n${this._deployOutput}\n\n`) + } + } + await super.destroy() }