Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Timers mock panic with sub-test #55849

Copy link
Copy link

Description

@axetroy
Issue body actions

Version

v22.10.0

Platform

No response

Subsystem

No response

What steps will reproduce the bug?

1. Create a test file a.test.mjs

import test from 'node:test'

test.beforeEach((t) => {
    t.mock.timers.enable({ apis: ['Date'] })
    t.mock.timers.tick(1731488301220) // 2024-11-13 16:58:21.220
})

test('test 1', async (t) => {
    await t.test('sub test 1', async (t) => {
        //
    })
})

2. Run the following command to test

node --test --experimental-default-type=module ./a.test.mjs

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?

▶ test 1
  ✖ sub test 1 (1.0925ms)
    TypeError [Error]: Cannot redefine property: Symbol(MockTimers)
        at defineProperties (<anonymous>)
        at #createDate (node:internal/test_runner/mock/mock_timers:381:5)
        at Object.Date (node:internal/test_runner/mock/mock_timers:614:45)
        at node:internal/test_runner/mock/mock_timers:635:74
        at Array.forEach (<anonymous>)
        at #toggleEnableTimers (node:internal/test_runner/mock/mock_timers:635:5)
        at MockTimers.enable (node:internal/test_runner/mock/mock_timers:720:29)
        at TestContext.<anonymous> (file:///path/to/a.test.mjs:4:19)
        at TestHook.runInAsyncScope (node:async_hooks:211:14)
        at TestHook.run (node:internal/test_runner/test:934:25)

Additional information

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.Issues with confirmed bugs.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.