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 loggerSpy : Awaited < typeof 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 { logger } = await import ( '@code-pushup/utils' ) ;
28+ loggerSpy = 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
@@ -113,30 +111,30 @@ describe('runAutorunExecutor', () => {
113111 expect ( output . command ) . toMatch ( '--upload.project="CLI"' ) ;
114112 } ) ;
115113
116- it ( 'should log information if verbose is set' , async ( ) => {
114+ it ( 'should set env var information if verbose is set' , async ( ) => {
117115 const output = await runAutorunExecutor (
118- { verbose : true } ,
116+ {
117+ dryRun : true , // here to produce log
118+ verbose : true ,
119+ } ,
119120 { ...executorContext ( 'github-action' ) , cwd : '<CWD>' } ,
120121 ) ;
121- expect ( executeProcessSpy ) . toHaveBeenCalledTimes ( 1 ) ;
122122
123- expect ( output . command ) . toMatch ( '--verbose' ) ;
124- expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
125- expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 2 ) ;
126- expect ( loggerInfoSpy ) . toHaveBeenCalledWith (
127- expect . stringContaining ( `Run CLI executor` ) ,
128- ) ;
129- expect ( loggerInfoSpy ) . toHaveBeenCalledWith (
130- expect . stringContaining ( 'Command:' ) ,
123+ expect ( executeProcessSpy ) . toHaveBeenCalledTimes ( 0 ) ;
124+
125+ expect ( output . command ) . not . toContain ( '--verbose' ) ;
126+ expect ( loggerSpy . warn ) . toHaveBeenCalledTimes ( 1 ) ;
127+ expect ( loggerSpy . warn ) . toHaveBeenCalledWith (
128+ expect . stringContaining ( 'CP_VERBOSE="true"' ) ,
131129 ) ;
132130 } ) ;
133131
134132 it ( 'should log command if dryRun is set' , async ( ) => {
135133 await runAutorunExecutor ( { dryRun : true } , executorContext ( 'utils' ) ) ;
136134
137- expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 0 ) ;
138- expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
139- expect ( loggerWarnSpy ) . toHaveBeenCalledWith (
135+ expect ( loggerSpy . command ) . toHaveBeenCalledTimes ( 0 ) ;
136+ expect ( loggerSpy . warn ) . toHaveBeenCalledTimes ( 1 ) ;
137+ expect ( loggerSpy . warn ) . toHaveBeenCalledWith (
140138 expect . stringContaining ( 'DryRun execution of' ) ,
141139 ) ;
142140 } ) ;
0 commit comments