question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reinstate timestamps for mock calls

See original GitHub issue

🚀 Feature Proposal

Record the timestamp of individual mock calls.

Motivation

I am well aware timestamps were removed in favor of invocationCallOrder(https://github.com/facebook/jest/pull/5867). However, to implement a new matcher proposed in https://github.com/jest-community/jest-extended/issues/112, timestamps are necessary. I am proposing to restore the implementation alongside invocationCallOrder and, at the same time, address the concerns raised previously regarding the precision issues (https://github.com/jest-community/jest-extended/issues/98#issuecomment-355440156, https://github.com/facebook/jest/issues/4402#issuecomment-375939427). @brigonzalez was already headed towards a possible solution for this resorting to process.hrtime() instead of Date.

Example

One potential scenario for this feature is, by making use of the aforementioned matcher, to ensure a function is called in compliance with a given exponential back-off strategy.

Pitch

I believe this feature supports a legitimate use case and other may follow.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
UselessPicklescommented, Aug 27, 2018

I think we need this PR merged first, because it includes changes to related code/structures: https://github.com/facebook/jest/pull/6381

Once that is merged, I could easily create a PR to store invocation and completion timestamps, but it might be time to seriously think about restructuring the parallel arrays of information about mock calls. Without any restructuring, it would require adding yet another parallel array to store the invocation timestamps (which may be “good enough” for now to avoid serious breaking changes). I would like feedback from the Jest team on this before I put any work into it.

No matter what approach we take, it will technically be a breaking change to the mock serializer.

The completion timestamp would simply be a new property on the MockFunctionResult structure that would be undefined while the type property is incomplete, then updated to a timestamp value when the function either returns or throws.

2reactions
SimenBcommented, Jul 11, 2018

I believe there’s also some NodeJS-specific process timestamp that can be obtained that is high precision.

process.hrtime is that one 😃 we can use https://www.npmjs.com/package/browser-process-hrtime which should work in all envs we care about

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset Jest mock functions calls count before every test
One way I found to handle it: to clear mock function after each test: To add to Sum.test.js: afterEach(() => { local.getData.
Read more >
Canvas - Android Developers
The recommended alternative calls are clipPath(android.graphics. ... Save the canvas state, draw the picture, and restore the canvas state.
Read more >
pactman - PyPI
Python version of Pact mocking, generation and verification. ... which we'll call Provider , and our product, Consumer is hitting an ...
Read more >
pactman 2.26.0 on PyPI - Libraries.io
Python version of Pact mocking, generation and verification. ... we call our method under test which will then communicate with the Pact mock....
Read more >
REST Invoke API - TechDocs - Broadcom Inc.
call : POST http://[host]:[port]/api/Dcm/VSEs/[serviceName]/actions/createService. Refer to the documentation on the createService call to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found