Skip to content

console.timeEnd reporting seconds as millisecondsΒ #6448

@HiDeoo

Description

@HiDeoo

πŸ› Bug Report

When using console.time & console.timeEnd in a test, the logged elapsed time is indicated as being in milliseconds while actually being in seconds.

To Reproduce

Use console.time & console.timeEnd in a test:

it('should add two numbers', () => {
  console.time('test')

  expect(add(1, 2)).toBe(3);

  console.timeEnd('test')
});

Expected behavior

If the elapsed time is 7ms, I expect console.timeEnd to actually logs either:

  • test: 7ms
  • test: 0.007s

I'm assuming the current behavior is coming from these lines which convert the elapsed time in seconds and then log them in ms.

https://github.com/facebook/jest/blob/9c1c3b1f072175e434943d1eb99d84b4d72ed458/packages/jest-util/src/Console.js#L130-L131

Link to repl or repo (highly encouraged)

Repl.it demo.

Run npx envinfo --preset jest

  System:
    OS: macOS High Sierra 10.13.5
    CPU: x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
  Binaries:
    Node: 10.3.0 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.1.0 - /usr/local/bin/npm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions