Socket
Socket
Sign inDemoInstall

@jest/fake-timers

Package Overview
Dependencies
Maintainers
6
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jest/fake-timers - npm Package Compare versions

Comparing version 29.0.3 to 29.1.0

5

build/index.d.ts

@@ -18,2 +18,3 @@ /**

private _fakeTimerAPIs;
private _fakingTime;
private _global;

@@ -45,2 +46,3 @@ private _immediates;

reset(): void;
now(): number;
runAllTicks(): void;

@@ -66,3 +68,3 @@ runAllImmediates(): void;

private _fakeSetTimeout;
private _getNextTimerHandle;
private _getNextTimerHandleAndExpiry;
private _runTimerHandle;

@@ -96,2 +98,3 @@ }

getRealSystemTime(): number;
now(): number;
getTimerCount(): number;

@@ -98,0 +101,0 @@ private _checkFakeTimers;

57

build/legacyFakeTimers.js

@@ -53,2 +53,3 @@ 'use strict';

_fakeTimerAPIs;
_fakingTime = false;
_global;

@@ -106,2 +107,10 @@ _immediates;

now() {
if (this._fakingTime) {
return this._now;
}
return Date.now();
}
runAllTicks() {

@@ -178,8 +187,11 @@ this._checkFakeTimers(); // Only run a generous number of ticks and then bail.

for (i = 0; i < this._maxLoops; i++) {
const nextTimerHandle = this._getNextTimerHandle(); // If there are no more timer handles, stop!
const nextTimerHandleAndExpiry = this._getNextTimerHandleAndExpiry(); // If there are no more timer handles, stop!
if (nextTimerHandle === null) {
if (nextTimerHandleAndExpiry === null) {
break;
}
const [nextTimerHandle, expiry] = nextTimerHandleAndExpiry;
this._now = expiry;
this._runTimerHandle(nextTimerHandle); // Some of the immediate calls could be enqueued

@@ -218,3 +230,7 @@ // during the previous handling of the timers, we should

.sort(([, left], [, right]) => left.expiry - right.expiry)
.forEach(([timerHandle]) => this._runTimerHandle(timerHandle));
.forEach(([timerHandle, timer]) => {
this._now = timer.expiry;
this._runTimerHandle(timerHandle);
});
}

@@ -248,20 +264,12 @@

for (i = 0; i < this._maxLoops; i++) {
const timerHandle = this._getNextTimerHandle(); // If there are no more timer handles, stop!
const timerHandleAndExpiry = this._getNextTimerHandleAndExpiry(); // If there are no more timer handles, stop!
if (timerHandle === null) {
if (timerHandleAndExpiry === null) {
break;
}
const timerValue = this._timers.get(timerHandle);
const [timerHandle, nextTimerExpiry] = timerHandleAndExpiry;
if (timerValue === undefined) {
break;
}
const nextTimerExpiry = timerValue.expiry;
if (this._now + msToRun < nextTimerExpiry) {
// There are no timers between now and the target we're running to, so
// adjust our time cursor and quit
this._now += msToRun;
// There are no timers between now and the target we're running to
break;

@@ -274,4 +282,6 @@ } else {

}
}
} // Advance the clock by whatever time we still have left to run
this._now += msToRun;
if (i === this._maxLoops) {

@@ -374,2 +384,3 @@ throw new Error(

global.process.nextTick = this._timerAPIs.nextTick;
this._fakingTime = false;
}

@@ -436,2 +447,3 @@

global.process.nextTick = this._fakeTimerAPIs.nextTick;
this._fakingTime = true;
}

@@ -446,4 +458,3 @@

_checkFakeTimers() {
// @ts-expect-error: condition always returns 'true'
if (this._global.setTimeout !== this._fakeTimerAPIs?.setTimeout) {
if (!this._fakingTime) {
this._global.console.warn(

@@ -595,3 +606,3 @@ 'A function to advance timers was called but the timers APIs are not mocked ' +

_getNextTimerHandle() {
_getNextTimerHandleAndExpiry() {
let nextTimerHandle = null;

@@ -607,3 +618,7 @@ let soonestTime = MS_IN_A_YEAR;

return nextTimerHandle;
if (nextTimerHandle === null) {
return null;
}
return [nextTimerHandle, soonestTime];
}

@@ -615,2 +630,4 @@

if (!timer) {
// Timer has been cleared - we'll hit this when a timer is cleared within
// another timer in runOnlyPendingTimers
return;

@@ -617,0 +634,0 @@ }

@@ -136,2 +136,10 @@ 'use strict';

now() {
if (this._fakingTime) {
return this._clock.now;
}
return Date.now();
}
getTimerCount() {

@@ -138,0 +146,0 @@ if (this._checkFakeTimers()) {

{
"name": "@jest/fake-timers",
"version": "29.0.3",
"version": "29.1.0",
"repository": {

@@ -20,11 +20,11 @@ "type": "git",

"dependencies": {
"@jest/types": "^29.0.3",
"@jest/types": "^29.1.0",
"@sinonjs/fake-timers": "^9.1.2",
"@types/node": "*",
"jest-message-util": "^29.0.3",
"jest-mock": "^29.0.3",
"jest-util": "^29.0.3"
"jest-message-util": "^29.1.0",
"jest-mock": "^29.1.0",
"jest-util": "^29.1.0"
},
"devDependencies": {
"@jest/test-utils": "^29.0.3",
"@jest/test-utils": "^29.1.0",
"@types/sinonjs__fake-timers": "^8.1.2"

@@ -38,3 +38,3 @@ },

},
"gitHead": "77f865da39af5b3e1c114dc347e49257eb3dcfd1"
"gitHead": "51f10300daf90db003a1749ceaed1084c4f74811"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc