Skip to content

Using standard NodeJS libraries for timing logic in tests. #92

@jdmarshall

Description

@jdmarshall

NodeJS 24 shipped last week and one of the changes was a standard API for mocking out timers and manually advancing them. This allows among other things to test very narrow race conditions by single stepping the timers and checking state in between them, without having to resort to very long timers that slow the tests down.

Also timers/promises was added in Node 16, and could be used to replace the delay module in the tests.

const res = await setTimeout(100, 'result');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions