Socket
Socket
Sign inDemoInstall

@sinonjs/fake-timers

Package Overview
Dependencies
2
Maintainers
6
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.5 to 7.1.0

21

CHANGELOG.md
7.1.0 / 2021-05-20
==================
* Remove Safari from Sauce Lab (ref #380)
* Bump hosted-git-info from 2.6.0 to 2.8.9
* Bump handlebars from 4.7.6 to 4.7.7
* Bump lodash from 4.17.19 to 4.17.21
* Add in latest Safari and evergreen Edge
* Drop IE11 and Safari 9
* chore: add type tests (#373)
* remove constructor types
* use globalThis to avoid conflicts
* Update yargs-parser
* Update mkdirp
* Upgrade jsdom
* Upgrade mochify to latest
* Upgrade Mocha to latest
* Bump y18n from 4.0.0 to 4.0.1
* make config optional
* add a bunch more types
7.0.5 / 2021-04-11

@@ -3,0 +24,0 @@ ==================

13

package.json
{
"name": "@sinonjs/fake-timers",
"description": "Fake JavaScript timers",
"version": "7.0.5",
"version": "7.1.0",
"homepage": "https://github.com/sinonjs/fake-timers",

@@ -24,2 +24,3 @@ "author": "Christian Johansen",

"test-coverage": "nyc --all --reporter text --reporter html --reporter lcovonly npm run test-node",
"test-types": "tsd",
"test": "npm run test-node && npm run test-headless",

@@ -50,8 +51,9 @@ "prettier:check": "prettier --check '**/*.{js,css,md}'",

"husky": "4.2.1",
"jsdom": "15.1.1",
"jsdom": "16.5.2",
"lint-staged": "10.0.7",
"mocha": "7.0.1",
"mochify": "6.6.0",
"mocha": "8.3.2",
"mochify": "7.0.0",
"nyc": "14.1.1",
"prettier": "2.2.1",
"tsd": "0.14.0",
"typescript": "4.1.3"

@@ -80,3 +82,6 @@ },

]
},
"tsd": {
"directory": "test"
}
}

@@ -9,17 +9,17 @@ "use strict";

* @property {any} timeouts
* @property {any} Date
* @property {typeof globalThis.Date} Date
* @property {number} loopLimit
* @property {(func: Function, timeout: number) => any} requestIdleCallback
* @property {(timerId: number) => any} cancelIdleCallback
* @property {(func: Function, timerId: number) => any} setTimeout
* @property {(timerId: number) => any} clearTimeout
* @property {(func: Function) => any} nextTick
* @property {(func: Function) => any} queueMicrotask
* @property {(func: Function, timeout: number) => any} setInterval
* @property {(timerId: number) => any} clearInterval
* @property {(func: Function) => any} setImmediate
* @property {(timerId: number) => any} clearImmediate
* @property {(func: Function, timeout: number) => number} requestIdleCallback
* @property {(timerId: number) => void} cancelIdleCallback
* @property {setTimeout} setTimeout
* @property {clearTimeout} clearTimeout
* @property {(func: Function, ...args: any[]) => void} nextTick
* @property {queueMicrotask} queueMicrotask
* @property {setInterval} setInterval
* @property {clearInterval} clearInterval
* @property {(func: (...args: any[]) => void, ...args: any[]) => NodeTimer} setImmediate
* @property {(timerId: NodeTimer) => void} clearImmediate
* @property {() => number} countTimers
* @property {(func: Function) => any} requestAnimationFrame
* @property {(timerId: number) => any} cancelAnimationFrame
* @property {(func: (timer: number) => void) => number} requestAnimationFrame
* @property {(timerId: number) => void} cancelAnimationFrame
* @property {() => void} runMicrotasks

@@ -37,3 +37,3 @@ * @property {(tickValue: string | number) => number} tick

* @property {(systemTime: number | Date) => void} setSystemTime
* @property {any} performance
* @property {({now(): number})} performance
* @property {(prev: any) => number[]} hrTime

@@ -44,3 +44,27 @@ * @property {() => void} uninstall Uninstall the clock.

