@@ -35,6 +35,7 @@ export class NextDeployInstance extends NextInstance {
3535 private _cliOutput : string
3636 private _buildId : string
3737 private _deployId : string
38+ private _shouldDeleteDeploy : boolean = false
3839
3940 public get buildId ( ) {
4041 // get deployment ID via fetch since we can't access
@@ -50,6 +51,9 @@ export class NextDeployInstance extends NextInstance {
5051 this . _buildId = process . env . BUILD_ID
5152 return
5253 }
54+
55+ const setupStartTime = Date . now ( )
56+
5357 // create the test site
5458 await super . createTestDir ( { parentSpan, skipInstall : true } )
5559
@@ -146,6 +150,7 @@ export class NextDeployInstance extends NextInstance {
146150 this . _url = url
147151 this . _parsedUrl = new URL ( this . _url )
148152 this . _deployId = deployID
153+ this . _shouldDeleteDeploy = ! process . env . NEXT_TEST_SKIP_CLEANUP
149154 this . _cliOutput = deployRes . stdout + deployRes . stderr
150155 require ( 'console' ) . log ( `Deployment URL: ${ this . _url } ` )
151156
@@ -169,6 +174,32 @@ export class NextDeployInstance extends NextInstance {
169174 ) . trim ( )
170175
171176 require ( 'console' ) . log ( `Got buildId: ${ this . _buildId } ` )
177+ require ( 'console' ) . log ( `Setup time: ${ ( Date . now ( ) - setupStartTime ) / 1000.0 } s` )
178+ }
179+
180+ public async destroy ( ) : Promise < void > {
181+ if ( this . _shouldDeleteDeploy ) {
182+ require ( 'console' ) . log ( `Deleting project with deploy_id ${ this . _deployId } ` )
183+
184+ const deleteResponse = await execa ( 'npx' , [
185+ 'ntl' ,
186+ 'api' ,
187+ 'deleteDeploy' ,
188+ '--data' ,
189+ `{ "deploy_id": "${ this . _deployId } " }` ,
190+ ] )
191+
192+ if ( deleteResponse . exitCode !== 0 ) {
193+ require ( 'console' ) . error (
194+ `Failed to delete deploy ${ deleteResponse . stdout } ${ deleteResponse . stderr } (${ deleteResponse . exitCode } )` ,
195+ )
196+ } else {
197+ require ( 'console' ) . log ( `Successfully deleted deploy with deploy_id ${ this . _deployId } ` )
198+ this . _shouldDeleteDeploy = false
199+ }
200+ }
201+
202+ await super . destroy ( )
172203 }
173204
174205 public get cliOutput ( ) {
0 commit comments