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

Fix for #10853 - Show test logs in terminal grouped by Worker Instance #11871

12 changes: 12 additions & 0 deletions packages/wdio-cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,13 @@ export const TESTRUNNER_DEFAULTS: Options.Definition<Options.Testrunner> = {
type: 'boolean',
default: true
},
/**
* whether or not print the log output grouped by Test Spec
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved
*/
groupLogsByTestSpec: {
type: 'boolean',
default: false
},
/**
* list of strings to watch of `wdio` command is called with `--watch` flag
*/
Expand Down Expand Up @@ -952,3 +959,8 @@ export const TESTRUNNER_DEFAULTS: Options.Definition<Options.Testrunner> = {
beforeAssertion: HOOK_DEFINITION,
afterAssertion: HOOK_DEFINITION
}

export const WORKER_GROUPLOGS_MESSAGES = {
normalExit: (cid: string) => `\n***** List of steps of WorkerID=[${cid}] *****`,
exitWithError: (cid: string) => `\n***** List of steps of WorkerID=[${cid}] that preceded the error above *****`
}
15 changes: 14 additions & 1 deletion packages/wdio-cli/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Options, Capabilities, Services } from '@wdio/types'

import CLInterface from './interface.js'
import { runLauncherHook, runOnCompleteHook, runServiceHook } from './utils.js'
import { TESTRUNNER_DEFAULTS } from './constants.js'
import { TESTRUNNER_DEFAULTS, WORKER_GROUPLOGS_MESSAGES } from './constants.js'
import type { HookError } from './utils.js'
import type { RunCommandArguments } from './types.js'

Expand Down Expand Up @@ -470,6 +470,19 @@ class Launcher {
})
worker.on('message', this.interface.onMessage.bind(this.interface))
worker.on('error', this.interface.onMessage.bind(this.interface))
worker.on('exit', (code) => {
if (!this.configParser.getConfig().groupLogsByTestSpec) {
return
}
if (code.exitCode === 0) {
console.log(WORKER_GROUPLOGS_MESSAGES.normalExit(code.cid))
} else {
console.log(WORKER_GROUPLOGS_MESSAGES.exitWithError(code.cid))
}
worker.logsAggregator.forEach((logLine) => {
console.log(logLine.replace(new RegExp('\\n$'), ''))
})
})
worker.on('exit', this._endHandler.bind(this))
}

