Skip to content

Commit

Permalink
Merge pull request #800 from IngmarStein/master
Browse files Browse the repository at this point in the history
Fix #376 (NaNms duration)
  • Loading branch information
honzajavorek committed Jun 15, 2017
2 parents 9981e14 + 7b1679f commit 26b18ca
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/data-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Documentation of various data structures in both [Gavel.js][] and Dredd. [MSON n

Transaction object is passed as a first argument to [hook functions](hooks.md) and is one of the main public interfaces in Dredd.

- id: `GET /greetings` - identifier for this transaction
- name: `./api-description.apib > My API > Greetings > Hello, world! > Retrieve Message > Example 2` (string) - reference to the transaction definition in the original API description document (see also [Dredd Transactions][])
- origin (object) - reference to the transaction definition in the original API description document (see also [Dredd Transactions][])
- filename: `./api-description.apib` (string)
Expand Down
6 changes: 6 additions & 0 deletions src/reporters/base-reporter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class BaseReporter
emitter.on 'test pass', (test) =>
@stats.passes += 1
test['end'] = new Date()
if typeof test['start'] is 'string'
test['start'] = new Date(test['start'])
test['duration'] = test.end - test.start

emitter.on 'test skip', (test) =>
Expand All @@ -35,11 +37,15 @@ class BaseReporter
emitter.on 'test fail', (test) =>
@stats.failures += 1
test['end'] = new Date()
if typeof test['start'] is 'string'
test['start'] = new Date(test['start'])
test['duration'] = test.end - test.start

emitter.on 'test error', (error, test) =>
@stats.errors += 1
test['end'] = new Date()
if typeof test['start'] is 'string'
test['start'] = new Date(test['start'])
test['duration'] = test.end - test.start


Expand Down
39 changes: 39 additions & 0 deletions test/unit/reporters/base-reporter-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,42 @@ describe 'BaseReporter', () ->

it 'should set the end time', () ->
assert.isOk tests[0].end

describe 'when passing test start is UTC string', () ->

beforeEach () ->
test =
status: 'pass'
title: 'Passing Test'
emitter.emit 'test start', test
test.start = '2017-06-15T09:29:50.588Z'
emitter.emit 'test pass', test

it 'should set the duration', () ->
assert.isNotNaN tests[0].duration

describe 'when failed test start is UTC string', () ->

beforeEach () ->
test =
status: 'pass'
title: 'Failed Test'
emitter.emit 'test start', test
test.start = '2017-06-15T09:29:50.588Z'
emitter.emit 'test fail', test

it 'should set the duration', () ->
assert.isNotNaN tests[0].duration

describe 'when errored test start is UTC string', () ->

beforeEach () ->
test =
status: 'pass'
title: 'Errored Test'
emitter.emit 'test start', test
test.start = '2017-06-15T09:29:50.588Z'
emitter.emit 'test error', new Error('Error'), test

it 'should set the duration', () ->
assert.isNotNaN tests[0].duration

0 comments on commit 26b18ca

Please sign in to comment.