reportportal / agent-js-webdriverio

Agent to integrate Webdriver.io with ReportPortal.
https://www.npmjs.com/package/@reportportal/agent-js-webdriverio
Apache License 2.0
8 stars 2 forks source link

Reporter breaks on skipped test for WebdriverIO + Mocha #46

Closed szarlatan closed 9 months ago

szarlatan commented 1 year ago

Hey there,

found a strange issue, that reporter breaks on it.skip(...) having WebdriverIO set up with Mocha (which seems quite popular pair).

Installed versions agent-js-webdriverio: ^5.0.3 webdriverio: ^7.30.2

Sample code

describe('Demo of breaking skipped tests', () => {
  it('executing test case', () => {
    expect(true).toBe(true)
  })

  it.skip('skipped test case', () => {
    expect(true).toBe(true)
  })
})

gives following output when run

[0-0] TypeError in "Demo of breaking skipped tests.executing test case"
TypeError: Cannot destructure property 'id' of 'this.storage.getCurrentTest(...)' as it is null.
    at Reporter.finishTest (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/@reportportal/agent-js-webdriverio/src/reporter.ts:177:7)
    at Reporter.onTestSkip (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/@reportportal/agent-js-webdriverio/src/reporter.ts:154:10)
    at Reporter.<anonymous> (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/@reportportal/agent-js-webdriverio/node_modules/@wdio/reporter/build/index.js:154:18)
    at Reporter.emit (node:events:526:28)
    at Reporter.emit (node:domain:475:12)
    at /Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/@wdio/runner/build/reporter.js:36:56
    at Array.forEach (<anonymous>)
    at BaseReporter.emit (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/@wdio/runner/build/reporter.js:36:25)
    at MochaAdapter.emit (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/@wdio/mocha-framework/build/index.js:257:24)
    at Runner.emit (node:events:538:35)
    at Runner.emit (node:domain:475:12)
    at next (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/mocha/lib/runner.js:759:14)
    at next (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/mocha/lib/runner.js:581:14)
    at /Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/mocha/lib/runner.js:591:7
    at next (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/mocha/lib/runner.js:474:14)
    at Immediate.<anonymous> (/Users/krzysztof.biszta/ACME/acme-app/clients/node_modules/mocha/lib/runner.js:559:5)
NikolayStanoev commented 1 year ago

Hello, we have faced the same problem while testing same setup.

The problem comes from the fact that test is not started when it.skip is used. As a result the code goes to reporter.ts and calls onTestSkip method which calls finishTest and it fails because the storage object missing information about the current test.

The fix which we tried locally seems to work on first look. We have changed the following method from reporter.ts

onTestSkip(testStats: TestStats): void {
    this.finishTest(testStats);
  }

to

onTestSkip(testStats: TestStats): void {
    this.onTestStart(testStats);
    this.finishTest(testStats);
  }

and the test was successfully added as skipped in report portal. And the execution completed without any hanging.

@AmsterGet Please take a look on this change and if it does not affect anything else - feel free to apply it.

AmsterGet commented 1 year ago

Fixed. Will be published in the scope of v5.0.4.

AmsterGet commented 9 months ago

Fixed in version 5.1.0.