Skip to content

Commit

Permalink
also print error message if present (#12378)
Browse files Browse the repository at this point in the history
  • Loading branch information
torbenkohlmeier committed Feb 28, 2024
1 parent 507bc3f commit 261b015
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/wdio-allure-reporter/src/compoundError.ts
Expand Up @@ -11,9 +11,13 @@ export default class CompoundError extends Error {

constructor(...innerErrors: Error[]) {
const message = ['CompoundError: One or more errors occurred. ---\n'].
concat(innerErrors.map(x => x.stack
? `${indentAll(x.stack)}\n--- End of stack trace ---\n`
: ` ${x.message}\n--- End of error message ---\n`
concat(innerErrors.map(x =>
x.message && x.stack?.includes(x.message)
? (x.stack ? `${indentAll(x.stack)}\n--- End of stack trace ---\n` : '')
: (
(x.message ? ` ${x.message}\n--- End of error message ---\n` : '') +
(x.stack ? `${indentAll(x.stack)}\n--- End of stack trace ---\n` : '')
)
)).join('\n')

super(message)
Expand Down
15 changes: 15 additions & 0 deletions packages/wdio-allure-reporter/tests/__fixtures__/testState.ts
Expand Up @@ -47,6 +47,21 @@ export function testFailedWithMultipleErrors() {
return Object.assign(testState(), { errors, state: 'failed', end: '2018-05-14T15:17:21.631Z', _duration: 2730 })
}

export function testFailedWithMultipleErrorsAndStacksNotContainingMessages() {
const errors =
[
{
message: 'ReferenceError: All is Dust',
stack: 'stack trace of ReferenceError'
},
{
message: 'InternalError: Abandon Hope',
stack: 'stack trace of InternalError'
}
]
return Object.assign(testState(), { errors, state: 'failed', end: '2018-05-14T15:17:21.631Z', _duration: 2730 })
}

export function testFailedWithAssertionErrorFromExpectWebdriverIO() {
const errors =
[
Expand Down
4 changes: 2 additions & 2 deletions packages/wdio-allure-reporter/tests/compoundError.test.ts
Expand Up @@ -80,9 +80,9 @@ describe('CompoundError', () => {
const lines = error.message.split('\n')

expect(lines[0]).toBe('CompoundError: One or more errors occurred. ---')
expect(lines[2]).toBe(' goodbye')
expect(lines[2]).toBe(' goodbye')
expect(lines[3]).toBe('--- End of error message ---')
expect(lines[5]).toBe(' hello')
expect(lines[5]).toBe(' hello')
expect(lines[6]).toBe('--- End of error message ---')
})
})
34 changes: 33 additions & 1 deletion packages/wdio-allure-reporter/tests/suite.test.ts
Expand Up @@ -19,7 +19,7 @@ import { clean, getResults, mapBy } from './helpers/wdio-allure-helper'
import { runnerEnd, runnerStart } from './__fixtures__/runner.js'
import { suiteEnd, suiteStart } from './__fixtures__/suite.js'
import {
testFailed, testPending, testStart, testFailedWithMultipleErrors,
testFailed, testPending, testStart, testFailedWithMultipleErrors, testFailedWithMultipleErrorsAndStacksNotContainingMessages,
hookStart, hookFailed,
testFailedWithAssertionErrorFromExpectWebdriverIO, eachHookFailed, eachHookStart
} from './__fixtures__/testState.js'
Expand Down Expand Up @@ -321,6 +321,38 @@ describe('Failed tests', () => {
expect(lines[5].trim()).toBe('InternalError: Abandon Hope')
})

it('should detect failed test case with multiple errors whose stacks do not contain error messages', () => {
const reporter = new AllureReporter({ outputDir })
const runnerEvent = runnerStart()

runnerEvent.config.framework = 'jasmine'

delete runnerEvent.capabilities.browserName
delete runnerEvent.capabilities.version

reporter.onRunnerStart(runnerEvent)
reporter.onSuiteStart(suiteStart())
reporter.onTestStart(testStart())
reporter.onTestFail(testFailedWithMultipleErrorsAndStacksNotContainingMessages())
reporter.onSuiteEnd(suiteEnd())
reporter.onRunnerEnd(runnerEnd())

const { results } = getResults(outputDir)

expect(results).toHaveLength(1)
expect(results[0].name).toEqual('should can do something')
expect(results[0].status).toEqual(Status.FAILED)

const { message } = results[0].statusDetails
const lines = message.split('\n')

expect(lines[0]).toBe('CompoundError: One or more errors occurred. ---')
expect(lines[2].trim()).toBe('ReferenceError: All is Dust')
expect(lines[4].trim()).toBe('stack trace of ReferenceError')
expect(lines[7].trim()).toBe('InternalError: Abandon Hope')
expect(lines[9].trim()).toBe('stack trace of InternalError')
})

it('should detect failed test case with Assertion failed from expect-webdriverIO', () => {
const reporter = new AllureReporter({ outputDir })

Expand Down

0 comments on commit 261b015

Please sign in to comment.