// eslint-disable-next-line complexity
/**
* Configuration object for the `install` method.
*
* @typedef {object} Config
* @property {number|Date} now a number (in milliseconds) or a Date object (default epoch)
* @property {string[]} toFake names of the methods that should be faked.
* @property {number} loopLimit the maximum number of timers that will be run when calling runAll()
* @property {boolean} shouldAdvanceTime tells FakeTimers to increment mocked time automatically (default false)
* @property {number} advanceTimeDelta increment mocked time every <<advanceTimeDelta>> ms (default: 20ms)
*/
/**
* @typedef {object} NodeTimer
* @property {() => boolean} hasRef
* @property {() => any} ref
* @property {() => any} unref
*/
/* eslint-disable complexity */
/**
* Mocks available features in the specified global namespace.
*
* @param {*} _global Namespace to mock (e.g. `window`)
*/
function withGlobal(_global) {

@@ -156,4 +180,4 @@ var userAgent = _global.navigator && _global.navigator.userAgent;

*
* @param {Number} msFloat the number of milliseconds
* @returns {Number} an integer number of nanoseconds in the range [0,1e6)
* @param {number} msFloat the number of milliseconds
* @returns {number} an integer number of nanoseconds in the range [0,1e6)
*

@@ -172,3 +196,3 @@ * Example: nanoRemainer(123.456789) -> 456789

* Used to grok the `now` parameter to createClock.
* @param epoch {Date|number} the system time
* @param {Date|number} epoch the system time
*/

@@ -647,2 +671,22 @@ function getEpoch(epoch) {

/**
* @typedef {object} Timers
* @property {setTimeout} setTimeout
* @property {clearTimeout} clearTimeout
* @property {setInterval} setInterval
* @property {clearInterval} clearInterval
* @property {typeof globalThis.Date} Date
* @property {((fn: (...args: any[]) => void, ...args: any[]) => NodeTimer)=} setImmediate
* @property {((id: NodeTimer) => void)=} clearImmediate
* @property {((time?: [number, number]) => [number, number])=} hrtime
* @property {((fn: Function, ...args: any[]) => void)=} nextTick
* @property {({now(): number})=} performance
* @property {((fn: (timer: number) => void) => number)=} requestAnimationFrame
* @property {boolean=} queueMicrotask
* @property {((id: number) => void)=} cancelAnimationFrame
* @property {((fn: (deadline: any) => void, options?: any) => number)=} requestIdleCallback
* @property {((id: number) => void)=} cancelIdleCallback
*/
/** @type {Timers} */
var timers = {

@@ -696,4 +740,4 @@ setTimeout: _global.setTimeout,

/**
* @param start {Date|number} the system time - non-integer values are floored
* @param loopLimit {number} maximum number of timers that will be run when calling runAll()
* @param {Date|number} start the system time - non-integer values are floored
* @param {number} loopLimit maximum number of timers that will be run when calling runAll()
* @returns {Clock}

@@ -1037,3 +1081,3 @@ */

/**
* @param {tickValue} {String|Number} number of milliseconds or a human-readable value like "01:11:15"
* @param {tickValue} {string|number} number of milliseconds or a human-readable value like "01:11:15"
*/

@@ -1273,18 +1317,8 @@ clock.tick = function tick(tickValue) {

/**
* 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)
*/
/* eslint-disable complexity */
/**
* @param [config] {Config} optional config
* @param {Config=} config Optional config
* @returns {Clock}
*/
// eslint-disable-next-line complexity
function install(config) {

@@ -1369,2 +1403,4 @@ if (

/* eslint-enable complexity */
return {

@@ -1378,2 +1414,4 @@ timers: timers,

/* eslint-enable complexity */
var defaultImplementation = withGlobal(globalObject);

@@ -1380,0 +1418,0 @@

export type Clock = {
now: number;
timeouts: any;
Date: any;
Date: typeof globalThis.Date;
loopLimit: number;
requestIdleCallback: (func: Function, timeout: number) => any;
cancelIdleCallback: (timerId: number) => any;
setTimeout: (func: Function, timerId: number) => any;
clearTimeout: (timerId: number) => any;
nextTick: (func: Function) => any;
queueMicrotask: (func: Function) => any;
setInterval: (func: Function, timeout: number) => any;
clearInterval: (timerId: number) => any;
setImmediate: (func: Function) => any;
clearImmediate: (timerId: number) => any;
requestIdleCallback: (func: Function, timeout: number) => number;
cancelIdleCallback: (timerId: number) => void;
setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
nextTick: (func: Function, ...args: any[]) => void;
queueMicrotask: typeof queueMicrotask;
setInterval: typeof setInterval;
clearInterval: typeof clearInterval;
setImmediate: (func: (...args: any[]) => void, ...args: any[]) => NodeTimer;
clearImmediate: (timerId: NodeTimer) => void;
countTimers: () => number;
requestAnimationFrame: (func: Function) => any;
cancelAnimationFrame: (timerId: number) => any;
requestAnimationFrame: (func: (timer: number) => void) => number;
cancelAnimationFrame: (timerId: number) => void;
runMicrotasks: () => void;

@@ -31,3 +31,5 @@ tick: (tickValue: string | number) => number;

setSystemTime: (systemTime: number | Date) => void;
performance: any;
performance: ({
now(): number;
});
hrTime: (prev: any) => number[];

@@ -40,71 +42,87 @@ /**

};
export namespace timers {
export const setTimeout: any;
export const clearTimeout: any;
export const setInterval: any;
export const clearInterval: any;
const Date_1: any;
export { Date_1 as Date };
}
/**
* @param start {Date|number} the system time - non-integer values are floored
* @param loopLimit {number} maximum number of timers that will be run when calling runAll()
* @returns {Clock}
*/
export function createClock(start: Date | number, loopLimit: number): Clock;
/**
* 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
* @returns {Clock}
*/
export function install(config?: {
export type Config = {
/**
* a number (in milliseconds) or a Date object (default epoch)
*/
now?: number | Date;
now: number | Date;
/**
* names of the methods that should be faked.
*/
toFake?: string[];
toFake: string[];
/**
* the maximum number of timers that will be run when calling runAll()
*/
loopLimit?: number;
loopLimit: number;
/**
* tells FakeTimers to increment mocked time automatically (default false)
*/
shouldAdvanceTime?: boolean;
shouldAdvanceTime: boolean;
/**
* increment mocked time every <<advanceTimeDelta>> ms (default: 20ms)
*/
advanceTimeDelta?: number;
}, ...args: any[]): Clock;
advanceTimeDelta: number;
};
export type NodeTimer = {
hasRef: () => boolean;
ref: () => any;
unref: () => any;
};
export namespace timers {
const setTimeout_1: typeof globalThis.setTimeout;
export { setTimeout_1 as setTimeout };
const clearTimeout_1: typeof globalThis.clearTimeout;
export { clearTimeout_1 as clearTimeout };
const setInterval_1: typeof globalThis.setInterval;
export { setInterval_1 as setInterval };
const clearInterval_1: typeof globalThis.clearInterval;
export { clearInterval_1 as clearInterval };
const Date_1: typeof globalThis.Date;
export { Date_1 as Date };
export const setImmediate: (fn: (...args: any[]) => void, ...args: any[]) => NodeTimer;
export const clearImmediate: (id: NodeTimer) => void;
export const hrtime: (time?: [number, number]) => [number, number];
export const nextTick: (fn: Function, ...args: any[]) => void;
export const performance: ({
now(): number;
}) | undefined;
export const requestAnimationFrame: (fn: (timer: number) => void) => number;
const queueMicrotask_1: boolean | undefined;
export { queueMicrotask_1 as queueMicrotask };
export const cancelAnimationFrame: (id: number) => void;
export const requestIdleCallback: (fn: (deadline: any) => void, options?: any) => number;
export const cancelIdleCallback: (id: number) => void;
}
/**
* @param {Date|number} start the system time - non-integer values are floored
* @param {number} loopLimit maximum number of timers that will be run when calling runAll()
* @returns {Clock}
*/
export function createClock(start: Date | number, loopLimit: number): Clock;
/**
* @param {Config=} config Optional config
* @returns {Clock}
*/
export function install(config?: Config | undefined, ...args: any[]): Clock;
/**
* @typedef {object} Clock
* @property {number} now
* @property {any} timeouts
* @property {any} Date
* @property {typeof globalThis.Date} Date
* @property {number} loopLimit
* @property {(func: Function, timeout: number) => any} requestIdleCallback
* @property {(timerId: number) => any} cancelIdleCallback
* @property {(func: Function, timerId: number) => any} setTimeout
* @property {(timerId: number) => any} clearTimeout
* @property {(func: Function) => any} nextTick
* @property {(func: Function) => any} queueMicrotask
* @property {(func: Function, timeout: number) => any} setInterval
* @property {(timerId: number) => any} clearInterval
* @property {(func: Function) => any} setImmediate
* @property {(timerId: number) => any} clearImmediate
* @property {(func: Function, timeout: number) => number} requestIdleCallback
* @property {(timerId: number) => void} cancelIdleCallback
* @property {setTimeout} setTimeout
* @property {clearTimeout} clearTimeout
* @property {(func: Function, ...args: any[]) => void} nextTick
* @property {queueMicrotask} queueMicrotask
* @property {setInterval} setInterval
* @property {clearInterval} clearInterval
* @property {(func: (...args: any[]) => void, ...args: any[]) => NodeTimer} setImmediate
* @property {(timerId: NodeTimer) => void} clearImmediate
* @property {() => number} countTimers
* @property {(func: Function) => any} requestAnimationFrame
* @property {(timerId: number) => any} cancelAnimationFrame
* @property {(func: (timer: number) => void) => number} requestAnimationFrame
* @property {(timerId: number) => void} cancelAnimationFrame
* @property {() => void} runMicrotasks

@@ -122,3 +140,3 @@ * @property {(tickValue: string | number) => number} tick

* @property {(systemTime: number | Date) => void} setSystemTime
* @property {any} performance
* @property {({now(): number})} performance
* @property {(prev: any) => number[]} hrTime

@@ -128,34 +146,46 @@ * @property {() => void} uninstall Uninstall the clock.

*/
/**
* Configuration object for the `install` method.
*
* @typedef {object} Config
* @property {number|Date} now a number (in milliseconds) or a Date object (default epoch)
* @property {string[]} toFake names of the methods that should be faked.
* @property {number} loopLimit the maximum number of timers that will be run when calling runAll()
* @property {boolean} shouldAdvanceTime tells FakeTimers to increment mocked time automatically (default false)
* @property {number} advanceTimeDelta increment mocked time every <<advanceTimeDelta>> ms (default: 20ms)
*/
/**
* @typedef {object} NodeTimer
* @property {() => boolean} hasRef
* @property {() => any} ref
* @property {() => any} unref
*/
/**
* Mocks available features in the specified global namespace.
*
* @param {*} _global Namespace to mock (e.g. `window`)
*/
export function withGlobal(_global: any): {
timers: {
setTimeout: any;
clearTimeout: any;
setInterval: any;
clearInterval: any;
Date: any;
setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
setInterval: typeof setInterval;
clearInterval: typeof clearInterval;
Date: typeof globalThis.Date;
setImmediate?: (fn: (...args: any[]) => void, ...args: any[]) => NodeTimer;
clearImmediate?: (id: NodeTimer) => void;
hrtime?: (time?: [number, number]) => [number, number];
nextTick?: (fn: Function, ...args: any[]) => void;
performance?: ({
now(): number;
}) | undefined;
requestAnimationFrame?: (fn: (timer: number) => void) => number;
queueMicrotask?: boolean | undefined;
cancelAnimationFrame?: (id: number) => void;
requestIdleCallback?: (fn: (deadline: any) => void, options?: any) => number;
cancelIdleCallback?: (id: number) => void;
};
createClock: (start: Date | number, loopLimit: number) => Clock;
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[]) => Clock;
install: (config?: Config | undefined, ...args: any[]) => Clock;
withGlobal: typeof withGlobal;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc