From 72220bf1d4bf1b88e667a3a0a126e54e581165e2 Mon Sep 17 00:00:00 2001 From: Erick Wendel Date: Sun, 3 Sep 2023 18:07:15 -0300 Subject: [PATCH 1/2] test_runner: fix invalid timer call Signed-off-by: Erick Wendel --- lib/internal/test_runner/mock/mock_timers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index 7e38f9f7b5113c..384cd3c32db55a 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, From 279aa992f37d31cb40792aa05d676d1d1f755668 Mon Sep 17 00:00:00 2001 From: Erick Wendel Date: Sun, 3 Sep 2023 18:58:24 -0300 Subject: [PATCH 2/2] test_runner: manually check descriptors Signed-off-by: Erick Wendel --- test/parallel/test-runner-mock-timers.js | 39 +++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) 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) => {