1+ import os from 'os'
2+ import path from 'path'
13import execa from 'execa'
4+ import fs from 'fs-extra'
25import { NextInstance } from './base'
36import {
47 TEST_PROJECT_NAME ,
@@ -23,16 +26,27 @@ export class NextDeployInstance extends NextInstance {
2326 // ensure Vercel CLI is installed
2427 try {
2528 const res = await execa ( 'vercel' , [ '--version' ] )
26- console . log ( `Using Vercel CLI version:` , res . stdout )
29+ require ( ' console' ) . log ( `Using Vercel CLI version:` , res . stdout )
2730 } catch ( _ ) {
28- console . log ( `Installing Vercel CLI` )
31+ require ( ' console' ) . log ( `Installing Vercel CLI` )
2932 await execa ( 'npm' , [ 'i' , '-g' , 'vercel@latest' ] , {
3033 stdio : 'inherit' ,
3134 } )
3235 }
3336 const vercelFlags = [ '--scope' , TEST_TEAM_NAME ]
3437 const vercelEnv = { ...process . env , TOKEN : TEST_TOKEN }
35- console . log ( `Linking project at ${ this . testDir } ` )
38+
39+ // create auth file in CI
40+ if ( process . env . NEXT_TEST_JOB ) {
41+ const vcConfigDir = path . join ( os . homedir ( ) , '.vercel' )
42+ await fs . ensureDir ( vcConfigDir )
43+ await fs . writeFile (
44+ path . join ( vcConfigDir , 'auth.json' ) ,
45+ JSON . stringify ( { token : TEST_TOKEN } )
46+ )
47+ vercelFlags . push ( '--global-config' , vcConfigDir )
48+ }
49+ require ( 'console' ) . log ( `Linking project at ${ this . testDir } ` )
3650
3751 // link the project
3852 const linkRes = await execa (
@@ -49,7 +63,7 @@ export class NextDeployInstance extends NextInstance {
4963 `Failed to link project ${ linkRes . stdout } ${ linkRes . stderr } (${ linkRes . exitCode } )`
5064 )
5165 }
52- console . log ( `Deploying project at ${ this . testDir } ` )
66+ require ( ' console' ) . log ( `Deploying project at ${ this . testDir } ` )
5367
5468 const deployRes = await execa (
5569 'vercel' ,
@@ -79,21 +93,21 @@ export class NextDeployInstance extends NextInstance {
7993 this . _url = deployRes . stdout
8094 this . _parsedUrl = new URL ( this . _url )
8195
82- console . log ( `Deployment URL: ${ this . _url } ` )
96+ require ( ' console' ) . log ( `Deployment URL: ${ this . _url } ` )
8397 const buildIdUrl = `${ this . _url } ${
8498 this . basePath || ''
8599 } /_next/static/__BUILD_ID`
86100
87101 const buildIdRes = await fetch ( buildIdUrl )
88102
89103 if ( ! buildIdRes . ok ) {
90- console . error (
104+ require ( ' console' ) . error (
91105 `Failed to load buildId ${ buildIdUrl } (${ buildIdRes . status } )`
92106 )
93107 }
94108 this . _buildId = ( await buildIdRes . text ( ) ) . trim ( )
95109
96- console . log ( `Got buildId: ${ this . _buildId } ` )
110+ require ( ' console' ) . log ( `Got buildId: ${ this . _buildId } ` )
97111
98112 const cliOutputRes = await fetch (
99113 `https://vercel.com/api/v1/deployments/${ this . _parsedUrl . hostname } /events?builds=1&direction=backward` ,
0 commit comments