Skip to content

Commit

Permalink
fix: async tests in Mocha
Browse files Browse the repository at this point in the history
Fixed the issue with async tests not being reported correctly.
  • Loading branch information
gibiw committed Aug 28, 2024
1 parent f5cad12 commit eeff718
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions qase-mocha/changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion qase-mocha/package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
8 changes: 5 additions & 3 deletions qase-mocha/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit eeff718

Please sign in to comment.