Skip to content

Commit

Permalink
Testing data passed to the emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Kliment committed Jun 12, 2015
1 parent 34c9ed1 commit 473c70e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/transaction-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ class TransactionRunner
data['results']['general'].push { severity: 'error', message: message }

data.message = message
data.test?.status = 'fail'

data['test'] ?= {}
data['test']['status'] = 'fail'

data['test']['results'] ?= {}

for key, value of data.results
data['test']['results'][key] = value

@configuration.emitter.emit 'test fail', data.test
else
Expand Down
84 changes: 75 additions & 9 deletions test/unit/transaction-runner-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1094,12 +1094,23 @@ describe 'TransactionRunner', ()->
assert.ok configuration.emitter.emit.calledWith "test fail"
done()

it 'should add fail message as a error under `general` to the results', (done) ->
it 'should add fail message as a error under `general` to the results on transaction', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = transaction['results']['general'].map (value, index) -> value['message']
assert.include messages.join(), 'expected false to be truthy'
done()

it 'should add fail message as a error under `general` to the results on test passed to the emitter', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = []
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1]['results']['general'].map(
(value, index) -> value['message']
)
assert.include messages.join(), 'expected false to be truthy'
done()

describe 'with after hook that throws a chai expectation error', () ->
beforeEach () ->
runner.hooks.afterHooks =
Expand Down Expand Up @@ -1127,13 +1138,22 @@ describe 'TransactionRunner', ()->
assert.equal transaction.test.status, 'fail'
done()

it 'should add fail message as a error under `general` to the results', (done) ->
it 'should add fail message as a error under `general` to the results on transaction', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = transaction['results']['general'].map (value, index) -> value['message']
assert.include messages.join(), 'expected false to be truthy'
done()


it 'should add fail message as a error under `general` to the results on test passed to the emitter', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = []
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1]['results']['general'].map(
(value, index) -> value['message']
)
assert.include messages.join(), 'expected false to be truthy'
done()

describe 'with hook failing the transaction', () ->
describe 'in before hook', () ->
Expand Down Expand Up @@ -1178,12 +1198,24 @@ describe 'TransactionRunner', ()->
assert.include messages.join(), "Failed in before hook:"
done()

it 'should add fail message as a error under `general` to the results', (done) ->
it 'should add fail message as a error under `general` to the results on the transaction', (done) ->
runner.executeAllTransactions [clonedTransaction], runner.hooks, () ->
messages = clonedTransaction['results']['general'].map (value, index) -> value['message']
assert.include messages.join(), 'Message before'
done()


it 'should add fail message as a error under `general` to the results on test passed to the emitter', (done) ->
runner.executeAllTransactions [clonedTransaction], runner.hooks, () ->
messages = []
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1]['results']['general'].map(
(value, index) -> value['message']
)
assert.include messages.join(), 'Message before'
done()

describe 'when message is set to fail also in after hook', () ->
beforeEach () ->
runner.hooks.afterHooks =
Expand All @@ -1198,7 +1230,7 @@ describe 'TransactionRunner', ()->
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1].message
assert.notInclude messages, "Message after fail"
assert.notInclude messages.join(), "Message after fail"
done()

it 'should not mention after hook in the error message', (done) ->
Expand All @@ -1207,15 +1239,26 @@ describe 'TransactionRunner', ()->
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1].message
assert.notInclude messages, "Failed in after hook:"
assert.notInclude messages.join(), "Failed in after hook:"
done()

it 'should not add fail message as a error under `general` to the results', (done) ->
it 'should not add fail message as a error under `general` to the results on the transaction', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = transaction['results']['general'].map (value, index) -> value['message']
assert.notInclude messages.join(), 'Message after fail'
done()

it 'should not add fail message as a error under `general` to the results on test passed to the emitter', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = []
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1]['results']['general'].map(
(value, index) -> value['message']
)
assert.notInclude messages.join(), 'Message after fail'
done()

describe 'in after hook when transaction fails ', () ->
modifiedTransaction = {}
beforeEach () ->
Expand Down Expand Up @@ -1267,12 +1310,23 @@ describe 'TransactionRunner', ()->
assert.notInclude messages, "Failed in after hook:"
done()

it 'should not add fail message as a error under `general` to the results', (done) ->
it 'should not add fail message as a error under `general` to the results on the transaction', (done) ->
runner.executeAllTransactions [modifiedTransaction], runner.hooks, () ->
messages = modifiedTransaction['results']['general'].map (value, index) -> value['message']
assert.notInclude messages.join(), 'Message after fail'
done()

it 'should not add fail message as a error under `general` to the results on test passed to the emitter', (done) ->
runner.executeAllTransactions [modifiedTransaction], runner.hooks, () ->
messages = []
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1]['results']['general'].map(
(value, index) -> value['message']
)
assert.notInclude messages.join(), 'Message after fail'
done()

describe 'in after hook when transaction passes ', () ->
beforeEach () ->
runner.hooks.afterHooks =
Expand Down Expand Up @@ -1324,12 +1378,24 @@ describe 'TransactionRunner', ()->
assert.equal transaction.test.status, 'fail'
done()

it 'should not add fail message as a error under `general` to the results', (done) ->
it 'should add fail message as a error under `general` to the results', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = transaction['results']['general'].map (value, index) -> value['message']
assert.include messages.join(), 'Message after pass'
done()

it 'should not add fail message as a error under `general` to the results on test passed to the emitter', (done) ->
runner.executeAllTransactions [transaction], runner.hooks, () ->
messages = []
callCount = configuration.emitter.emit.callCount
for callNo in [0.. callCount - 1]
messages.push configuration.emitter.emit.getCall(callNo).args[1]['results']['general'].map(
(value, index) -> value['message']
)
assert.include messages.join(), 'Message after pass'
done()


describe 'without hooks', () ->
beforeEach () ->
sinon.stub configuration.emitter, 'emit'
Expand Down

0 comments on commit 473c70e

Please sign in to comment.