Skip to content

Commit e65beea

Browse files
committed
test_runner: fix mock timer setInterval tests
Some tests relied on the custom return value and were broken by the change to always return the value provided by the caller.
1 parent 96edbb4 commit e65beea

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

test/parallel/test-runner-mock-timers.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,11 @@ describe('Mock Timers Test Suite', () => {
667667

668668
const expectedIterations = 5;
669669
const interval = 1000;
670-
const startedAt = Date.now();
670+
let time = 0;
671671
async function run() {
672672
const times = [];
673-
for await (const time of nodeTimersPromises.setInterval(interval, startedAt)) {
673+
for await (const _ of nodeTimersPromises.setInterval(interval)) { // eslint-disable-line no-unused-vars
674+
time += interval;
674675
times.push(time);
675676
if (times.length === expectedIterations) break;
676677

@@ -688,7 +689,7 @@ describe('Mock Timers Test Suite', () => {
688689
const timeResults = await r;
689690
assert.strictEqual(timeResults.length, expectedIterations);
690691
for (let it = 1; it < expectedIterations; it++) {
691-
assert.strictEqual(timeResults[it - 1], startedAt + (interval * it));
692+
assert.strictEqual(timeResults[it - 1], interval * it);
692693
}
693694
});
694695

@@ -711,7 +712,7 @@ describe('Mock Timers Test Suite', () => {
711712

712713
const interval = 100;
713714
const abortController = new AbortController();
714-
const intervalIterator = nodeTimersPromises.setInterval(interval, Date.now(), {
715+
const intervalIterator = nodeTimersPromises.setInterval(interval, undefined, {
715716
signal: abortController.signal
716717
});
717718

@@ -723,8 +724,6 @@ describe('Mock Timers Test Suite', () => {
723724
t.mock.timers.tick(interval);
724725

725726
const firstResult = await first;
726-
// Interval * 2 because value can be a little bit greater than interval
727-
assert.ok(firstResult.value < Date.now() + interval * 2);
728727
assert.strictEqual(firstResult.done, false);
729728

730729
await assert.rejects(() => second, {
@@ -757,13 +756,12 @@ describe('Mock Timers Test Suite', () => {
757756
const signal = controller.signal;
758757
const interval = 200;
759758
const expectedIterations = 2;
760-
const startedAt = Date.now();
761-
const timeResults = [];
759+
let numIterations = 0;
762760
async function run() {
763-
const it = nodeTimersPromises.setInterval(interval, startedAt, { signal });
764-
for await (const time of it) {
765-
timeResults.push(time);
766-
if (timeResults.length === 5) break;
761+
const it = nodeTimersPromises.setInterval(interval, undefined, { signal });
762+
for await (const _ of it) { // eslint-disable-line no-unused-vars
763+
numIterations += 1;
764+
if (numIterations === 5) break;
767765
}
768766
}
769767

@@ -779,11 +777,7 @@ describe('Mock Timers Test Suite', () => {
779777
await assert.rejects(() => r, {
780778
name: 'AbortError',
781779
});
782-
assert.strictEqual(timeResults.length, expectedIterations);
783-
784-
for (let it = 1; it < expectedIterations; it++) {
785-
assert.strictEqual(timeResults[it - 1], startedAt + (interval * it));
786-
}
780+
assert.strictEqual(numIterations, expectedIterations);
787781

788782
});
789783

0 commit comments

Comments
 (0)