-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5261f66
commit b77de7e
Showing
7 changed files
with
51 additions
and
57 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
module.exports = typeof setImmediate === 'function' ? setImmediate : (...args) => { | ||
args.splice(1, 0, 0); | ||
setTimeout(...args); | ||
const setImmediate = typeof globalThis.setImmediate === 'function' ? globalThis.setImmediate : (...arguments_) => { | ||
arguments_.splice(1, 0, 0); | ||
setTimeout(...arguments_); | ||
}; | ||
|
||
export default setImmediate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
/* eslint-disable no-global-assign */ | ||
import {randomInt} from 'node:crypto'; | ||
import test from 'ava'; | ||
import importFresh from 'import-fresh'; | ||
|
||
test.cb('shim', t => { | ||
let called = false; | ||
const importFresh = async moduleName => import(`${moduleName}?${randomInt(100_000_000)}`); | ||
|
||
test.serial('shim', async t => { | ||
// Force the shim | ||
const _ = setImmediate; | ||
setImmediate = null; | ||
const setImmediateShim = importFresh('.'); | ||
setImmediate = _; | ||
const _ = globalThis.setImmediate; | ||
globalThis.setImmediate = undefined; | ||
const {default: setImmediateShim} = await importFresh('./index.js'); | ||
globalThis.setImmediate = _; | ||
|
||
setImmediateShim(() => { | ||
called = true; | ||
t.end(); | ||
await new Promise(resolve => { | ||
setImmediateShim(() => { | ||
resolve(); | ||
}); | ||
}); | ||
|
||
t.false(called); | ||
t.pass(); | ||
}); | ||
|
||
test.cb('pass rest arguments', t => { | ||
test.serial('pass rest arguments', async t => { | ||
// Force the shim | ||
const _ = setImmediate; | ||
setImmediate = null; | ||
const setImmediateShim = importFresh('.'); | ||
setImmediate = _; | ||
const _ = globalThis.setImmediate; | ||
globalThis.setImmediate = undefined; | ||
const {default: setImmediateShim} = await importFresh('./index.js'); | ||
globalThis.setImmediate = _; | ||
|
||
setImmediateShim((a, b) => { | ||
t.is(a, 3); | ||
t.is(b, 5); | ||
t.end(); | ||
}, 3, 5); | ||
await new Promise(resolve => { | ||
setImmediateShim((a, b) => { | ||
t.is(a, 3); | ||
t.is(b, 5); | ||
resolve(); | ||
}, 3, 5); | ||
}); | ||
|
||
t.pass(); | ||
}); |