File tree 3 files changed +27
-4
lines changed
3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { Duration } from '@cucumber/messages'
2
+
3
+ const NANOS_IN_SECOND = 1_000_000_000
4
+
5
+ export function durationToNanoseconds ( duration : Duration ) : number {
6
+ return Math . floor ( duration . seconds * NANOS_IN_SECOND + duration . nanos )
7
+ }
Original file line number Diff line number Diff line change
1
+ import { expect } from 'chai'
2
+ import { durationToNanoseconds } from './duration_helpers'
3
+
4
+ describe ( 'duration helpers' , ( ) => {
5
+ describe ( 'durationToNanoseconds' , ( ) => {
6
+ it ( 'should convert under a second' , ( ) => {
7
+ expect ( durationToNanoseconds ( { seconds : 0 , nanos : 257344166 } ) ) . to . eq (
8
+ 257344166
9
+ )
10
+ } )
11
+
12
+ it ( 'should convert over a second' , ( ) => {
13
+ expect ( durationToNanoseconds ( { seconds : 2 , nanos : 1043459 } ) ) . to . eq (
14
+ 2001043459
15
+ )
16
+ } )
17
+ } )
18
+ } )
Original file line number Diff line number Diff line change 8
8
import { ITestCaseAttempt } from './helpers/event_data_collector'
9
9
import { doesHaveValue , doesNotHaveValue } from '../value_checker'
10
10
import { parseStepArgument } from '../step_arguments'
11
+ import { durationToNanoseconds } from './helpers/duration_helpers'
11
12
12
13
const { getGherkinStepMap, getGherkinScenarioMap } = GherkinDocumentParser
13
14
@@ -280,10 +281,7 @@ export default class JsonFormatter extends Formatter {
280
281
status : messages . TestStepResultStatus [ status ] . toLowerCase ( ) ,
281
282
}
282
283
if ( doesHaveValue ( testStepResult . duration ) ) {
283
- data . result . duration =
284
- messages . TimeConversion . durationToMilliseconds (
285
- testStepResult . duration
286
- ) * 1000000
284
+ data . result . duration = durationToNanoseconds ( testStepResult . duration )
287
285
}
288
286
if (
289
287
status === messages . TestStepResultStatus . FAILED &&
You can’t perform that action at this time.
0 commit comments