@@ -2,7 +2,10 @@ import { type Tree, updateProjectConfiguration } from '@nx/devkit';
22import path from 'node:path' ;
33import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration' ;
44import { afterEach , expect } from 'vitest' ;
5- import { generateCodePushupConfig } from '@code-pushup/nx-plugin' ;
5+ import {
6+ type AutorunCommandExecutorOptions ,
7+ generateCodePushupConfig ,
8+ } from '@code-pushup/nx-plugin' ;
69import {
710 generateWorkspaceAndProject ,
811 materializeTree ,
@@ -20,6 +23,7 @@ import { INLINE_PLUGIN } from './inline-plugin.js';
2023async function addTargetToWorkspace (
2124 tree : Tree ,
2225 options : { cwd : string ; project : string } ,
26+ executorOptions ?: AutorunCommandExecutorOptions ,
2327) {
2428 const { cwd, project } = options ;
2529 const projectCfg = readProjectConfiguration ( tree , project ) ;
@@ -29,6 +33,7 @@ async function addTargetToWorkspace(
2933 ...projectCfg . targets ,
3034 'code-pushup' : {
3135 executor : '@code-pushup/nx-plugin:cli' ,
36+ ...( executorOptions && { options : executorOptions } ) ,
3237 } ,
3338 } ,
3439 } ) ;
@@ -95,6 +100,42 @@ describe('executor command', () => {
95100 ) . rejects . toThrow ( '' ) ;
96101 } ) ;
97102
103+ it ( 'should execute collect executor and merge target and command-line options' , async ( ) => {
104+ const cwd = path . join ( testFileDir , 'execute-collect-with-merged-options' ) ;
105+ await addTargetToWorkspace (
106+ tree ,
107+ { cwd, project } ,
108+ {
109+ persist : {
110+ outputDir : '.reports' ,
111+ filename : 'report' ,
112+ } ,
113+ } ,
114+ ) ;
115+
116+ const { stdout, code } = await executeProcess ( {
117+ command : 'npx' ,
118+ args : [
119+ 'nx' ,
120+ 'run' ,
121+ `${ project } :code-pushup` ,
122+ 'collect' ,
123+ '--persist.filename=terminal-report' ,
124+ ] ,
125+ cwd,
126+ } ) ;
127+
128+ expect ( code ) . toBe ( 0 ) ;
129+ const cleanStdout = removeColorCodes ( stdout ) ;
130+ expect ( cleanStdout ) . toContain (
131+ 'nx run my-lib:code-pushup collect --persist.filename=terminal-report' ,
132+ ) ;
133+
134+ await expect (
135+ readJsonFile ( path . join ( cwd , '.reports' , 'terminal-report.json' ) ) ,
136+ ) . resolves . not . toThrow ( ) ;
137+ } ) ;
138+
98139 it ( 'should execute collect executor and add report to sub folder named by project' , async ( ) => {
99140 const cwd = path . join ( testFileDir , 'execute-collect-command' ) ;
100141 await addTargetToWorkspace ( tree , { cwd, project } ) ;
0 commit comments