From 27f9a09c6b4d9d23fc628e9ed3039f168294636b Mon Sep 17 00:00:00 2001 From: Ingmar Stein Date: Wed, 14 Jun 2017 22:06:11 +0200 Subject: [PATCH 1/3] fix: NaNms duration (#376) --- src/reporters/base-reporter.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/reporters/base-reporter.coffee b/src/reporters/base-reporter.coffee index 37b0a5185..2d3959bf4 100644 --- a/src/reporters/base-reporter.coffee +++ b/src/reporters/base-reporter.coffee @@ -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) => @@ -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 From 6423d41c0620c13183402cda5cdb9fe68282b71e Mon Sep 17 00:00:00 2001 From: Ingmar Stein Date: Thu, 15 Jun 2017 06:24:23 +0200 Subject: [PATCH 2/3] docs: document transaction.id --- docs/data-structures.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/data-structures.md b/docs/data-structures.md index f6ffcb774..4dd7254e2 100644 --- a/docs/data-structures.md +++ b/docs/data-structures.md @@ -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) From 7b1679fded4c593be33304a74df79fa2e09ca6ae Mon Sep 17 00:00:00 2001 From: Ingmar Stein Date: Thu, 15 Jun 2017 10:45:38 +0200 Subject: [PATCH 3/3] test: add test that checks if duration is NaN --- test/unit/reporters/base-reporter-test.coffee | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/unit/reporters/base-reporter-test.coffee b/test/unit/reporters/base-reporter-test.coffee index 2ad00cb8b..c4e2c2ca8 100644 --- a/test/unit/reporters/base-reporter-test.coffee +++ b/test/unit/reporters/base-reporter-test.coffee @@ -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