Expand Down
1 change: 1 addition & 0 deletions packages/wdio-config/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DEFAULT_CONFIGS: () => Omit<Options.Testrunner, 'capabilities'> = (
outputDir: undefined,
logLevel: 'info' as const,
logLevels: {},
groupLogsByTestSpec: false,
excludeDriverLogs: [],
bail: 0,
waitforInterval: 500,
Expand Down
8 changes: 6 additions & 2 deletions packages/wdio-local-runner/src/transformStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import type { Readable, TransformCallback } from 'node:stream'
import { Transform } from 'node:stream'
import { DEBUGGER_MESSAGES } from './constants.js'

export default function runnerTransformStream(cid: string, inputStream: Readable): Readable {
export default function runnerTransformStream(cid: string, inputStream: Readable, aggregator?: string[]): Readable {
return inputStream
.pipe(split(/\r?\n/, line => `${line}\n`))
.pipe(ignore(DEBUGGER_MESSAGES))
.pipe(map(line => `[${cid}] ${line}`))
.pipe(map((line) => {
const newLine = `[${cid}] ${line}`
aggregator ? aggregator.push(newLine) : 0
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved
return newLine
}))
}

function ignore(patternsToIgnore: string[]) {
Expand Down
10 changes: 9 additions & 1 deletion packages/wdio-local-runner/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class WorkerInstance extends EventEmitter implements Workers.Work
childProcess?: ChildProcess
sessionId?: string
server?: Record<string, any>
logsAggregator: string[] = []

instances?: Record<string, { sessionId: string }>
isMultiremote?: boolean
Expand Down Expand Up @@ -149,7 +150,14 @@ export default class WorkerInstance extends EventEmitter implements Workers.Work
/* istanbul ignore if */
if (!process.env.VITEST_WORKER_ID) {
if (childProcess.stdout !== null) {
runnerTransformStream(cid, childProcess.stdout).pipe(stdOutStream)
if (this.config.groupLogsByTestSpec) {
// Test spec logs are collected only from child stdout stream
// and then printed when the worker exits
// As a result, there is no pipe to parent stdout stream here
runnerTransformStream(cid, childProcess.stdout, this.logsAggregator)
} else {
runnerTransformStream(cid, childProcess.stdout).pipe(stdOutStream)
}
}

if (childProcess.stderr !== null) {
Expand Down
10 changes: 10 additions & 0 deletions packages/wdio-types/src/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ export interface Testrunner extends Hooks, Omit<WebdriverIO, 'capabilities'>, We
* Whether or not retried spec files should be retried immediately or deferred to the end of the queue
*/
specFileRetriesDeferred?: boolean
/**
* Choose the log output view.
* If set to "false" logs from different Test Specs will be printed in real-time.
christian-bromann marked this conversation as resolved.
Show resolved Hide resolved
* Please note that this may result in the mixing of log outputs from different Test Specs when running in parallel.
* If set to "true" log outputs will be grouped by test files and printed only when the test is completed.
* By default, it is set to "false" so logs are printed in real-time.
*
* @default false
*/
groupLogsByTestSpec?: boolean,
/**
* Services take over a specific job you don't want to take care of. They enhance
* your test setup with almost no effort.
Expand Down
3 changes: 2 additions & 1 deletion packages/wdio-types/src/Services.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { DesiredCapabilities, RemoteCapability, RemoteCapabilities } from './Capabilities.js'
import type { Testrunner as TestrunnerOptions, WebdriverIO as WebdriverIOOptions } from './Options.js'
import type { Suite, Test, TestResult } from './Frameworks.js'
import type { Worker } from './Workers.js'

export interface RunnerInstance {
initialize(): Promise<void>
shutdown(): Promise<boolean>
closeSession?: (cid: number) => Promise<void>
getWorkerCount(): number
run(args: any): NodeJS.EventEmitter
run(args: any): Worker
workerPool: any
browserPool: any
}
Expand Down
1 change: 1 addition & 0 deletions packages/wdio-types/src/Workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Worker
postMessage: (command: string, args: WorkerMessageArgs) => void;
specs: string[];
sessionId?: string;
logsAggregator: string[]
}

export type WorkerPool = Record<string, Worker>;
13 changes: 13 additions & 0 deletions website/docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ Whether or not retried spec files should be retried immediately or deferred to t
Type: `Boolean`<br />
Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

WebdriverIO Services übernehmen eine bestimmte Aufgabe, um die Sie sich nicht kümmern möchten. Sie erweitern Ihren Testaufbau nahezu ohne Aufwand.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Los servicios se hacen cargo de un trabajo específico que no desea cuidar. Mejoran su configuración de prueba sin casi ningún esfuerzo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

سرویس ها کار خاصی را به عهده می گیرند که شما نمی خواهید از آن مراقبت کنید. آنها تقریباً بدون هیچ تلاشی تنظیمات تست شما را بهبود می بخشند.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

सेवाएँ एक विशिष्ट कार्य लेती हैं जिसकी आप देखभाल नहीं करना चाहते हैं। वे लगभग बिना किसी प्रयास के आपके परीक्षण सेटअप को बढ़ाते हैं।
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t

Type: `Boolean`<br /> Default: `true`

### groupLogsByTestSpec

Choose the log output view.

If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel.

If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed.
tech-dm-klymenko marked this conversation as resolved.
Show resolved Hide resolved

By default, it is set to `false` so logs are printed in real-time.

Type: `Boolean`<br />
Default: `false`

### services

Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.
Expand Down