-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex3.test.js
More file actions
24 lines (19 loc) · 838 Bytes
/
ex3.test.js
File metadata and controls
24 lines (19 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
'use strict';
const { starveMicrotasks } = require('./ex3');
function assert(condition, message) {
if (!condition) throw new Error(message || 'Assertion failed');
}
(async () => {
// Case 1: no yielding => timersObserved should be 0 during microtask loop
const r1 = await starveMicrotasks(5000, 0);
assert(r1.microtasksRun === 5000, 'must run requested microtasks');
assert(r1.timersObserved === 0, 'without yielding, setImmediate should be starved during loop');
// Case 2: yielding => we should observe setImmediate running
const r2 = await starveMicrotasks(5000, 250);
assert(r2.microtasksRun === 5000, 'must run requested microtasks');
assert(r2.timersObserved > 0, 'with yielding, setImmediate should run');
console.log('ex3 tests passed');
})().catch((err) => {
console.error(err);
process.exit(1);
});