Repository navigation
Timers mock panic with sub-test #55849
Description
Activity
- addedtest_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Nov 14, 2024 Even simpler reproduction:
import { test, beforeEach } from 'node:test' beforeEach((t) => t.mock.timers.enable()); test(() => test());
$ node repro.jsIt's failing here:
node/lib/internal/test_runner/mock/mock_timers.js
Lines 396 to 413 in be5a500
ObjectDefineProperties(MockDate, { __proto__: null, [kMock]: { __proto__: null, enumerable: false, configurable: false, writable: false, value: this, }, isMock: { __proto__: null, enumerable: true, configurable: false, writable: false, value: true, }, }); Reacted by AxetroyWith above example,
#createDateis called 2 times. So when I changeconfigurableof[kMock]to true, above example is working. But I'm not sure that this approach is right.configurable: false, I don't think we should set it to
true.IMO The appropriate response should be an error that the mock is already enabled, as is done if you try to enable it twice.
A better way to look at this is:
import { test } from 'node:test' test((outer) => { outer.mock.timers.enable() test((inner) => inner.mock.timers.enable()) });
When
outerchanges theDateobject, it sets these properties.Then, when
innerwants to change theDateobject, it copies those properties, before trying to set them:
node/lib/internal/test_runner/mock/mock_timers.js
Lines 380 to 383 in be5a500
ObjectDefineProperties( MockDate, dateProps, ); IMO there are two paths that can be taken here:
A) Throw an error that the object has already been mocked
B) Exclude those properties, and overwrite the mock.I'm inclined for (A).
Opened #55858
- added a commit that references this issue
on Nov 17, 2024 - added a commit that references this issue
on Nov 18, 2024
Version
v22.10.0
Platform
No response
Subsystem
No response
What steps will reproduce the bug?
1. Create a test file
a.test.mjs2. Run the following command to test
How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior? Why is that the expected behavior?
There should be not panic
What do you see instead?
Additional information
No response