11import { logger } from '@nx/devkit' ;
22import { afterAll , afterEach , beforeEach , expect , vi } from 'vitest' ;
33import { executorContext } from '@code-pushup/test-nx-utils' ;
4- import { MEMFS_VOLUME } from '@code-pushup/test-utils' ;
4+ import { MEMFS_VOLUME , removeColorCodes } from '@code-pushup/test-utils' ;
55import * as executeProcessModule from '../../internal/execute-process.js' ;
66import runAutorunExecutor from './executor.js' ;
77
@@ -44,13 +44,17 @@ describe('runAutorunExecutor', () => {
4444
4545 it ( 'should call executeProcess with return result' , async ( ) => {
4646 const output = await runAutorunExecutor ( { } , executorContext ( 'utils' ) ) ;
47- expect ( output . success ) . toBe ( true ) ;
48- expect ( output . command ) . toMatch ( 'npx @code-pushup/cli' ) ;
49- expect ( executeProcessSpy ) . toHaveBeenCalledWith ( {
50- command : 'npx' ,
51- args : expect . arrayContaining ( [ '@code-pushup/cli' ] ) ,
52- cwd : MEMFS_VOLUME ,
47+ expect ( output ) . toStrictEqual ( {
48+ success : true ,
49+ command : expect . stringContaining ( 'npx @code-pushup/cli' ) ,
5350 } ) ;
51+ expect ( executeProcessSpy ) . toHaveBeenCalledWith (
52+ expect . objectContaining ( {
53+ command : 'npx' ,
54+ args : expect . arrayContaining ( [ '@code-pushup/cli' ] ) ,
55+ cwd : MEMFS_VOLUME ,
56+ } ) ,
57+ ) ;
5458 } ) ;
5559
5660 it ( 'should normalize context' , async ( ) => {
@@ -62,12 +66,15 @@ describe('runAutorunExecutor', () => {
6266 } ,
6367 ) ;
6468 expect ( output . success ) . toBe ( true ) ;
65- expect ( output . command ) . toMatch ( 'utils' ) ;
66- expect ( executeProcessSpy ) . toHaveBeenCalledWith ( {
67- command : 'npx' ,
68- args : expect . arrayContaining ( [ '@code-pushup/cli' ] ) ,
69- cwd : 'cwd-form-context' ,
70- } ) ;
69+ expect ( output . command ) . toMatch ( 'npx @code-pushup/cli' ) ;
70+ expect ( output . command ) . toContain ( 'cwd-form-context' ) ;
71+ expect ( executeProcessSpy ) . toHaveBeenCalledWith (
72+ expect . objectContaining ( {
73+ command : 'npx' ,
74+ args : expect . arrayContaining ( [ '@code-pushup/cli' ] ) ,
75+ cwd : 'cwd-form-context' ,
76+ } ) ,
77+ ) ;
7178 } ) ;
7279
7380 it ( 'should process executorOptions' , async ( ) => {
@@ -104,7 +111,6 @@ describe('runAutorunExecutor', () => {
104111 expect ( output . command ) . toMatch (
105112 '--persist.format="md" --persist.format="json"' ,
106113 ) ;
107- expect ( output . command ) . toMatch ( '--upload.apiKey="cp_1234567"' ) ;
108114 expect ( output . command ) . toMatch ( '--upload.project="CLI"' ) ;
109115 } ) ;
110116
@@ -115,26 +121,23 @@ describe('runAutorunExecutor', () => {
115121 ) ;
116122 expect ( executeProcessSpy ) . toHaveBeenCalledTimes ( 1 ) ;
117123
118- expect ( output . command ) . toMatch ( '--verbose' ) ;
124+ expect ( output . command ) . toMatch ( 'CP_VERBOSE="true"' ) ;
125+ expect ( output . command ) . not . toMatch ( '--verbose' ) ;
119126 expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
120- expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 2 ) ;
121- expect ( loggerInfoSpy ) . toHaveBeenCalledWith (
122- expect . stringContaining ( `Run CLI executor` ) ,
123- ) ;
124- expect ( loggerInfoSpy ) . toHaveBeenCalledWith (
125- expect . stringContaining ( 'Command: npx @code-pushup/cli' ) ,
126- ) ;
127+ expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 0 ) ;
127128 } ) ;
128129
129130 it ( 'should log command if dryRun is set' , async ( ) => {
130- await runAutorunExecutor ( { dryRun : true } , executorContext ( 'utils' ) ) ;
131+ const output = await runAutorunExecutor (
132+ { dryRun : true } ,
133+ executorContext ( 'utils' ) ,
134+ ) ;
131135
136+ expect ( output ) . toStrictEqual ( {
137+ success : true ,
138+ command : expect . stringContaining ( 'npx @code-pushup/cli' ) ,
139+ } ) ;
132140 expect ( loggerInfoSpy ) . toHaveBeenCalledTimes ( 0 ) ;
133- expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 1 ) ;
134- expect ( loggerWarnSpy ) . toHaveBeenCalledWith (
135- expect . stringContaining (
136- 'DryRun execution of: npx @code-pushup/cli --dryRun' ,
137- ) ,
138- ) ;
141+ expect ( loggerWarnSpy ) . toHaveBeenCalledTimes ( 0 ) ;
139142 } ) ;
140143} ) ;
0 commit comments