@@ -6,12 +6,13 @@ import process from 'node:process';
6
6
import { createRequire } from 'node:module' ;
7
7
import { mock } from 'node:test' ;
8
8
import { promisify as promisify_ } from 'node:util' ;
9
- import { afterEach , beforeEach , describe , expect , it } from 'vitest' ;
9
+ import { afterEach , beforeAll , beforeEach , describe , expect , it } from 'vitest' ;
10
10
import Generator from 'yeoman-generator' ;
11
11
import tempDirectory from 'temp-dir' ;
12
12
import { RunContextBase as RunContext } from '../src/run-context.js' ;
13
13
import helpers from '../src/helpers.js' ;
14
14
import { DummyPrompt } from '../src/adapter.js' ;
15
+ import { BaseEnvironmentOptions } from '@yeoman/types' ;
15
16
16
17
/* Remove argument from promisify return */
17
18
const promisify = function_ => ( ) => promisify_ ( function_ ) ( ) ;
@@ -21,7 +22,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
21
22
const tmpdir = path . join ( tempDirectory , 'yeoman-run-context' ) ;
22
23
23
24
describe ( 'RunContext' , ( ) => {
24
- const environmentOptions = { foo : 'bar' } ;
25
+ let environmentOptions : BaseEnvironmentOptions | undefined ;
25
26
let context : RunContext ;
26
27
let execSpy ;
27
28
let Dummy ;
@@ -61,6 +62,9 @@ describe('RunContext', () => {
61
62
) ;
62
63
63
64
describe ( 'constructor' , ( ) => {
65
+ beforeAll ( ( ) => {
66
+ environmentOptions = { foo : 'bar' } ;
67
+ } ) ;
64
68
it (
65
69
'forwards envOptions to the environment' ,
66
70
promisify ( done => {
@@ -856,6 +860,32 @@ describe('RunContext', () => {
856
860
) ;
857
861
} ) ;
858
862
863
+ describe ( '#withEnvironmentRun()' , ( ) => {
864
+ it ( 'calls runGenerator by default' , async ( ) => {
865
+ let mockedRunGenerator : ReturnType < typeof mock . fn > ;
866
+ await context
867
+ . withEnvironment ( environment => {
868
+ mockedRunGenerator = mock . method ( environment , 'runGenerator' ) ;
869
+ } )
870
+ . toPromise ( ) ;
871
+ expect ( mockedRunGenerator ! . mock . callCount ( ) ) . toBe ( 1 ) ;
872
+ } ) ;
873
+
874
+ it ( 'calls custom environment run method' , async ( ) => {
875
+ let mockedRunGenerator : ReturnType < typeof mock . fn > ;
876
+ const mockedEnvironmentRun = mock . fn ( ) ;
877
+ await context
878
+ . withEnvironment ( environment => {
879
+ mockedRunGenerator = mock . method ( environment , 'runGenerator' ) ;
880
+ } )
881
+ . withEnvironmentRun ( mockedEnvironmentRun )
882
+ . toPromise ( ) ;
883
+
884
+ expect ( mockedRunGenerator ! . mock . callCount ( ) ) . toBe ( 0 ) ;
885
+ expect ( mockedEnvironmentRun ! . mock . callCount ( ) ) . toBe ( 1 ) ;
886
+ } ) ;
887
+ } ) ;
888
+
859
889
describe ( '#withLocalConfig()' , ( ) => {
860
890
it (
861
891
'provides config to the generator' ,
0 commit comments