Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(e2e-runner): enable or disable target logging via options #203

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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