Skip to content

Commit

Permalink
fix: add IMethods interface for use in time module functions (#2111)
Browse files Browse the repository at this point in the history
* fix: add IMethods interface for use in time module

* Update CHANGELOG.md

Co-authored-by: David Goss <[email protected]>
  • Loading branch information
Manny and davidjgoss authored Aug 24, 2022
1 parent 223e9c4 commit 0ac8f58
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

## [Unreleased]
### Added
- `IPublishConfig` interface for use in return type of `makePublishConfig` instead of explicit `any` ([#1648](https://github.com/cucumber/cucumber-js/pull/2106))
- `IMethods` interface for use in `getTimestamp`, `durationBetweenTimestamps`, and `wrapPromiseWithTimeout` functions and `methods` in `time` module instead of explicit `any` ([#2111](https://github.com/cucumber/cucumber-js/pull/2111))
- `IPublishConfig` interface for use in return type of `makePublishConfig` instead of explicit `any` ([#2106](https://github.com/cucumber/cucumber-js/pull/2106))

### Fixed
- Add override to ensure `ansi-regex` version is `^5.0.1` ([#2114](https://github.com/cucumber/cucumber-js/pull/2114))
Expand Down
11 changes: 9 additions & 2 deletions src/time.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { performance } from 'perf_hooks'
import * as messages from '@cucumber/messages'
import { FakeClock, GlobalTimers, TimerId } from '@sinonjs/fake-timers'

let previousTimestamp: number

const methods: any = {
interface IMethods extends GlobalTimers<TimerId> {
beginTiming: () => void
endTiming: () => number
performance: FakeClock<TimerId>['performance']
}

const methods: Partial<IMethods> = {
beginTiming() {
previousTimestamp = getTimestamp()
},
Expand Down Expand Up @@ -44,7 +51,7 @@ export async function wrapPromiseWithTimeout<T>(
timeoutInMilliseconds: number,
timeoutMessage: string = ''
): Promise<T> {
let timeoutId: NodeJS.Timeout
let timeoutId: TimerId
if (timeoutMessage === '') {
timeoutMessage = `Action did not complete within ${timeoutInMilliseconds} milliseconds`
}
Expand Down

0 comments on commit 0ac8f58

Please sign in to comment.