From 348246c3ce61d47ac193e7813517f113a9261e7f Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 14:19:08 +0100 Subject: [PATCH 01/26] refactor: set env vars if verbose is given --- .../nx-plugin/src/executors/cli/executor.ts | 17 ++++++++++------- .../src/executors/cli/executor.unit.test.ts | 14 ++++---------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index be932a35d..b4b32a170 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -23,23 +23,26 @@ export default async function runAutorunExecutor( terminalAndExecutorOptions, normalizedContext, ); - const { dryRun, verbose, command, bin } = terminalAndExecutorOptions; + const { dryRun, verbose, command, bin, ...args } = cliArgumentObject; + const executorEnvVariables = { + ...(verbose && { CP_VERBOSE: 'true' }), + }; const commandString = createCliCommandString({ command, - args: cliArgumentObject, + args: args, bin, }); - if (verbose) { - logger.info(`Run CLI executor ${command ?? ''}`); - logger.info(`Command: ${commandString}`); - } + if (dryRun) { logger.warn(`DryRun execution of: ${commandString}`); } else { try { await executeProcess({ - ...createCliCommandObject({ command, args: cliArgumentObject, bin }), + ...createCliCommandObject({ command, args, bin }), ...(context.cwd ? { cwd: context.cwd } : {}), + ...(Object.keys(executorEnvVariables).length + ? { env: executorEnvVariables } + : {}), }); } catch (error) { logger.error(error); diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index bcac3e153..6b7a38e2c 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -108,21 +108,17 @@ describe('runAutorunExecutor', () => { expect(output.command).toMatch('--upload.project="CLI"'); }); - it('should log information if verbose is set', async () => { + it('should set env var information if verbose is set', async () => { const output = await runAutorunExecutor( { verbose: true }, { ...executorContext('github-action'), cwd: '' }, ); expect(executeProcessSpy).toHaveBeenCalledTimes(1); - expect(output.command).toMatch('--verbose'); + expect(output.command).not.toContain('--verbose'); expect(loggerWarnSpy).toHaveBeenCalledTimes(0); - expect(loggerInfoSpy).toHaveBeenCalledTimes(2); expect(loggerInfoSpy).toHaveBeenCalledWith( - expect.stringContaining(`Run CLI executor`), - ); - expect(loggerInfoSpy).toHaveBeenCalledWith( - expect.stringContaining('Command: npx @code-pushup/cli'), + expect.stringContaining('CP_VERBOSE=true'), ); }); @@ -132,9 +128,7 @@ describe('runAutorunExecutor', () => { expect(loggerInfoSpy).toHaveBeenCalledTimes(0); expect(loggerWarnSpy).toHaveBeenCalledTimes(1); expect(loggerWarnSpy).toHaveBeenCalledWith( - expect.stringContaining( - 'DryRun execution of: npx @code-pushup/cli --dryRun', - ), + expect.stringContaining('DryRun execution of'), ); }); }); From 2dcfb6587d240244743ea14d98a0c8bac01a2eb9 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 14:23:11 +0100 Subject: [PATCH 02/26] refactor: fix int test --- packages/nx-plugin/src/executors/cli/executor.int.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/nx-plugin/src/executors/cli/executor.int.test.ts b/packages/nx-plugin/src/executors/cli/executor.int.test.ts index fee1e59d8..b504ae830 100644 --- a/packages/nx-plugin/src/executors/cli/executor.int.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.int.test.ts @@ -47,6 +47,9 @@ describe('runAutorunExecutor', () => { command: 'npx', args: expect.arrayContaining(['@code-pushup/cli']), cwd: process.cwd(), + env: { + CP_VERBOSE: 'true', + }, }); }); }); From 1106a36fa8ec7cd5bfbf2009c6b6a65e6b45d442 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 14:46:47 +0100 Subject: [PATCH 03/26] refactor: fix lint --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 3 ++- packages/nx-plugin/src/executors/cli/executor.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index fb5408812..2184172ce 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -199,7 +199,8 @@ describe('nx-plugin', () => { // Nx command expect(cleanStdout).toContain('nx run my-lib:code-pushup'); // Run CLI executor - expect(cleanStdout).toContain('Command: npx @code-pushup/cli'); + expect(cleanStdout).toContain('DryRun execution of:'); + expect(cleanStdout).toContain('npx @code-pushup/cli'); expect(cleanStdout).toContain('--dryRun --verbose'); }); diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index b4b32a170..122eadd53 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -29,7 +29,7 @@ export default async function runAutorunExecutor( }; const commandString = createCliCommandString({ command, - args: args, + args, bin, }); @@ -40,7 +40,7 @@ export default async function runAutorunExecutor( await executeProcess({ ...createCliCommandObject({ command, args, bin }), ...(context.cwd ? { cwd: context.cwd } : {}), - ...(Object.keys(executorEnvVariables).length + ...(Object.keys(executorEnvVariables).length > 0 ? { env: executorEnvVariables } : {}), }); From 21511d47ed64dbc7fb5be2bb1482521285dfc318 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 15:46:11 +0100 Subject: [PATCH 04/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 2184172ce..9bd89c5e8 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -1,5 +1,6 @@ import type { Tree } from '@nx/devkit'; import path from 'node:path'; +import * as process from 'node:process'; import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; import { afterEach, expect } from 'vitest'; import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; @@ -197,11 +198,14 @@ describe('nx-plugin', () => { const cleanStdout = removeColorCodes(stdout); // Nx command + process.stdout.write(cleanStdout); // For easier debugging expect(cleanStdout).toContain('nx run my-lib:code-pushup'); // Run CLI executor expect(cleanStdout).toContain('DryRun execution of:'); expect(cleanStdout).toContain('npx @code-pushup/cli'); - expect(cleanStdout).toContain('--dryRun --verbose'); + expect(cleanStdout).toContain('--dryRun'); + expect(cleanStdout).not.toContain('--verbose'); + expect(cleanStdout).toContain('CP_VERBOSE=true'); }); it('should consider plugin option bin in executor target', async () => { From e120e3b32484a5932c1ce3bde98638e24906df9d Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 15:49:32 +0100 Subject: [PATCH 05/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 9bd89c5e8..656c8bf9e 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -198,7 +198,7 @@ describe('nx-plugin', () => { const cleanStdout = removeColorCodes(stdout); // Nx command - process.stdout.write(cleanStdout); // For easier debugging + throw new Error(cleanStdout); // For easier debugging expect(cleanStdout).toContain('nx run my-lib:code-pushup'); // Run CLI executor expect(cleanStdout).toContain('DryRun execution of:'); From 5bab88e2357794dff165223022707f37aa32fb4b Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 16:06:23 +0100 Subject: [PATCH 06/26] refactor: wip --- packages/nx-plugin/src/executors/cli/executor.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index 122eadd53..2f0af998b 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -25,6 +25,7 @@ export default async function runAutorunExecutor( ); const { dryRun, verbose, command, bin, ...args } = cliArgumentObject; const executorEnvVariables = { + ...process.env, ...(verbose && { CP_VERBOSE: 'true' }), }; const commandString = createCliCommandString({ From bf78e82545335311d09a709f9c2efb67c196220d Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 16:13:06 +0100 Subject: [PATCH 07/26] refactor: wip --- packages/nx-plugin/src/executors/cli/executor.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index 2f0af998b..dbb9c10f2 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -1,4 +1,4 @@ -import { type ExecutorContext, logger } from '@nx/devkit'; +import { type ExecutorContext } from '@nx/devkit'; import { executeProcess } from '../../internal/execute-process.js'; import { createCliCommandObject, @@ -18,6 +18,7 @@ export default async function runAutorunExecutor( terminalAndExecutorOptions: AutorunCommandExecutorOptions, context: ExecutorContext, ): Promise { + const { logger, stringifyError } = await import('@code-pushup/utils'); const normalizedContext = normalizeContext(context); const cliArgumentObject = parseAutorunExecutorOptions( terminalAndExecutorOptions, @@ -41,12 +42,10 @@ export default async function runAutorunExecutor( await executeProcess({ ...createCliCommandObject({ command, args, bin }), ...(context.cwd ? { cwd: context.cwd } : {}), - ...(Object.keys(executorEnvVariables).length > 0 - ? { env: executorEnvVariables } - : {}), + ...(verbose ? { env: executorEnvVariables } : {}), }); } catch (error) { - logger.error(error); + logger.error(stringifyError(error)); return { success: false, command: commandString, From 676b88c228aa5db53f1a1f61eaa849071661f93f Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 16:16:39 +0100 Subject: [PATCH 08/26] refactor: wip --- packages/nx-plugin/src/executors/cli/executor.int.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.int.test.ts b/packages/nx-plugin/src/executors/cli/executor.int.test.ts index b504ae830..99e02c018 100644 --- a/packages/nx-plugin/src/executors/cli/executor.int.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.int.test.ts @@ -47,9 +47,9 @@ describe('runAutorunExecutor', () => { command: 'npx', args: expect.arrayContaining(['@code-pushup/cli']), cwd: process.cwd(), - env: { + env: expect.objectContaining({ CP_VERBOSE: 'true', - }, + }), }); }); }); From 5ff36274eeb97c2ca4d107f56e69ef577bae3802 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 16:19:23 +0100 Subject: [PATCH 09/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 656c8bf9e..715f37b0d 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -198,12 +198,10 @@ describe('nx-plugin', () => { const cleanStdout = removeColorCodes(stdout); // Nx command - throw new Error(cleanStdout); // For easier debugging - expect(cleanStdout).toContain('nx run my-lib:code-pushup'); + expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); // Run CLI executor expect(cleanStdout).toContain('DryRun execution of:'); expect(cleanStdout).toContain('npx @code-pushup/cli'); - expect(cleanStdout).toContain('--dryRun'); expect(cleanStdout).not.toContain('--verbose'); expect(cleanStdout).toContain('CP_VERBOSE=true'); }); From be536024183412c29a268ba197a727ca816635cc Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 18:11:30 +0100 Subject: [PATCH 10/26] refactor: fix unit test --- .../nx-plugin/src/executors/cli/executor.ts | 13 +++++++--- .../src/executors/cli/executor.unit.test.ts | 26 +++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index e9562434d..038736d03 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -1,4 +1,4 @@ -import { type ExecutorContext } from '@nx/devkit'; +import type { ExecutorContext } from '@nx/devkit'; import { executeProcess } from '../../internal/execute-process.js'; import { normalizeContext } from '../internal/context.js'; import type { AutorunCommandExecutorOptions } from './schema.js'; @@ -36,11 +36,11 @@ export default async function runAutorunExecutor( ]; const args = [...positionals, ...objectToCliArgs(restArgs)]; const executorEnvVariables = { - ...process.env, ...(verbose && { CP_VERBOSE: 'true' }), }; const commandString = formatCommandStatus([command, ...args].join(' '), { cwd: context.cwd, + env: executorEnvVariables, }); if (dryRun) { @@ -51,7 +51,14 @@ export default async function runAutorunExecutor( command, args, ...(context.cwd ? { cwd: context.cwd } : {}), - ...(verbose ? { env: executorEnvVariables } : {}), + ...(verbose + ? { + env: { + ...process.env, + ...executorEnvVariables, + }, + } + : {}), }); } catch (error) { logger.error(stringifyError(error)); diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index 6b7a38e2c..39ad3c75e 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -1,7 +1,7 @@ -import { logger } from '@nx/devkit'; import { afterAll, afterEach, beforeEach, expect, vi } from 'vitest'; import { executorContext } from '@code-pushup/test-nx-utils'; import { MEMFS_VOLUME } from '@code-pushup/test-utils'; +import { logger } from '@code-pushup/utils'; import * as executeProcessModule from '../../internal/execute-process.js'; import runAutorunExecutor from './executor.js'; @@ -9,8 +9,6 @@ describe('runAutorunExecutor', () => { const processEnvCP = Object.fromEntries( Object.entries(process.env).filter(([k]) => k.startsWith('CP_')), ); - const loggerInfoSpy = vi.spyOn(logger, 'info'); - const loggerWarnSpy = vi.spyOn(logger, 'warn'); const executeProcessSpy = vi.spyOn(executeProcessModule, 'executeProcess'); beforeAll(() => { @@ -37,8 +35,6 @@ describe('runAutorunExecutor', () => { }); afterEach(() => { - loggerWarnSpy.mockReset(); - loggerInfoSpy.mockReset(); executeProcessSpy.mockReset(); }); @@ -110,24 +106,28 @@ describe('runAutorunExecutor', () => { it('should set env var information if verbose is set', async () => { const output = await runAutorunExecutor( - { verbose: true }, + { + dryRun: true, // here to produce log + verbose: true, + }, { ...executorContext('github-action'), cwd: '' }, ); - expect(executeProcessSpy).toHaveBeenCalledTimes(1); + + expect(executeProcessSpy).toHaveBeenCalledTimes(0); expect(output.command).not.toContain('--verbose'); - expect(loggerWarnSpy).toHaveBeenCalledTimes(0); - expect(loggerInfoSpy).toHaveBeenCalledWith( - expect.stringContaining('CP_VERBOSE=true'), + expect(logger.warn).toHaveBeenCalledTimes(1); + expect(logger.warn).toHaveBeenCalledWith( + expect.stringContaining('CP_VERBOSE=\"true\"'), ); }); it('should log command if dryRun is set', async () => { await runAutorunExecutor({ dryRun: true }, executorContext('utils')); - expect(loggerInfoSpy).toHaveBeenCalledTimes(0); - expect(loggerWarnSpy).toHaveBeenCalledTimes(1); - expect(loggerWarnSpy).toHaveBeenCalledWith( + expect(logger.command).toHaveBeenCalledTimes(0); + expect(logger.warn).toHaveBeenCalledTimes(1); + expect(logger.warn).toHaveBeenCalledWith( expect.stringContaining('DryRun execution of'), ); }); From f3a92315e920bce7d395845d3e4822a54e2b1d71 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 18:25:33 +0100 Subject: [PATCH 11/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 1 + packages/nx-plugin/src/executors/cli/executor.unit.test.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index af80803fe..86e183921 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -173,6 +173,7 @@ describe('nx-plugin', () => { }); const cleanStdout = removeColorCodes(stdout); + throw new Error(cleanStdout); // Nx command expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); // Run CLI executor diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index 39ad3c75e..00370ecf3 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -118,7 +118,7 @@ describe('runAutorunExecutor', () => { expect(output.command).not.toContain('--verbose'); expect(logger.warn).toHaveBeenCalledTimes(1); expect(logger.warn).toHaveBeenCalledWith( - expect.stringContaining('CP_VERBOSE=\"true\"'), + expect.stringContaining('CP_VERBOSE="true"'), ); }); From 13a6340eca6def7b01b7e48a02347cbb406dcce8 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 18:26:07 +0100 Subject: [PATCH 12/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 86e183921..9ba3aba90 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -173,14 +173,13 @@ describe('nx-plugin', () => { }); const cleanStdout = removeColorCodes(stdout); - throw new Error(cleanStdout); // Nx command expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); // Run CLI executor expect(cleanStdout).toContain('DryRun execution of:'); expect(cleanStdout).toContain('npx @code-pushup/cli'); expect(cleanStdout).not.toContain('--verbose'); - expect(cleanStdout).toContain('CP_VERBOSE=true'); + expect(cleanStdout).toContain('CP_VERBOSE="true"'); }); it('should consider plugin option bin in executor target', async () => { From f5b950ba117f7c91c592a70ba5f2dde627ac4cda Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 18:39:53 +0100 Subject: [PATCH 13/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 1 + packages/nx-plugin/src/executors/cli/executor.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 9ba3aba90..1d4153a77 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -173,6 +173,7 @@ describe('nx-plugin', () => { }); const cleanStdout = removeColorCodes(stdout); + throw new Error(cleanStdout); // Nx command expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); // Run CLI executor diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index 038736d03..2dc773934 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -47,6 +47,7 @@ export default async function runAutorunExecutor( logger.warn(`DryRun execution of: ${commandString}`); } else { try { + logger.debug(`With env vars: ${executorEnvVariables}`); await executeProcess({ command, args, From aea384b0bde13e3dd3a41cd0cc75f3a2792ce9da Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 18:44:26 +0100 Subject: [PATCH 14/26] refactor: wip --- e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts index 1d4153a77..c7f911a2e 100644 --- a/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/plugin-create-nodes.e2e.test.ts @@ -173,7 +173,7 @@ describe('nx-plugin', () => { }); const cleanStdout = removeColorCodes(stdout); - throw new Error(cleanStdout); + // Nx command expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); // Run CLI executor From 4e02f79dc71e84eb172e9a8d176805ab0e3bc140 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 18:53:39 +0100 Subject: [PATCH 15/26] refactor: wip --- packages/nx-plugin/src/executors/cli/executor.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index 2dc773934..de838edb9 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -22,13 +22,8 @@ export default async function runAutorunExecutor( terminalAndExecutorOptions, normalizedContext, ); - const { - dryRun, - verbose, - command: cliCommand, - bin, - ...restArgs - } = cliArgumentObject; + const { command: cliCommand } = terminalAndExecutorOptions; + const { dryRun, verbose, bin, ...restArgs } = cliArgumentObject; const command = bin ? `node` : 'npx'; const positionals = [ bin ?? '@code-pushup/cli', From 986ce0edccca633e9c73f22fa4602b5b3446ab33 Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 19:04:26 +0100 Subject: [PATCH 16/26] refactor: fix lint --- .../src/executors/cli/executor.unit.test.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index 00370ecf3..d99408155 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -1,7 +1,6 @@ import { afterAll, afterEach, beforeEach, expect, vi } from 'vitest'; import { executorContext } from '@code-pushup/test-nx-utils'; import { MEMFS_VOLUME } from '@code-pushup/test-utils'; -import { logger } from '@code-pushup/utils'; import * as executeProcessModule from '../../internal/execute-process.js'; import runAutorunExecutor from './executor.js'; @@ -10,6 +9,7 @@ describe('runAutorunExecutor', () => { Object.entries(process.env).filter(([k]) => k.startsWith('CP_')), ); const executeProcessSpy = vi.spyOn(executeProcessModule, 'executeProcess'); + let loggerSpy: Awaited['logger']; beforeAll(() => { Object.entries(process.env) @@ -23,7 +23,9 @@ describe('runAutorunExecutor', () => { ); }); - beforeEach(() => { + beforeEach(async () => { + const { logger } = await import('@code-pushup/utils'); + loggerSpy = logger; vi.unstubAllEnvs(); executeProcessSpy.mockResolvedValue({ bin: 'npx ...', @@ -116,8 +118,8 @@ describe('runAutorunExecutor', () => { expect(executeProcessSpy).toHaveBeenCalledTimes(0); expect(output.command).not.toContain('--verbose'); - expect(logger.warn).toHaveBeenCalledTimes(1); - expect(logger.warn).toHaveBeenCalledWith( + expect(loggerSpy.warn).toHaveBeenCalledTimes(1); + expect(loggerSpy.warn).toHaveBeenCalledWith( expect.stringContaining('CP_VERBOSE="true"'), ); }); @@ -125,9 +127,9 @@ describe('runAutorunExecutor', () => { it('should log command if dryRun is set', async () => { await runAutorunExecutor({ dryRun: true }, executorContext('utils')); - expect(logger.command).toHaveBeenCalledTimes(0); - expect(logger.warn).toHaveBeenCalledTimes(1); - expect(logger.warn).toHaveBeenCalledWith( + expect(loggerSpy.command).toHaveBeenCalledTimes(0); + expect(loggerSpy.warn).toHaveBeenCalledTimes(1); + expect(loggerSpy.warn).toHaveBeenCalledWith( expect.stringContaining('DryRun execution of'), ); }); From 2fb8ecd7a317a1d9a77c731f1231a94d647dc66d Mon Sep 17 00:00:00 2001 From: John Doe Date: Tue, 2 Dec 2025 20:36:37 +0100 Subject: [PATCH 17/26] refactor: wip --- .../src/executors/cli/executor.unit.test.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index d99408155..547f6dd65 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -109,7 +109,29 @@ describe('runAutorunExecutor', () => { it('should set env var information if verbose is set', async () => { const output = await runAutorunExecutor( { - dryRun: true, // here to produce log + verbose: true, + }, + { ...executorContext('github-action'), cwd: '' }, + ); + + expect(executeProcessSpy).toHaveBeenCalledTimes(1); + expect(executeProcessSpy).toHaveBeenCalledWith({ + command: 'npx', + args: expect.arrayContaining(['@code-pushup/cli']), + cwd: '', + env: expect.objectContaining({ + CP_VERBOSE: 'true', + }), + }); + + expect(output.command).not.toContain('--verbose'); + expect(loggerSpy.warn).toHaveBeenCalledTimes(0); + }); + + it('should log env var in dryRun information if verbose is set', async () => { + const output = await runAutorunExecutor( + { + dryRun: true, verbose: true, }, { ...executorContext('github-action'), cwd: '' }, From 1c41694ea9b95b4f421f63ec2537a5345059e00c Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 16:24:01 +0100 Subject: [PATCH 18/26] refactor: use logger to set verbose --- packages/nx-plugin/src/executors/cli/executor.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.ts b/packages/nx-plugin/src/executors/cli/executor.ts index de838edb9..066119213 100644 --- a/packages/nx-plugin/src/executors/cli/executor.ts +++ b/packages/nx-plugin/src/executors/cli/executor.ts @@ -23,7 +23,9 @@ export default async function runAutorunExecutor( normalizedContext, ); const { command: cliCommand } = terminalAndExecutorOptions; - const { dryRun, verbose, bin, ...restArgs } = cliArgumentObject; + const { verbose = false, dryRun, bin, ...restArgs } = cliArgumentObject; + logger.setVerbose(verbose); + const command = bin ? `node` : 'npx'; const positionals = [ bin ?? '@code-pushup/cli', @@ -47,14 +49,6 @@ export default async function runAutorunExecutor( command, args, ...(context.cwd ? { cwd: context.cwd } : {}), - ...(verbose - ? { - env: { - ...process.env, - ...executorEnvVariables, - }, - } - : {}), }); } catch (error) { logger.error(stringifyError(error)); From df0ec9c6ae7c799af4b5b7df3ba27f033636c49d Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 16:34:07 +0100 Subject: [PATCH 19/26] refactor: fix tests --- .../src/executors/cli/executor.unit.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index 547f6dd65..17b992d20 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -9,7 +9,7 @@ describe('runAutorunExecutor', () => { Object.entries(process.env).filter(([k]) => k.startsWith('CP_')), ); const executeProcessSpy = vi.spyOn(executeProcessModule, 'executeProcess'); - let loggerSpy: Awaited['logger']; + let logger: import('@code-pushup/utils').Logger; beforeAll(() => { Object.entries(process.env) @@ -24,8 +24,8 @@ describe('runAutorunExecutor', () => { }); beforeEach(async () => { - const { logger } = await import('@code-pushup/utils'); - loggerSpy = logger; + const utils = await import('@code-pushup/utils'); + logger = utils.logger; vi.unstubAllEnvs(); executeProcessSpy.mockResolvedValue({ bin: 'npx ...', @@ -125,7 +125,7 @@ describe('runAutorunExecutor', () => { }); expect(output.command).not.toContain('--verbose'); - expect(loggerSpy.warn).toHaveBeenCalledTimes(0); + expect(logger.warn).toHaveBeenCalledTimes(0); }); it('should log env var in dryRun information if verbose is set', async () => { @@ -140,8 +140,8 @@ describe('runAutorunExecutor', () => { expect(executeProcessSpy).toHaveBeenCalledTimes(0); expect(output.command).not.toContain('--verbose'); - expect(loggerSpy.warn).toHaveBeenCalledTimes(1); - expect(loggerSpy.warn).toHaveBeenCalledWith( + expect(logger.warn).toHaveBeenCalledTimes(1); + expect(logger.warn).toHaveBeenCalledWith( expect.stringContaining('CP_VERBOSE="true"'), ); }); @@ -149,9 +149,9 @@ describe('runAutorunExecutor', () => { it('should log command if dryRun is set', async () => { await runAutorunExecutor({ dryRun: true }, executorContext('utils')); - expect(loggerSpy.command).toHaveBeenCalledTimes(0); - expect(loggerSpy.warn).toHaveBeenCalledTimes(1); - expect(loggerSpy.warn).toHaveBeenCalledWith( + expect(logger.command).toHaveBeenCalledTimes(0); + expect(logger.warn).toHaveBeenCalledTimes(1); + expect(logger.warn).toHaveBeenCalledWith( expect.stringContaining('DryRun execution of'), ); }); From 6df53af8806af105aca5639a170de2da20515ecd Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 16:54:50 +0100 Subject: [PATCH 20/26] refactor: wip --- .../nx-plugin/src/executors/cli/executor.int.test.ts | 12 ++++++++++-- .../src/executors/cli/executor.unit.test.ts | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.int.test.ts b/packages/nx-plugin/src/executors/cli/executor.int.test.ts index 99e02c018..0a95028b1 100644 --- a/packages/nx-plugin/src/executors/cli/executor.int.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.int.test.ts @@ -27,6 +27,11 @@ describe('runAutorunExecutor', () => { }); it('should normalize context, parse CLI options and execute command', async () => { + expect(process.env).toStrictEqual( + expect.not.objectContaining({ + CP_VERBOSE: 'true', + }), + ); const output = await runAutorunExecutor( { verbose: true }, executorContext('utils'), @@ -47,9 +52,12 @@ describe('runAutorunExecutor', () => { command: 'npx', args: expect.arrayContaining(['@code-pushup/cli']), cwd: process.cwd(), - env: expect.objectContaining({ + }); + + expect(process.env).toStrictEqual( + expect.objectContaining({ CP_VERBOSE: 'true', }), - }); + ); }); }); diff --git a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts index 17b992d20..4736f8196 100644 --- a/packages/nx-plugin/src/executors/cli/executor.unit.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.unit.test.ts @@ -119,10 +119,13 @@ describe('runAutorunExecutor', () => { command: 'npx', args: expect.arrayContaining(['@code-pushup/cli']), cwd: '', - env: expect.objectContaining({ + }); + + expect(process.env).toStrictEqual( + expect.objectContaining({ CP_VERBOSE: 'true', }), - }); + ); expect(output.command).not.toContain('--verbose'); expect(logger.warn).toHaveBeenCalledTimes(0); From 28321f5321dedf520fadfa704823cedd1a8fab04 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 17:00:03 +0100 Subject: [PATCH 21/26] refactor: wip --- e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts index 047fbfe24..3c297eb8b 100644 --- a/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts @@ -201,6 +201,7 @@ describe('executor command', () => { expect(cleanStdout).toContain( 'nx run my-lib:code-pushup collect --persist.filename=terminal-report', ); + throw new Error(cleanStdout); expect(cleanStdout).toContain('Code PushUp CLI'); await expect( From 61d72524bfbf5e8d758cd7bfba84e1dffd1b805f Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 17:24:30 +0100 Subject: [PATCH 22/26] refactor: wip --- e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts index 3c297eb8b..ffb9ab06e 100644 --- a/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts @@ -192,6 +192,7 @@ describe('executor command', () => { `${project}:code-pushup`, 'collect', '--persist.filename=terminal-report', + '--verbose', ], cwd, }); @@ -201,7 +202,6 @@ describe('executor command', () => { expect(cleanStdout).toContain( 'nx run my-lib:code-pushup collect --persist.filename=terminal-report', ); - throw new Error(cleanStdout); expect(cleanStdout).toContain('Code PushUp CLI'); await expect( From eccec6df6d39c3cc4fec13a30cdb3e19dbcb0e30 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 18:36:25 +0100 Subject: [PATCH 23/26] refactor: fix lighthouse text styling --- packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts b/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts index d997d4e0d..c78c0cdb2 100644 --- a/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts +++ b/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts @@ -199,7 +199,7 @@ describe('createRunnerFunction', () => { ); expect(logger.warn).toHaveBeenCalledWith( - `Lighthouse did not produce a result for URL: ${ansis.underline.blueBright('fail')}`, + `Lighthouse did not produce a result for URL: ${ansis.blueBright('fail')}`, ); }); From 1205bd35ea316bc324590735521c15c36bccf1e3 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Wed, 3 Dec 2025 19:19:35 +0100 Subject: [PATCH 24/26] refactor: wip --- packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts b/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts index c78c0cdb2..d997d4e0d 100644 --- a/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts +++ b/packages/plugin-lighthouse/src/lib/runner/runner.unit.test.ts @@ -199,7 +199,7 @@ describe('createRunnerFunction', () => { ); expect(logger.warn).toHaveBeenCalledWith( - `Lighthouse did not produce a result for URL: ${ansis.blueBright('fail')}`, + `Lighthouse did not produce a result for URL: ${ansis.underline.blueBright('fail')}`, ); }); From c543f622ab32f984dbf788230fc47ac4f4a26f83 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:32:48 +0100 Subject: [PATCH 25/26] Update packages/nx-plugin/src/executors/cli/executor.int.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/nx-plugin/src/executors/cli/executor.int.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.int.test.ts b/packages/nx-plugin/src/executors/cli/executor.int.test.ts index 0a95028b1..62728dff8 100644 --- a/packages/nx-plugin/src/executors/cli/executor.int.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.int.test.ts @@ -27,11 +27,7 @@ describe('runAutorunExecutor', () => { }); it('should normalize context, parse CLI options and execute command', async () => { - expect(process.env).toStrictEqual( - expect.not.objectContaining({ - CP_VERBOSE: 'true', - }), - ); + expect(process.env).not.toHaveProperty('CP_VERBOSE', 'true'); const output = await runAutorunExecutor( { verbose: true }, executorContext('utils'), From d7c4eec3c1b9c8a648ec1f263db65e7c48c09922 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Thu, 4 Dec 2025 12:32:57 +0100 Subject: [PATCH 26/26] Update packages/nx-plugin/src/executors/cli/executor.int.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/nx-plugin/src/executors/cli/executor.int.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/nx-plugin/src/executors/cli/executor.int.test.ts b/packages/nx-plugin/src/executors/cli/executor.int.test.ts index 62728dff8..eaa7f1777 100644 --- a/packages/nx-plugin/src/executors/cli/executor.int.test.ts +++ b/packages/nx-plugin/src/executors/cli/executor.int.test.ts @@ -50,10 +50,6 @@ describe('runAutorunExecutor', () => { cwd: process.cwd(), }); - expect(process.env).toStrictEqual( - expect.objectContaining({ - CP_VERBOSE: 'true', - }), - ); + expect(process.env).toHaveProperty('CP_VERBOSE', 'true'); }); });