Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add fake timers implementation backed by Lolex #8897

Merged
merged 3 commits into from
Sep 6, 2019

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Aug 31, 2019

Summary

Adds the implementation of fake timers using Lolex from all of my other PRs. Note that this does not include a way to actually use this in Jest - It's just the implementation. This is not terribly useful on its own, but it makes it easier to keep up to date with the current implementation, and less rebasing work.

Test plan

Test added, which is a copy of the current tests with initialization changed for Lolex

setImmediate(() => f());
jest.runAllImmediates();
expect(f.mock.calls.length).toBe(1);
setTimeout(f, 0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of these changes does not strictly have to be here, but it's needed when we actually start using Lolex. Why not land the changes now 🤷‍♂

The reason for this change is that runAllImmediates is not supported in the Lolex implementation

@@ -5,15 +5,16 @@
jest.useFakeTimers();

it('schedules a 10-second timer after 1 second', () => {
jest.spyOn(global, 'setTimeout');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this change is that the fake timer functions in current implementation are mock functions, a feature I've purposefully not implemented in the Lolex version.

@codecov-io
Copy link

codecov-io commented Aug 31, 2019

Codecov Report

Merging #8897 into master will increase coverage by 0.02%.
The diff coverage is 69.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8897      +/-   ##
==========================================
+ Coverage   64.25%   64.27%   +0.02%     
==========================================
  Files         275      276       +1     
  Lines       11657    11700      +43     
  Branches     2845     2860      +15     
==========================================
+ Hits         7490     7520      +30     
- Misses       3544     3549       +5     
- Partials      623      631       +8
Impacted Files Coverage Δ
packages/jest-fake-timers/src/FakeTimersLolex.ts 69.76% <69.76%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70bd497...bdd5ea9. Read the comment docs.

@SimenB SimenB merged commit 9279a3a into jestjs:master Sep 6, 2019
@SimenB SimenB deleted the lolex-fake-timers branch September 6, 2019 08:42
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants