Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test hangs when exception is thrown in after suite hook #139

Open
dorg-jskinner opened this issue Jan 22, 2021 · 1 comment
Open

Test hangs when exception is thrown in after suite hook #139

dorg-jskinner opened this issue Jan 22, 2021 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dorg-jskinner
Copy link

If there is an exception in Mocha's after suite hook, there will be an UnhandledPromiseRejectionWarning in reporter.js which will cause the test to hang.

To reproduce, set up a test that has an exception in the Mocha after hook.

Environment

  • WebdriverIO version: 5.18.7
  • wdio-reportportal-version version: 6.1.0
  • Node.js version: 14.15.4
  • wdio/mocha-framework: 5.18.7
  • Additional wdio packages used (if applicable):

Additional context:
The actual error thrown is:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of null
at ReportPortalReporter.onTestStart (C:\automation\workspace\dozi-apps-web-engage-ui\node_modules\wdio-reportportal-reporter\build\reporter.js:137:37)
at ReportPortalReporter.onHookEnd (C:\automation\workspace\dozi-apps-web-engage-ui\node_modules\wdio-reportportal-reporter\build\reporter.js:265:22)

This is what I believe is happening after some investigation...
In this case, in the onHookEnd in the reporter.js, there is an error and testItem in null so it is calling the onTestStart method. In the onTestStart method, it tries to get the current suite but since we are in the after suite hook, the suite no longer exists so it is null. When the following line is called:
const { tempId, promise } = this.client.startTestItem(testStartObj, this.tempLaunchId, suite.id);
suite is null so it is not able to get suite.id which is throwing the Cannot read property 'id' of null

@BorisOsipov BorisOsipov added bug Something isn't working help wanted Extra attention is needed labels Jan 22, 2021
@BorisOsipov
Copy link
Owner

@dorg-jskinner thanks for reporting this. I reproduced the error.
Btw it will be not easy to fix. Current reporter logic aren't ready to report hooks and especially such mocha after suite hooks. I would suggest add more describes and make this hook bounded to some describe e.g.
before

describe('My suite 1', () => {
    it('passed test', async () => {
        //await browser.url("https://feedly.com/i/my")
        //await browser.pause(Math.floor(Math.random() * (1001)) + 2000);
    });
});
describe('My suite 2', () => {
    it('passed test', async () => {
        //await browser.url("https://feedly.com/i/my")
        //await browser.pause(Math.floor(Math.random() * (1001)) + 2000);
    });
});
after(() => {
    //will throw error and hang
})

after

describe('my awesome suite', () => {
    describe('My suite 1', () => {
        it('passed test', async () => {
            //await browser.url("https://feedly.com/i/my")
            //await browser.pause(Math.floor(Math.random() * (1001)) + 2000);
        });
    });
    describe('My suite 2', () => {
        it('passed test', async () => {
            //await browser.url("https://feedly.com/i/my")
            //await browser.pause(Math.floor(Math.random() * (1001)) + 2000);
        });
    });
    after(() => {
        //will throw error and no issue.
    })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants