Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .yarn/patches/nock-npm-13.5.5-ccb57f0a2f.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/lib/common.js b/lib/common.js
index a6f7f766d03fb7acc9fe2494488685684fa7fe07..1d29b572e18ee94c4a76e593e69cf628f9e18d69 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -612,7 +612,45 @@ const wrapTimer =
return id
}

-const setTimeout = wrapTimer(timers.setTimeout, timeouts)
+/**
+ * PATCH NOTES (https://github.com/MetaMask/core/issues/4428):
+ *
+ * Schedule positive response delays (e.g. from `.delay()`) on the global
+ * `setTimeout`, resolved at call time, instead of the `timers` module
+ * function captured at module load time. Jest/Sinon fake timers replace the
+ * global timer functions but cannot affect the load-time-captured `timers`
+ * module reference, so delayed responses were not controllable by fake
+ * timers and ran in real time.
+ *
+ * Zero-delay scheduling (used for every mocked response) is deliberately
+ * left on the real `timers` module function so that tests which enable fake
+ * timers but do not advance them still receive undelayed mock responses, as
+ * they do today.
+ *
+ * This is a more conservative version of the patch applied in the extension
+ * repository: https://github.com/MetaMask/metamask-extension/pull/24805
+ *
+ * TODO: Remove this patch after updating to `nock@14`, which no longer uses
+ * the `timers` module for response delays.
+ */
+const wrapDelayTimer =
+ (timer, ids) =>
+ (callback, ...timerArgs) => {
+ const cb = (...callbackArgs) => {
+ try {
+ // eslint-disable-next-line n/no-callback-literal
+ callback(...callbackArgs)
+ } finally {
+ ids.delete(id)
+ }
+ }
+ const timerFn = timerArgs[0] > 0 ? globalThis.setTimeout : timer
+ const id = timerFn(cb, ...timerArgs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delay patch breaks fake-timer tests

High Severity

Routing positive nock delays through globalThis.setTimeout makes .delay() fake-timer-controlled, but several existing suites still await those delayed mocks without advancing timers afterward. Those tests previously relied on real wall-clock delays and will hang or fail under this patch, contrary to the claim that no expectations change.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cea9f24. Configure here.

+ ids.add(id)
+ return id
+ }
+
+const setTimeout = wrapDelayTimer(timers.setTimeout, timeouts)
const setImmediate = wrapTimer(timers.setImmediate, immediates)

function clearTimer(clear, ids) {
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@nktkas/hyperliquid@npm:^0.33.1": "patch:@nktkas/hyperliquid@npm%3A0.33.1#~/.yarn/patches/@nktkas-hyperliquid-npm-0.33.1-6a541fdd1d.patch",
"elliptic@6.5.4": "^6.5.7",
"fast-xml-parser@^4.3.4": "^4.4.1",
"nock@npm:^13.3.1": "patch:nock@npm%3A13.5.5#~/.yarn/patches/nock-npm-13.5.5-ccb57f0a2f.patch",
"ws@7.4.6": "^7.5.10"
},
"simple-git-hooks": {
Expand Down
13 changes: 12 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22106,7 +22106,7 @@ __metadata:
languageName: node
linkType: hard

"nock@npm:^13.3.1":
"nock@npm:13.5.5":
version: 13.5.5
resolution: "nock@npm:13.5.5"
dependencies:
Expand All @@ -22117,6 +22117,17 @@ __metadata:
languageName: node
linkType: hard

"nock@patch:nock@npm%3A13.5.5#~/.yarn/patches/nock-npm-13.5.5-ccb57f0a2f.patch":
version: 13.5.5
resolution: "nock@patch:nock@npm%3A13.5.5#~/.yarn/patches/nock-npm-13.5.5-ccb57f0a2f.patch::version=13.5.5&hash=5834ac"
dependencies:
debug: "npm:^4.1.0"
json-stringify-safe: "npm:^5.0.1"
propagate: "npm:^2.0.0"
checksum: 10/4e8a6eeac8f3997ade78d65234d2489e33aeab144977fc129cf567b5a9010ea959cc32989d923d366f8836adead4e320495d0624a57a93013f993d277a3a4ee1
languageName: node
linkType: hard

"node-abi@npm:^3.3.0":
version: 3.92.0
resolution: "node-abi@npm:3.92.0"
Expand Down