@sinonjs/fake-timers
Advanced tools
Comparing version 7.0.1 to 7.0.2
7.0.2 / 2021-01-18 | ||
================== | ||
* Make config options optional in TypeScript defs (#354) | ||
7.0.1 / 2021-01-14 | ||
@@ -3,0 +8,0 @@ ================== |
{ | ||
"name": "@sinonjs/fake-timers", | ||
"description": "Fake JavaScript timers", | ||
"version": "7.0.1", | ||
"version": "7.0.2", | ||
"homepage": "http://github.com/sinonjs/fake-timers", | ||
@@ -24,3 +24,3 @@ "author": "Christian Johansen", | ||
"test-coverage": "nyc --all --reporter text --reporter html --reporter lcovonly npm run test-node", | ||
"test": "npm run lint && npm run test-node && npm run test-headless", | ||
"test": "npm run test-node && npm run test-headless", | ||
"prepublishOnly": "npm run build", | ||
@@ -82,3 +82,3 @@ "preversion": "./scripts/preversion.sh", | ||
"hooks": { | ||
"pre-commit": "npm run lint && npm run test-node" | ||
"pre-commit": "npm run lint" | ||
} | ||
@@ -85,0 +85,0 @@ }, |
@@ -17,2 +17,5 @@ # `@sinonjs/fake-timers` | ||
## Help us get our TypeScript definitions production ready! | ||
In version 7 we introduced TypeScript definitions that are generated from our JSDoc. This makes importing types from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/sinonjs__fake-timers/index.d.ts) superfluous, but we have just gotten started and we need your work for this to be up to the same quality. If you need good TypeScript definitions _now_ and find the ones included by `fake-timers` less than satisfactory, we suggest you install version 6 in the meantime. | ||
## Installation | ||
@@ -85,3 +88,3 @@ | ||
} | ||
var clock = FakeTimers.install({target: context}); | ||
var clock = FakeTimers.withGlobal(context).install(); | ||
@@ -142,3 +145,2 @@ context.setTimeout(fn, 15); // Schedules with clock.setTimeout | ||
--------- | ---- | ------- | ------------ | ||
`config.target`| Object | global | installs FakeTimers onto the specified target context | ||
`config.now` | Number/Date | 0 | installs FakeTimers with the specified unix epoch | ||
@@ -296,4 +298,4 @@ `config.toFake` | String[] | ["setTimeout", "clearTimeout", "setImmediate", "clearImmediate","setInterval", "clearInterval", "Date", "requestAnimationFrame", "cancelAnimationFrame", "requestIdleCallback", "cancelIdleCallback", "hrtime"] | an array with explicit function names to hijack. *When not set, FakeTimers will automatically fake all methods **except** `nextTick`* e.g., `FakeTimers.install({ toFake: ["setTimeout","nextTick"]})` will fake only `setTimeout` and `nextTick` | ||
Restores the original methods on the `target` that was passed to | ||
`FakeTimers.install`, or the native timers if no `target` was given. | ||
Restores the original methods of the native timers or the methods on the object | ||
that was passed to `FakeTimers.withGlobal` | ||
@@ -300,0 +302,0 @@ ### `Date` |
@@ -1215,9 +1215,15 @@ "use strict"; | ||
/** | ||
* @param config {Object} optional config | ||
* @param config.now {number|Date} a number (in milliseconds) or a Date object (default epoch) | ||
* @param config.toFake {string[]} names of the methods that should be faked. | ||
* @param config.loopLimit {number} the maximum number of timers that will be run when calling runAll() | ||
* @param config.shouldAdvanceTime {Boolean} tells FakeTimers to increment mocked time automatically (default false) | ||
* @param config.advanceTimeDelta {Number} increment mocked time every <<advanceTimeDelta>> ms (default: 20ms) | ||
* Configuration object for the `install` method. | ||
* | ||
* @typedef {object} Config | ||
* @property [now] {number|Date} a number (in milliseconds) or a Date object (default epoch) | ||
* @property [toFake] {string[]} names of the methods that should be faked. | ||
* @property [loopLimit] {number} the maximum number of timers that will be run when calling runAll() | ||
* @property [shouldAdvanceTime] {Boolean} tells FakeTimers to increment mocked time automatically (default false) | ||
* @property [advanceTimeDelta] {Number} increment mocked time every <<advanceTimeDelta>> ms (default: 20ms) | ||
*/ | ||
/** | ||
* @param [config] {Config} optional config | ||
*/ | ||
// eslint-disable-next-line complexity | ||
@@ -1224,0 +1230,0 @@ function install(config) { |
@@ -19,15 +19,35 @@ export namespace timers { | ||
/** | ||
* @param config {Object} optional config | ||
* @param config.now {number|Date} a number (in milliseconds) or a Date object (default epoch) | ||
* @param config.toFake {string[]} names of the methods that should be faked. | ||
* @param config.loopLimit {number} the maximum number of timers that will be run when calling runAll() | ||
* @param config.shouldAdvanceTime {Boolean} tells FakeTimers to increment mocked time automatically (default false) | ||
* @param config.advanceTimeDelta {Number} increment mocked time every <<advanceTimeDelta>> ms (default: 20ms) | ||
* Configuration object for the `install` method. | ||
* | ||
* @typedef {object} Config | ||
* @property [now] {number|Date} a number (in milliseconds) or a Date object (default epoch) | ||
* @property [toFake] {string[]} names of the methods that should be faked. | ||
* @property [loopLimit] {number} the maximum number of timers that will be run when calling runAll() | ||
* @property [shouldAdvanceTime] {Boolean} tells FakeTimers to increment mocked time automatically (default false) | ||
* @property [advanceTimeDelta] {Number} increment mocked time every <<advanceTimeDelta>> ms (default: 20ms) | ||
*/ | ||
export function install(config: { | ||
now: number | Date; | ||
toFake: string[]; | ||
loopLimit: number; | ||
shouldAdvanceTime: boolean; | ||
advanceTimeDelta: number; | ||
/** | ||
* @param [config] {Config} optional config | ||
*/ | ||
export function install(config?: { | ||
/** | ||
* a number (in milliseconds) or a Date object (default epoch) | ||
*/ | ||
now?: number | Date; | ||
/** | ||
* names of the methods that should be faked. | ||
*/ | ||
toFake?: string[]; | ||
/** | ||
* the maximum number of timers that will be run when calling runAll() | ||
*/ | ||
loopLimit?: number; | ||
/** | ||
* tells FakeTimers to increment mocked time automatically (default false) | ||
*/ | ||
shouldAdvanceTime?: boolean; | ||
/** | ||
* increment mocked time every <<advanceTimeDelta>> ms (default: 20ms) | ||
*/ | ||
advanceTimeDelta?: number; | ||
}, ...args: any[]): { | ||
@@ -53,8 +73,23 @@ now: number; | ||
}; | ||
install: (config: { | ||
now: number | Date; | ||
toFake: string[]; | ||
loopLimit: number; | ||
shouldAdvanceTime: boolean; | ||
advanceTimeDelta: number; | ||
install: (config?: { | ||
/** | ||
* a number (in milliseconds) or a Date object (default epoch) | ||
*/ | ||
now?: number | Date; | ||
/** | ||
* names of the methods that should be faked. | ||
*/ | ||
toFake?: string[]; | ||
/** | ||
* the maximum number of timers that will be run when calling runAll() | ||
*/ | ||
loopLimit?: number; | ||
/** | ||
* tells FakeTimers to increment mocked time automatically (default false) | ||
*/ | ||
shouldAdvanceTime?: boolean; | ||
/** | ||
* increment mocked time every <<advanceTimeDelta>> ms (default: 20ms) | ||
*/ | ||
advanceTimeDelta?: number; | ||
}, ...args: any[]) => { | ||
@@ -61,0 +96,0 @@ now: number; |
75158
1245
340