Skip to content

[🐛 Bug]: context.skip() behaviour is inconsistent with Sync and Async mocha hooks #13620

@vignesh-grexit

Description

@vignesh-grexit

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

v18

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [{
        browserName: 'chrome'
 }],

What happened?

I've encountered inconsistent behaviour when trying to skip tests using context.skip() within mocha hook beforeTest.
Specifically, when I define async beforeTest and call context.skip(), the test does not get skipped.

async beforeTest (test, context) {
context.skip()
}

However, when I define an sync beforeTest and call context.skip(), the test get skipped as expected

beforeTest: function (test, context) {
  context.skip()
}

Upon analysis, I found that we are resolving the rejected promise that is returned.

if (result && typeof result.then === 'function') {
return result.then(resolve, (e: Error) => {
log.error(e.stack || e.message)
resolve(e)
})
}

I would appreciate your thoughts on rejecting the rejected promise with a message like sync|async skip; aborting execution to ensure the test is skipped as intended.

What is your expected behavior?

When context.skip() is called in an async beforeTest, the test should be skipped, just as it works with sync beforeTest.

How to reproduce the bug.

conf file

// wdio.conf.js

export const config = {
    runner: 'local',
    specs: [
        './test/specs/**/*.js'
    ],

    exclude: [
    ],
    capabilities: [{
        browserName: 'chrome'
    }],
    logLevel: 'error',
    bail: 0,
    waitforTimeout: 10000,
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    framework: 'mocha',
    reporters: ['spec'],
    mochaOpts: {
        ui: 'bdd',
        timeout: 60000,
    },
    async beforeTest (test, context) {
        context.skip()
    }
}

test file

//test/specs/test.skip.js

describe('SKIP TEST', () => {

    it('TO SKIP', () => {
        console.log('SHOULD NOT BE PRINTED...')
    })

})

Relevant log output

[0-0] RUNNING in chrome - file:///test/specs/test.skip.js
[0-0] 2024-09-19T16:29:20.386Z ERROR @wdio/utils:shim: sync skip; aborting execution
[0-0] SHOULD NOT BE PRINTED...
[0-0] PASSED in chrome - file:///test/specs/test.skip.js

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

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions