Skip to content

createDebugger leaks console timer when inspect: true #142

Description

@vinamra1102

Environment

  • hookable: v6.1.1
  • Node.js: v22
  • Browser: Chrome / any Chromium browser

Reproduction

import { Hookable, createDebugger } from 'hookable'

const hooks = new Hookable()
createDebugger(hooks, { inspect: true })

await hooks.callHook('myHook') // timer started, never ended
await hooks.callHook('myHook') // browser warns: "Timer 'myHook' already exists"

Describe the bug

When inspect: true (the default in browsers), createDebugger calls
console.timeLog() in the afterEach handler but never calls
console.timeEnd(). The timer started by console.time() in beforeEach
leaks on every hook call.

On the second call to the same hook the browser warns:

Timer 'hookName' already exists

Root cause: in src/debugger.ts lines 69-72, console.timeEnd() is
inside the else branch of the inspect check, so it is never reached
when inspect: true.

Since inspect defaults to true in browsers, every browser user of
createDebugger is affected.

I have a fix ready and would like to submit a PR if confirmed.

Additional context

No response

Logs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions