@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
5
5
import process from 'node:process' ;
6
6
import { createRequire } from 'node:module' ;
7
7
import { expect } from 'esmocha' ;
8
- import { assert as sinonAssert , spy as sinonSpy , stub as sinonStub , fake as sinonFake } from 'sinon' ;
8
+ import { assert as sinonAssert , spy as sinonSpy , stub as sinonStub , fake as sinonFake , type SinonStub } from 'sinon' ;
9
9
import inquirer from 'inquirer' ;
10
10
import Generator from 'yeoman-generator' ;
11
11
import tempDirectory from 'temp-dir' ;
@@ -647,10 +647,17 @@ describe('RunContext', function () {
647
647
it ( 'provide arguments to the generator when passed as String' , async function ( ) {
648
648
ctx . withSpawnMock ( ) ;
649
649
Dummy . prototype . mockTask = async function ( ) {
650
- await this . spawnCommand ( 'foo' ) ;
651
- this . spawnCommandSync ( 'foo' ) ;
652
- await this . spawn ( 'foo' ) ;
653
- this . spawnSync ( 'foo' ) ;
650
+ const spawnCommandFoo = this . spawnCommand ( 'foo' ) ;
651
+ expect ( spawnCommandFoo ) . toMatchObject ( { stderr : expect . any ( Object ) , stdout : expect . any ( Object ) } ) ;
652
+ await expect ( spawnCommandFoo ) . resolves . toMatchObject ( { exitCode : 0 , stderr : '' , stdout : '' } ) ;
653
+
654
+ expect ( this . spawnCommandSync ( 'foo' ) ) . toMatchObject ( { exitCode : 0 , stderr : '' , stdout : '' } ) ;
655
+
656
+ const spawnFoo = this . spawn ( 'foo' ) ;
657
+ expect ( spawnFoo ) . toMatchObject ( { stderr : expect . any ( Object ) , stdout : expect . any ( Object ) } ) ;
658
+ await expect ( spawnFoo ) . resolves . toMatchObject ( { exitCode : 0 , stderr : '' , stdout : '' } ) ;
659
+
660
+ expect ( this . spawnSync ( 'foo' ) ) . toMatchObject ( { exitCode : 0 , stderr : '' , stdout : '' } ) ;
654
661
} ;
655
662
656
663
const result = await ctx . toPromise ( ) ;
@@ -659,6 +666,36 @@ describe('RunContext', function () {
659
666
assert . deepStrictEqual ( result . getSpawnArgsUsingDefaultImplementation ( ) [ 2 ] , [ 'spawn' , 'foo' ] ) ;
660
667
assert . deepStrictEqual ( result . getSpawnArgsUsingDefaultImplementation ( ) [ 3 ] , [ 'spawnSync' , 'foo' ] ) ;
661
668
} ) ;
669
+
670
+ it ( 'with callback' , async function ( ) {
671
+ ctx . withSpawnMock ( {
672
+ stub : sinonStub ( ) ,
673
+ registerSinonDefaults : true ,
674
+ callback ( stub : SinonStub ) {
675
+ stub . withArgs ( 'spawnCommandSync' , 'foo' ) . returns ( 'bar' ) ;
676
+ } ,
677
+ } ) ;
678
+
679
+ Dummy . prototype . mockTask = async function ( ) {
680
+ expect ( this . spawnCommandSync ( ) ) . toMatchObject ( { exitCode : 0 , stderr : '' , stdout : '' } ) ;
681
+ expect ( this . spawnCommandSync ( 'foo' ) ) . toBe ( 'bar' ) ;
682
+ } ;
683
+
684
+ await ctx . toPromise ( ) ;
685
+ } ) ;
686
+
687
+ it ( 'without defaults' , async function ( ) {
688
+ ctx . withSpawnMock ( {
689
+ stub : sinonStub ( ) ,
690
+ registerSinonDefaults : false ,
691
+ } ) ;
692
+
693
+ Dummy . prototype . mockTask = async function ( ) {
694
+ expect ( this . spawnCommandSync ( ) ) . toBeUndefined ( ) ;
695
+ } ;
696
+
697
+ await ctx . toPromise ( ) ;
698
+ } ) ;
662
699
} ) ;
663
700
664
701
describe ( '#withEnvironment()' , function ( ) {
0 commit comments