Skip to content

Commit

Permalink
test_runner: fix mock timer setInterval tests
Browse files Browse the repository at this point in the history
Some tests relied on the custom return value and were broken by the
change to always return the value provided by the caller.
  • Loading branch information
mika-fischer committed Oct 23, 2023
1 parent 88e13a7 commit 06d8b9d
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,11 @@ describe('Mock Timers Test Suite', () => {

const expectedIterations = 5;
const interval = 1000;
const startedAt = Date.now();
let time = 0;
async function run() {
const times = [];
for await (const time of nodeTimersPromises.setInterval(interval, startedAt)) {
for await (const _ of nodeTimersPromises.setInterval(interval)) { // eslint-disable-line no-unused-vars
time += interval;
times.push(time);
if (times.length === expectedIterations) break;
}
Expand All @@ -535,7 +536,7 @@ describe('Mock Timers Test Suite', () => {
const timeResults = await r;
assert.strictEqual(timeResults.length, expectedIterations);
for (let it = 1; it < expectedIterations; it++) {
assert.strictEqual(timeResults[it - 1], startedAt + (interval * it));
assert.strictEqual(timeResults[it - 1], interval * it);
}
});

Expand Down Expand Up @@ -602,13 +603,12 @@ describe('Mock Timers Test Suite', () => {
const signal = controller.signal;
const interval = 200;
const expectedIterations = 2;
const startedAt = Date.now();
const timeResults = [];
let numIterations = 0;
async function run() {
const it = nodeTimersPromises.setInterval(interval, startedAt, { signal });
for await (const time of it) {
timeResults.push(time);
if (timeResults.length === 5) break;
const it = nodeTimersPromises.setInterval(interval, undefined, { signal });
for await (const _ of it) { // eslint-disable-line no-unused-vars
numIterations += 1;
if (numIterations === 5) break;
}
}

Expand All @@ -624,11 +624,7 @@ describe('Mock Timers Test Suite', () => {
await assert.rejects(() => r, {
name: 'AbortError',
});
assert.strictEqual(timeResults.length, expectedIterations);

for (let it = 1; it < expectedIterations; it++) {
assert.strictEqual(timeResults[it - 1], startedAt + (interval * it));
}
assert.strictEqual(numIterations, expectedIterations);
});
});
});
Expand Down

0 comments on commit 06d8b9d

Please sign in to comment.