wdio-reportportal-reporter
wdio-reportportal-reporter copied to clipboard
Test hangs when exception is thrown in after suite hook
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
@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.
})
})