Skip to content

Commit

Permalink
rework time interfaces to avoid using sinon types (#2142)
Browse files Browse the repository at this point in the history
* rework time interfaces to avoid using sinon types

* add changelog entry
  • Loading branch information
davidjgoss committed Sep 20, 2022
1 parent 1a3828d commit e795ae7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO
### Added
- Debug logging capability to help diagnose configuration issues (see [documentation](./docs/debugging.md)) ([#2120](https://github.com/cucumber/cucumber-js/pull/2120))

### Fixed
- Rework time interfaces to avoid using sinon types ([#2142](https://github.com/cucumber/cucumber-js/pull/2142))

## [8.5.3] - 2022-09-10
### Fixed
- Default `stderr` if not provided to `Cli` constructor ([#2138](https://github.com/cucumber/cucumber-js/pull/2138))
Expand Down
19 changes: 14 additions & 5 deletions src/time.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { performance } from 'perf_hooks'
import * as messages from '@cucumber/messages'
import { FakeClock, GlobalTimers, TimerId } from '@sinonjs/fake-timers'

let previousTimestamp: number

interface IMethods extends GlobalTimers<TimerId> {
interface ProtectedTimingBuiltins {
clearImmediate: typeof clearImmediate
clearInterval: typeof clearInterval
clearTimeout: typeof clearTimeout
Date: typeof Date
setImmediate: typeof setImmediate
setInterval: typeof setInterval
setTimeout: typeof setTimeout
performance: typeof performance
}

interface CustomTimingFunctions {
beginTiming: () => void
endTiming: () => number
performance: FakeClock<TimerId>['performance']
}

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

0 comments on commit e795ae7

Please sign in to comment.