From b4d42a8f2bffe442aef32bd582d790d5b6fcd913 Mon Sep 17 00:00:00 2001 From: Erick Wendel Date: Tue, 5 Sep 2023 18:17:28 -0300 Subject: [PATCH] test_runner: fix invalid timer call Signed-off-by: Erick Wendel PR-URL: https://github.com/nodejs/node/pull/49477 Reviewed-By: Chemi Atlow Reviewed-By: Benjamin Gruenbaum Reviewed-By: Moshe Atlow --- lib/internal/test_runner/mock/mock_timers.js | 2 +- test/parallel/test-runner-mock-timers.js | 39 ++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index 1624b03f8af674..1ff6489885fe30 100644 --- a/lib/internal/test_runner/mock/mock_timers.js +++ b/lib/internal/test_runner/mock/mock_timers.js @@ -372,7 +372,7 @@ class MockTimers { ObjectDefineProperty( nodeTimers, 'setTimeout', - this.#realSetTimeout, + this.#realTimersSetTimeout, ); ObjectDefineProperty( nodeTimers, diff --git a/test/parallel/test-runner-mock-timers.js b/test/parallel/test-runner-mock-timers.js index c740aa3b4958d4..3a2203091337c6 100644 --- a/test/parallel/test-runner-mock-timers.js +++ b/test/parallel/test-runner-mock-timers.js @@ -46,8 +46,7 @@ describe('Mock Timers Test Suite', () => { code: 'ERR_INVALID_ARG_VALUE', }); }); - - it('should check that propertyDescriptor gets back after reseting timers', (t) => { + it('should check that propertyDescriptor gets back after resetting timers', (t) => { const getDescriptor = (ctx, fn) => Object.getOwnPropertyDescriptor(ctx, fn); const getCurrentTimersDescriptors = () => { const timers = [ @@ -71,26 +70,36 @@ describe('Mock Timers Test Suite', () => { nodeTimersPromises: nodeTimersPromisesDescriptors, }; }; - const before = getCurrentTimersDescriptors(); + + const originalDescriptors = getCurrentTimersDescriptors(); + t.mock.timers.enable(); const during = getCurrentTimersDescriptors(); t.mock.timers.reset(); const after = getCurrentTimersDescriptors(); - assert.deepStrictEqual( - before, - after, - ); + for (const env in originalDescriptors) { + for (const prop in originalDescriptors[env]) { + const originalDescriptor = originalDescriptors[env][prop]; + const afterDescriptor = after[env][prop]; - assert.notDeepStrictEqual( - before, - during, - ); + assert.deepStrictEqual( + originalDescriptor, + afterDescriptor, + ); - assert.notDeepStrictEqual( - during, - after, - ); + assert.notDeepStrictEqual( + originalDescriptor, + during[env][prop], + ); + + assert.notDeepStrictEqual( + during[env][prop], + after[env][prop], + ); + + } + } }); it('should reset all timers when calling .reset function', (t) => {