@@ -538,3 +538,71 @@ it(`should handle parallel installs`, async () => {
538
538
] ) ;
539
539
} ) ;
540
540
} ) ;
541
+
542
+ it ( `should not override the package manager exit code` , async ( ) => {
543
+ await xfs . mktempPromise ( async cwd => {
544
+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
545
+ packageManager : `yarn@2.2.2` ,
546
+ } ) ;
547
+
548
+ const yarnPath = ppath . join ( npath . toPortablePath ( process . env . COREPACK_HOME ! ) , `yarn/2.2.2/yarn.js` as PortablePath ) ;
549
+
550
+ await xfs . mkdirPromise ( ppath . dirname ( yarnPath ) , { recursive : true } ) ;
551
+ await xfs . writeFilePromise ( yarnPath , `
552
+ process.exitCode = 42;
553
+ ` ) ;
554
+
555
+ await expect ( runCli ( cwd , [ `yarn` , `--version` ] ) ) . resolves . toMatchObject ( {
556
+ exitCode : 42 ,
557
+ stdout : `` ,
558
+ stderr : `` ,
559
+ } ) ;
560
+ } ) ;
561
+ } ) ;
562
+
563
+ it ( `should not override the package manager exit code when it throws` , async ( ) => {
564
+ await xfs . mktempPromise ( async cwd => {
565
+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
566
+ packageManager : `yarn@2.2.2` ,
567
+ } ) ;
568
+
569
+ const yarnPath = ppath . join ( npath . toPortablePath ( process . env . COREPACK_HOME ! ) , `yarn/2.2.2/yarn.js` as PortablePath ) ;
570
+
571
+ await xfs . mkdirPromise ( ppath . dirname ( yarnPath ) , { recursive : true } ) ;
572
+ await xfs . writeFilePromise ( yarnPath , `
573
+ process.exitCode = 42;
574
+ throw new Error('foo');
575
+ ` ) ;
576
+
577
+ await expect ( runCli ( cwd , [ `yarn` , `--version` ] ) ) . resolves . toMatchObject ( {
578
+ exitCode : 42 ,
579
+ stdout : expect . stringContaining ( `foo` ) ,
580
+ stderr : `` ,
581
+ } ) ;
582
+ } ) ;
583
+ } ) ;
584
+
585
+ it ( `should not set the exit code after successfully launching the package manager` , async ( ) => {
586
+ await xfs . mktempPromise ( async cwd => {
587
+ await xfs . writeJsonPromise ( ppath . join ( cwd , `package.json` as Filename ) , {
588
+ packageManager : `yarn@2.2.2` ,
589
+ } ) ;
590
+
591
+ const yarnPath = ppath . join ( npath . toPortablePath ( process . env . COREPACK_HOME ! ) , `yarn/2.2.2/yarn.js` as PortablePath ) ;
592
+
593
+ await xfs . mkdirPromise ( ppath . dirname ( yarnPath ) , { recursive : true } ) ;
594
+ await xfs . writeFilePromise ( yarnPath , `
595
+ process.once('beforeExit', () => {
596
+ if (process.exitCode === undefined) {
597
+ process.exitCode = 42;
598
+ }
599
+ });
600
+ ` ) ;
601
+
602
+ await expect ( runCli ( cwd , [ `yarn` , `--version` ] ) ) . resolves . toMatchObject ( {
603
+ exitCode : 42 ,
604
+ stdout : `` ,
605
+ stderr : `` ,
606
+ } ) ;
607
+ } ) ;
608
+ } ) ;
0 commit comments