1- import { logger } from '@nx/devkit' ;
21import { afterAll , afterEach , beforeEach , expect , vi } from 'vitest' ;
32import { executorContext } from '@code-pushup/test-nx-utils' ;
43import { MEMFS_VOLUME } from '@code-pushup/test-utils' ;
@@ -9,9 +8,8 @@ describe('runAutorunExecutor', () => {
98 const processEnvCP = Object . fromEntries (
109 Object . entries ( process . env ) . filter ( ( [ k ] ) => k . startsWith ( 'CP_' ) ) ,
1110 ) ;
12- const loggerInfoSpy = vi . spyOn ( logger , 'info' ) ;
13- const loggerWarnSpy = vi . spyOn ( logger , 'warn' ) ;
1411 const executeProcessSpy = vi . spyOn ( executeProcessModule , 'executeProcess' ) ;
12+ let logger : import ( '@code-pushup/utils' ) . Logger ;
1513
1614 beforeAll ( ( ) => {
1715 Object . entries ( process . env )
@@ -25,7 +23,9 @@ describe('runAutorunExecutor', () => {
2523 ) ;
2624 } ) ;
2725
28- beforeEach ( ( ) => {
26+ beforeEach ( async ( ) => {
27+ const utils = await import ( '@code-pushup/utils' ) ;
28+ logger = utils . logger ;
2929 vi . unstubAllEnvs ( ) ;
3030 executeProcessSpy . mockResolvedValue ( {
3131 bin : 'npx ...' ,
@@ -37,8 +37,6 @@ describe('runAutorunExecutor', () => {
3737 } ) ;
3838
3939 afterEach ( ( ) => {
40- loggerWarnSpy . mockReset ( ) ;
41- loggerInfoSpy . mockReset ( ) ;
4240 executeProcessSpy . mockReset ( ) ;
4341 } ) ;
4442
@@ -108,30 +106,55 @@ describe('runAutorunExecutor', () => {
108106 expect ( output . command ) . toMatch ( '--upload.project="CLI"' ) ;
109107 } ) ;
110108
111- it ( 'should log information if verbose is set' , async ( ) => {
109+ it ( 'should set env var information if verbose is set' , async ( ) => {
112110 const output = await runAutorunExecutor (
113- { verbose : true } ,
111+ {
112+ verbose : true ,
113+ } ,
114114 { ...executorContext ( 'github-action' ) , cwd : '<CWD>' } ,
115115 ) ;
116+
116117 expect ( executeProcessSpy ) . toHaveBeenCalledTimes ( 1 ) ;
118+ expect ( executeProcessSpy ) . toHaveBeenCalledWith ( {
119+ command : 'npx' ,
120+ args : expect . arrayContaining ( [ '@code-pushup/cli' ] ) ,
121+ cwd : '<CWD>' ,
122+ } ) ;
117123
118- expect ( output . command ) . toMatch ( '--verbose' ) ;
119- expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
120- expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 2 ) ;
121- expect ( loggerInfoSpy ) . toHaveBeenCalledWith (
122- expect . stringContaining ( `Run CLI executor` ) ,
124+ expect ( process . env ) . toStrictEqual (
125+ expect . objectContaining ( {
126+ CP_VERBOSE : 'true' ,
127+ } ) ,
123128 ) ;
124- expect ( loggerInfoSpy ) . toHaveBeenCalledWith (
125- expect . stringContaining ( 'Command:' ) ,
129+
130+ expect ( output . command ) . not . toContain ( '--verbose' ) ;
131+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 0 ) ;
132+ } ) ;
133+
134+ it ( 'should log env var in dryRun information if verbose is set' , async ( ) => {
135+ const output = await runAutorunExecutor (
136+ {
137+ dryRun : true ,
138+ verbose : true ,
139+ } ,
140+ { ...executorContext ( 'github-action' ) , cwd : '<CWD>' } ,
141+ ) ;
142+
143+ expect ( executeProcessSpy ) . toHaveBeenCalledTimes ( 0 ) ;
144+
145+ expect ( output . command ) . not . toContain ( '--verbose' ) ;
146+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
147+ expect ( logger . warn ) . toHaveBeenCalledWith (
148+ expect . stringContaining ( 'CP_VERBOSE="true"' ) ,
126149 ) ;
127150 } ) ;
128151
129152 it ( 'should log command if dryRun is set' , async ( ) => {
130153 await runAutorunExecutor ( { dryRun : true } , executorContext ( 'utils' ) ) ;
131154
132- expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 0 ) ;
133- expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
134- expect ( loggerWarnSpy ) . toHaveBeenCalledWith (
155+ expect ( logger . command ) . toHaveBeenCalledTimes ( 0 ) ;
156+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 ) ;
157+ expect ( logger . warn ) . toHaveBeenCalledWith (
135158 expect . stringContaining ( 'DryRun execution of' ) ,
136159 ) ;
137160 } ) ;
0 commit comments