npm / minipass-fetch

An implementation of window.fetch in Node.js using Minipass streams
Other
54 stars 11 forks source link

fix: check for existence of unref before calling #13

Closed ewanharris closed 2 years ago

ewanharris commented 3 years ago

Environments like Electron do not always expose the Node.js setTiemout, so there is no unref function on resTimeout. So update the check to also check if the unref function exists

Ref: https://github.com/electron/electron/issues/21162

isaacs commented 3 years ago

Sounds good to me. Needs a test that fails without the patch and passes with it, though.

ewanharris commented 3 years ago

I've added a test that overrides setTimeout to emulate running in environments that don't have unref. I'm not super familiar with tap so I'm not sure how to ensure that setTimeout gets reset if the test throws. Please let me know if you think there's a better way to have the test mock that behaviour

isaacs commented 2 years ago

Thanks! I tweaked the test a little to put the reset into a t.teardown() method, since that'll get called even if the test fails.