Skip to content

Commit

Permalink
feat(e2e-runner): enable or disable target logging via options (#203)
Browse files Browse the repository at this point in the history
Use the new `logging` option on a target to either enable, or disable
the logging output for the specified target.

Closes #202

I tried adding some component tests; but I can't seem to mock
`child_process.spawn` properly without adding extra libraries.
  • Loading branch information
TriPSs authored Dec 20, 2023
2 parents 236c386 + 662f22f commit 2fb0b91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/e2e-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
```

Expand All @@ -56,7 +57,8 @@ Example target
{
"target": "api:serve",
"checkUrl": "http://localhost:9000/health",
"checkMaxTries": 50
"checkMaxTries": 50,
"logging": false
}
]
}
Expand Down
9 changes: 7 additions & 2 deletions packages/e2e-runner/src/executors/run/utils/nx-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface NxTargetOptions {
env?: { [key: string]: string }
reuseExistingServer?: boolean
rejectUnauthorized?: boolean
logging?: boolean
}

export class NxTarget {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -162,10 +164,13 @@ function launchProcess(
options: {
onExit: (exitCode: number | null, signal: string | null) => void
env?: { [key: string]: string }
logging?: boolean
}
): () => Promise<void> {
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}` : ''
Expand All @@ -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
Expand Down

0 comments on commit 2fb0b91

Please sign in to comment.