jemishgopani/wdio-json-reporter

Incorrect loop results in many duplicated test entries

Closed this issue · 1 comments

This loop seems incorrect, and results in an explosion of duplicated test entries and incorrect test counting. I wasn't able to build the project locally due to an upstream eslint dep, but bringing the inner loop outside of the loop here fixed it after bringing this code into another wdio reporter project I have.

https://github.com/fijijavis/wdio-json-reporter/blob/master/src/index.js#L22

What fixes it:

    prepareJson (runner) {
        var resultSet = initResultSet(runner)

        for (let specId of Object.keys(runner.specs)) {
            resultSet.specs.push(runner.specs[specId])
        }

        for (let suiteKey of Object.keys(this.suites)) {
            const suite = this.suites[suiteKey]
            let testSuite = {}
            testSuite.name = suite.title
            testSuite.duration = suite._duration
            testSuite.start = suite.start
            testSuite.end = suite.end
            testSuite.sessionId = runner.sessionId
            testSuite.tests = MapTests(suite.tests)
            testSuite.hooks = MapHooks(suite.hooks)

            resultSet.state.failed += testSuite.hooks.filter(hook => hook.error).length
            resultSet.state.passed += testSuite.tests.filter(test => test.state === 'passed').length
            resultSet.state.failed += testSuite.tests.filter(test => test.state === 'failed').length
            resultSet.state.skipped += testSuite.tests.filter(test => test.state === 'skipped').length
            resultSet.suites.push(testSuite)
        }

        return resultSet
    }

Stale issue message