-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure durations are integers in json formatter
- Loading branch information
1 parent
fb3144e
commit 35730c4
Showing
3 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Duration } from '@cucumber/messages' | ||
|
||
const NANOS_IN_SECOND = 1_000_000_000 | ||
|
||
export function durationToNanoseconds(duration: Duration): number { | ||
return Math.floor(duration.seconds * NANOS_IN_SECOND + duration.nanos) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from 'chai' | ||
import { durationToNanoseconds } from './duration_helpers' | ||
|
||
describe('duration helpers', () => { | ||
describe('durationToNanoseconds', () => { | ||
it('should convert under a second', () => { | ||
expect(durationToNanoseconds({ seconds: 0, nanos: 257344166 })).to.eq( | ||
257344166 | ||
) | ||
}) | ||
|
||
it('should convert over a second', () => { | ||
expect(durationToNanoseconds({ seconds: 2, nanos: 1043459 })).to.eq( | ||
2001043459 | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters