From 662f22f13173bf13df8b9b655d0e7178dbd8f98a Mon Sep 17 00:00:00 2001 From: Milo Cesar Date: Wed, 20 Dec 2023 21:38:53 +0100 Subject: [PATCH] feat(e2e-runner): enable or disable target logging via options Use the new `logging` option on a target to either enable, or disable the logging output for the specified target. Closes #202 --- packages/e2e-runner/README.md | 4 +++- packages/e2e-runner/src/executors/run/utils/nx-target.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/e2e-runner/README.md b/packages/e2e-runner/README.md index 335e81e1..e9609245 100644 --- a/packages/e2e-runner/README.md +++ b/packages/e2e-runner/README.md @@ -34,6 +34,7 @@ Each target can be configured with the following options. env?: { [key: string]: string } // Extra parameters provided to the target on startup. reuseExistingServer?: boolean // Set to true to allow using a previously started target. rejectUnauthorized?: boolean // Set to false to allow the use of self-signed certificates in your target. + logging?: boolean // Set to true to forwards the logs of the target, set to false to hide the logs of the target. When undefined, the logs are only forwarded with the `--verbose` flag. } ``` @@ -56,7 +57,8 @@ Example target { "target": "api:serve", "checkUrl": "http://localhost:9000/health", - "checkMaxTries": 50 + "checkMaxTries": 50, + "logging": false } ] } diff --git a/packages/e2e-runner/src/executors/run/utils/nx-target.ts b/packages/e2e-runner/src/executors/run/utils/nx-target.ts index aca23e6e..096a5ee1 100644 --- a/packages/e2e-runner/src/executors/run/utils/nx-target.ts +++ b/packages/e2e-runner/src/executors/run/utils/nx-target.ts @@ -13,6 +13,7 @@ export interface NxTargetOptions { env?: { [key: string]: string } reuseExistingServer?: boolean rejectUnauthorized?: boolean + logging?: boolean } export class NxTarget { @@ -101,7 +102,8 @@ export class NxTarget { onExit: (code) => ( processExitedReject(new Error(`Target "${this.options.target}" was not able to start. Exit code: ${code}`)) ), - env: this.options.env + env: this.options.env, + logging: this.options.logging }) if (this.killed) { @@ -162,10 +164,13 @@ function launchProcess( options: { onExit: (exitCode: number | null, signal: string | null) => void env?: { [key: string]: string } + logging?: boolean } ): () => Promise { const { project, target, configuration } = parseTargetString(targetString, readCachedProjectGraph()) + const shouldLog = options.logging ?? USE_VERBOSE_LOGGING + const spawnedProcess = childProcess.spawn( `${getPackageManagerExecCommand()} nx ${target} ${project} ${ configuration ? `--configuration=${configuration}` : '' @@ -175,7 +180,7 @@ function launchProcess( detached: true, shell: true, cwd: process.cwd(), - stdio: USE_VERBOSE_LOGGING ? 'inherit' : undefined, + stdio: shouldLog ? 'inherit' : undefined, env: { ...process.env, // Make sure NODE_ENV is set to test