From 90952b3f93baf9abf2ef9f69a3d7907c6f289bf0 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridnev Date: Tue, 3 Sep 2024 17:04:20 +0200 Subject: [PATCH] fix: issue with steps If `cucumber` was used to write tests, the steps were not written sequentially, but as nested ones. --- qase-wdio/src/reporter.ts | 62 ++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/qase-wdio/src/reporter.ts b/qase-wdio/src/reporter.ts index fe7413b1..8f614e02 100644 --- a/qase-wdio/src/reporter.ts +++ b/qase-wdio/src/reporter.ts @@ -135,20 +135,6 @@ export default class WDIOQaseReporter extends WDIOReporter { case '@suite': this.addSuite({ suite: tagData.value }); break; - // case 'parameters': - // const params = tagData.value.split(',').map((param) => { - // const [key, value] = param.split(':'); - // return { key, value }; - // }); - // process.emit(events.addParameters, { records: params }); - // break; - // case 'fields': - // const fields = tagData.value.split(',').map((field) => { - // const [key, value] = field.split(':'); - // return { key, value }; - // }); - // process.emit(events.addFields, { records: fields }); - // break; } } @@ -238,14 +224,51 @@ export default class WDIOQaseReporter extends WDIOReporter { return err; } - override async onTestEnd(test: TestStats) { + override async onTestPass() { + if (this._options.useCucumber) { + this._endStep(); + return; + } + + await this._endTest(TestStatusEnum.passed, null); + } + + override async onTestRetry(test: TestStats) { + const error = test.errors ? WDIOQaseReporter.transformError(test.errors) : null; + + if (this._options.useCucumber) { + this._endStep(error ? TestStatusEnum.failed : TestStatusEnum.passed); + return; + } + + await this._endTest(WDIOQaseReporter.statusMap[test.state] ?? TestStatusEnum.skipped, + error, + test.end ? test.end.valueOf() / 1000 : Date.now().valueOf() / 1000); + } + + override async onTestFail(test: TestStats) { const error = test.errors ? WDIOQaseReporter.transformError(test.errors) : null; + if (this._options.useCucumber) { + this._endStep(TestStatusEnum.failed); + return; + } + await this._endTest(WDIOQaseReporter.statusMap[test.state] ?? TestStatusEnum.skipped, error, test.end ? test.end.valueOf() / 1000 : Date.now().valueOf() / 1000); } + override async onTestSkip(test: TestStats) { + if (this._options.useCucumber) { + this._endStep(TestStatusEnum.skipped); + return; + } + + await this._endTest(WDIOQaseReporter.statusMap[test.state] ?? TestStatusEnum.skipped, + null); + } + private async _endTest(status: TestStatusEnum, err: CompoundError | null, end_time: number = Date.now().valueOf() / 1000) { const testResult = this.storage.getCurrentTest(); if (testResult === undefined || this.storage.ignore) { @@ -275,18 +298,9 @@ export default class WDIOQaseReporter extends WDIOReporter { null : err.message === undefined ? null : err.message; - console.log(testResult); await this.reporter.addTestResult(testResult); } - override onHookStart() { - console.log('Hook started'); - } - - override onHookEnd() { - console.log('Hook ended'); - } - override onBeforeCommand(command: BeforeCommandArgs) { if (!this.storage.getLastItem()) { return;