Skip to content

[🐛 Bug]: afterStep hook type issue when using async #14826

@franck-jude

Description

@franck-jude

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.12

Node.js Version

22.20.0

Mode

WDIO Testrunner

Which capabilities are you using?

What happened?

Hello,
It seems i'm dealing with some type issue with the afterStep hook from wdio config file, when using async functions using beforeScenario, afterStep, afterScenario etc... in async mode, using typescript and eslint9.

To execute async function (ie browser.takeScreenshot) we need to mark the hook as async ie:


afterScenario: async (world, result) => { 
...
}

It seems to work well when done, however using latest eslint some type error is detected on these hooks:

"Promise-returning function provided to property where a void return was expected.eslint@typescript-eslint/no-misused-promises"

indeed if we take a look at @wdio/cucumber-framework/build/types.d.ts :

afterStep?(step: PickleStep, scenario: Pickle, result: Frameworks.PickleResult, context: Object): void;
this is in contrast of other hooks that may return promises ie @wdio/types/build/Services.d.ts :

onPrepare?(config: TestrunnerOptions, capabilities: RemoteCapabilities): unknown | Promise<unknown>;
However, i still can find some exemples here and there regarding this usage ie in the official doc:

> A WebdriverIO reporter plugin to create [Allure Test Reports](https://allurereport.org/docs/webdriverio/).

this is given as exemple:


afterStep: async function (step, scenario, { error, duration, passed }, context) {
  if (error) {
    await browser.takeScreenshot();
  }
}

I tried multiple approaches to get rid of this lint issue with no success so far...

Am I missing something ?

If I bypass linting using no-misused-promises exception, could that possibly break things ?

It was working before the error was detected, but I'm now wondering if "Promise" shouldn't be added as returned type to these hooks in type.d.ts such as these in services.d.ts , if documentation & exemples are correct ; if my assumption are well-founded i would be happy to help & create a PR.

Thank you !

What is your expected behavior?

No lint issue when using async hooks.

How to reproduce the bug.

Use async function in hooks described in type.d.ts that return void only ie afterStep, beforeScenario, etc... and declare them as async:

beforeScenario: async world => {
            await browser.execute('window.__ACTIVATE_CONSOLE_WATCH && window.__ACTIVATE_CONSOLE_WATCH();');
}

Relevant log output

Promise-returning function provided to property where a void return was expected.sonarqube(typescript:S6544)

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions