Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #376 (NaNms duration) #800

Merged
merged 3 commits into from
Jun 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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