From eeff7183a82b9c0f98a0b4b0aeb18f05f661483d Mon Sep 17 00:00:00 2001 From: Dmitrii Gridnev Date: Wed, 28 Aug 2024 11:06:48 +0200 Subject: [PATCH] fix: async tests in Mocha Fixed the issue with async tests not being reported correctly. --- qase-mocha/changelog.md | 6 ++++++ qase-mocha/package.json | 2 +- qase-mocha/src/reporter.ts | 8 +++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/qase-mocha/changelog.md b/qase-mocha/changelog.md index 8c6cadf9..fa01c33c 100644 --- a/qase-mocha/changelog.md +++ b/qase-mocha/changelog.md @@ -1,3 +1,9 @@ +# qase-mocha@1.0.0-beta.4 + +## What's new + +Fixed the issue with async tests not being reported correctly. + # qase-mocha@1.0.0-beta.3 ## What's new diff --git a/qase-mocha/package.json b/qase-mocha/package.json index a0afd47b..cae0f1f6 100644 --- a/qase-mocha/package.json +++ b/qase-mocha/package.json @@ -1,6 +1,6 @@ { "name": "mocha-qase-reporter", - "version": "1.0.0-beta.3", + "version": "1.0.0-beta.4", "description": "Mocha Cypress Reporter", "homepage": "https://github.com/qase-tms/qase-javascript", "sideEffects": false, diff --git a/qase-mocha/src/reporter.ts b/qase-mocha/src/reporter.ts index 21241e23..7180d8a3 100644 --- a/qase-mocha/src/reporter.ts +++ b/qase-mocha/src/reporter.ts @@ -86,7 +86,8 @@ export class MochaQaseReporter extends reporters.Base { this.runner.on(Events.EVENT_HOOK_BEGIN, (hook: Hook) => this.addMethods(hook.ctx)); this.runner.on(Events.EVENT_TEST_BEGIN, () => this.onStartTest()); - this.runner.on(Events.EVENT_TEST_END, (test) => this.onEndTest(test)); + // eslint-disable-next-line @typescript-eslint/no-misused-promises + this.runner.on(Events.EVENT_TEST_END, async (test) => await this.onEndTest(test)); }; private onStartRun() { @@ -116,7 +117,7 @@ export class MochaQaseReporter extends reporters.Base { this.currentType = 'test'; } - private onEndTest(test: Mocha.Test) { + private async onEndTest(test: Mocha.Test) { if (this.metadata.ignore) { return; } @@ -172,7 +173,8 @@ export class MochaQaseReporter extends reporters.Base { title: this.metadata.title && this.metadata.title != '' ? this.metadata.title : test.title, }; - deasyncPromise(this.reporter.addTestResult(result)); + await this.reporter.addTestResult(result); + this.metadata.clear(); this.currentTest = new currentTest(); }