@@ -214,12 +214,35 @@ function spawnProc (filename, options = {}, stdioHandler, stderrHandler) {
214214 } ) )
215215}
216216
217+ async function execHelper ( command , options ) {
218+ /* eslint-disable no-console */
219+ try {
220+ console . log ( 'Exec START: ' , command )
221+ await exec ( command , options )
222+ console . log ( 'Exec SUCCESS: ' , command )
223+ } catch ( error ) {
224+ console . error ( 'Exec ERROR: ' , command , error )
225+ if ( command . startsWith ( 'yarn' ) ) {
226+ try {
227+ console . log ( 'Exec RETRY START: ' , command )
228+ await exec ( command , options )
229+ console . log ( 'Exec RETRY SUCESS: ' , command )
230+ } catch ( retryError ) {
231+ console . error ( 'Exec RETRY ERROR' , command , retryError )
232+ }
233+ throw error
234+ }
235+ }
236+ /* eslint-enable no-console */
237+ }
238+
217239/**
218240 * @param {string[] } dependencies
219241 * @param {boolean } isGitRepo
220242 * @param {string[] } integrationTestsPaths
221243 * @param {string } [followUpCommand]
222244 */
245+
223246async function createSandbox ( dependencies = [ ] , isGitRepo = false ,
224247 integrationTestsPaths = [ './integration-tests/*' ] , followUpCommand ) {
225248 const cappedDependencies = dependencies . map ( dep => {
@@ -241,8 +264,8 @@ async function createSandbox (dependencies = [], isGitRepo = false,
241264 // yarn-linked into dd-trace and want to run the integration tests against them.
242265
243266 // Link dd-trace to itself, then...
244- await exec ( 'yarn link' )
245- await exec ( 'yarn link dd-trace' )
267+ await execHelper ( 'yarn link' )
268+ await execHelper ( 'yarn link dd-trace' )
246269 // ... run the tests in the current directory.
247270 return { folder : path . join ( process . cwd ( ) , 'integration-tests' ) , remove : async ( ) => { } }
248271 }
@@ -254,49 +277,45 @@ async function createSandbox (dependencies = [], isGitRepo = false,
254277 const preferOfflineFlag = process . env . OFFLINE === '1' || process . env . OFFLINE === 'true' ? ' --prefer-offline' : ''
255278 const addCommand = `yarn add ${ allDependencies . join ( ' ' ) } --ignore-engines${ preferOfflineFlag } `
256279 const addOptions = { cwd : folder , env : restOfEnv }
257- await exec ( `npm pack --silent --pack-destination ${ folder } ` , { env : restOfEnv } ) // TODO: cache this
280+ await execHelper ( `npm pack --silent --pack-destination ${ folder } ` , { env : restOfEnv } ) // TODO: cache this
258281
259- try {
260- await exec ( addCommand , addOptions )
261- } catch ( e ) { // retry in case of server error from registry
262- await exec ( addCommand , addOptions )
263- }
282+ await execHelper ( addCommand , addOptions )
264283
265284 for ( const path of integrationTestsPaths ) {
266285 if ( process . platform === 'win32' ) {
267- await exec ( `Copy-Item -Recurse -Path "${ path } " -Destination "${ folder } "` , { shell : 'powershell.exe' } )
286+ await execHelper ( `Copy-Item -Recurse -Path "${ path } " -Destination "${ folder } "` , { shell : 'powershell.exe' } )
268287 } else {
269- await exec ( `cp -R ${ path } ${ folder } ` )
288+ await execHelper ( `cp -R ${ path } ${ folder } ` )
270289 }
271290 }
272291 if ( process . platform === 'win32' ) {
273292 // On Windows, we can only sync entire filesystem volume caches.
274- await exec ( `Write-VolumeCache ${ folder [ 0 ] } ` , { shell : 'powershell.exe' } )
293+ await execHelper ( `Write-VolumeCache ${ folder [ 0 ] } ` , { shell : 'powershell.exe' } )
275294 } else {
276- await exec ( `sync ${ folder } ` )
295+ await execHelper ( `sync ${ folder } ` )
277296 }
278297
279298 if ( followUpCommand ) {
280- await exec ( followUpCommand , { cwd : folder , env : restOfEnv } )
299+ await execHelper ( followUpCommand , { cwd : folder , env : restOfEnv } )
281300 }
282301
283302 if ( isGitRepo ) {
284- await exec ( 'git init' , { cwd : folder } )
303+ await execHelper ( 'git init' , { cwd : folder } )
285304 await fs . writeFile ( path . join ( folder , '.gitignore' ) , 'node_modules/' , { flush : true } )
286- await exec ( 'git config user.email "[email protected] "' , { cwd :
folder } ) 287- await exec ( 'git config user.name "John Doe"' , { cwd : folder } )
288- await exec ( 'git config commit.gpgsign false' , { cwd : folder } )
305+ await execHelper ( 'git config user.email "[email protected] "' , { cwd :
folder } ) 306+ await execHelper ( 'git config user.name "John Doe"' , { cwd : folder } )
307+ await execHelper ( 'git config commit.gpgsign false' , { cwd : folder } )
289308
290309 // Create a unique local bare repo for this test
291310 const localRemotePath = path . join ( folder , '..' , `${ path . basename ( folder ) } -remote.git` )
292311 if ( ! existsSync ( localRemotePath ) ) {
293- await exec ( `git init --bare ${ localRemotePath } ` )
312+ await execHelper ( `git init --bare ${ localRemotePath } ` )
294313 }
295314
296- await exec ( 'git add -A' , { cwd : folder } )
297- await exec ( 'git commit -m "first commit" --no-verify' , { cwd : folder } )
298- await exec ( `git remote add origin ${ localRemotePath } ` , { cwd : folder } )
299- await exec ( 'git push --set-upstream origin HEAD' , { cwd : folder } )
315+ await execHelper ( 'git add -A' , { cwd : folder } )
316+ await execHelper ( 'git commit -m "first commit" --no-verify' , { cwd : folder } )
317+ await execHelper ( `git remote add origin ${ localRemotePath } ` , { cwd : folder } )
318+ await execHelper ( 'git push --set-upstream origin HEAD' , { cwd : folder } )
300319 }
301320
302321 return {
0 commit comments