Skip to content

Commit

Permalink
Fixing exception logging
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerstedt committed Apr 26, 2019
1 parent b1e1a04 commit 9c84d06
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
5 changes: 2 additions & 3 deletions packages/wdio-cucumber-framework/src/index.js
Expand Up @@ -11,7 +11,7 @@ import { EventEmitter } from 'events'

import logger from '@wdio/logger'
import { executeHooksWithArgs } from '@wdio/config'
import { executeSync, executeAsync, runFnInFiberContextWithCallback, runTestInFiberContext } from '@wdio/sync'
import { executeSync, executeAsync, runFnInFiberContextWithCallback } from '@wdio/sync'
import { DEFAULT_OPTS } from './constants'

const log = logger('@wdio/cucumber-framework')
Expand Down Expand Up @@ -75,8 +75,7 @@ class CucumberAdapter {

await executeHooksWithArgs(this.config.before, [this.capabilities, this.specs])
result = await runtime.start() ? 0 : 1
}
catch (e) {
} catch (e) {
runtimeError = e
result = 1
}
Expand Down
99 changes: 52 additions & 47 deletions packages/wdio-cucumber-framework/src/reporter.js
Expand Up @@ -3,8 +3,6 @@ import { CucumberEventListener } from './CucumberEventListener'
import { createStepArgument } from './utils'
import * as path from 'path'

const SETTLE_TIMEOUT = 5000

class CucumberReporter {
gherkinDocEvents = []

Expand Down Expand Up @@ -141,7 +139,7 @@ class CucumberReporter {
}
}

this.emit('test:' + e, {
const payload = {
uid: this.getUniqueIdentifier(step),
title: stepTitle.trim(),
type: 'test',
Expand All @@ -152,7 +150,9 @@ class CucumberReporter {
tags: scenario.tags,
keyword: step.keyword,
argument: createStepArgument(step)
})
}

this.emit('test:' + e, payload)
}

handleAfterScenario (uri, feature, scenario, sourceLocation) {
Expand All @@ -179,51 +179,13 @@ class CucumberReporter {
}

emit (event, payload) {
const message = {
event: event,
cid: this.cid,
uid: payload.uid,
title: payload.title,
pending: payload.pending || false,
parent: payload.parent || null,
type: payload.type,
file: payload.file,
err: payload.error || {},
duration: payload.duration,
runner: {
[this.cid]: this.capabilities
},
specs: this.specs,
tags: payload.tags || [],
featureName: payload.featureName,
scenarioName: payload.scenarioName,
description: payload.description,
keyword: payload.keyword || null,
argument: payload.argument
}
let message = this.formatMessage({ type: event, payload })

//let message = this.formatMessage({ type: event, payload, err })
this.reporter.emit(event, message)
}
message.cid = this.cid
message.specs = this.specs
message.uid = payload.uid

send (...args) {
return process.send.apply(process, args)
}

/**
* wait until all messages were sent to parent
*/
waitUntilSettled () {
return new Promise((resolve) => {
const start = (new Date()).getTime()
const interval = setInterval(() => {
const now = (new Date()).getTime()

if (this.sentMessages !== this.receivedMessages && now - start < SETTLE_TIMEOUT) return
clearInterval(interval)
resolve()
}, 100)
})
this.reporter.emit(message.type, message)
}

getTitle (featureOrScenario) {
Expand Down Expand Up @@ -269,6 +231,49 @@ class CucumberReporter {

return name + line
}

formatMessage (params) {
let message = {
type: params.type
}

if (params.payload && params.payload.error) {
message.error = params.payload.error

/**
* hook failures are emitted as "test:fail"
*/
if (params.payload.title && params.payload.title.match(/^"(before|after)( all)*" hook/g)) {
message.type = 'hook:end'
}
}

if (params.payload) {
message.title = params.payload.title
message.parent = params.payload.parent ? params.payload.parent.title : null

message.fullTitle = params.payload.fullTitle ? params.payload.fullTitle() : message.parent + ' ' + message.title
message.pending = params.payload.pending || false
message.file = params.payload.file
message.duration = params.payload.duration

/**
* Add the current test title to the payload for cases where it helps to
* identify the test, e.g. when running inside a beforeEach hook
*/
if (params.payload.ctx && params.payload.ctx.currentTest) {
message.currentTest = params.payload.ctx.currentTest.title
}

if (params.type.match(/Test/)) {
message.passed = (params.payload.state === 'passed')
}

if (params.payload.context) { message.context = params.payload.context }
}

return message
}
}

export default CucumberReporter

0 comments on commit 9c84d06

Please sign in to comment.