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

Fake timers #315

Merged
merged 2 commits into from
Nov 9, 2021
Merged

Fake timers #315

merged 2 commits into from
Nov 9, 2021

Conversation

bpinto
Copy link
Contributor

@bpinto bpinto commented Sep 1, 2021

Depends on #314
Closes #38

@mAAdhaTTah
Copy link
Contributor

mAAdhaTTah commented Sep 9, 2021

I haven't done this upgrade because this would be a major version bump, as we're exposing the underlying fake-timers API and I believe it only supports newer versions of node. It's not quite as simple as "bump a few versions", in this case, because all of our dependent packages also then need to get major version bumps, so the whole Kefir ecosystem would need a bump.

@bpinto
Copy link
Contributor Author

bpinto commented Sep 9, 2021

Yeah, I think this would require a major version bump as @sinonjs/fake-timers has dropped support for node 8.

Many libraries are dropping support for node 10 already, but since this is only dropping support for node 8 which was last updated on 2019 I personally think the benefits of upgrading our stack vs maintaining support for node 8 are greater.

As a user of kefir and its related tools, I would like to see a bigger community so that more people are testing the code we use every day, I believe one way to achieve that is to constantly update the libraries and keep issues/PRs tidy.

@mAAdhaTTah
Copy link
Contributor

As a user of kefir and its related tools, I would like to see a bigger community so that more people are testing the code we use every day, I believe one way to achieve that is to constantly update the libraries and keep issues/PRs tidy.

Fair. I don't use Kefir as much as I used to, but I would be open to refreshing the testing utilities and it's related suite of tools. The only issue is I don't think there's a good reason to release a major version of Kefir, and if we drop Node 8 & 10 support in KTU, then we'll probs need to drop support for (or at least stop testing) those versions, which is a major version bump. At that point, there are a handful of breaking changes we may want to consider as well, and now we're starting to unravel things a bit. So that's why I haven't really bothered with all of this.

@bpinto
Copy link
Contributor Author

bpinto commented Sep 9, 2021

In theory, KTU depends on Kefir and not the other way around, so if we released a version bump of KTU, would we necessarily need to do the same with Kefir?

I mean, there is no reason a user using Kefir 3.x needs to use KTU 2.x, they could continue to use KTU 1.x versions.

@mAAdhaTTah
Copy link
Contributor

Kefir uses KTU to test itself, so if KTU no longer supported those old node versions, we wouldn't be able to test Kefir on them either, which would effectively drop support for those versions from Kefir.

@bpinto
Copy link
Contributor Author

bpinto commented Sep 9, 2021

We keep Kefir on KTU 1.x until we are ready for a major bump there? If we were to drop automated tests for node <8 on Kefir, I'm not sure if we need to do a major version bump. I mean, we wouldn't be breaking the contract it's just that we wouldn't be running automated tests on those older node versions.

@mAAdhaTTah
Copy link
Contributor

I mean, we wouldn't be breaking the contract it's just that we wouldn't be running automated tests on those older node versions.

Generally, in other OS projects, dropping testing for a Node version means that version is no longer supported, which would be a breaking change.

@bpinto
Copy link
Contributor Author

bpinto commented Sep 9, 2021

That's fair.

Ooops, so I looked into kefir build status and it's already not running tests on node 6 and 8 because of an earlier change I did. 😓

What do you think I should do?

@mAAdhaTTah
Copy link
Contributor

I think we have two options:

  1. Leave everything as is. The library works, the supporting libs work, so maybe changes aren't worth the effort.
  2. Embark on a major version overhaul of the lib + ecosystem. This actually sounds worse than it is, especially because there aren't that many planned breaking changes in the core library.

Unfortunately, I don't have a ton of time right now to work on the overhaul but I can pitch in a bit, so you'd be taking on a good amount of the work for #2 if we want to go that route.

Also cc @Macil @rpominov in case either of you have thoughts around this or if either of you are interested in & available to work on this.

@bpinto
Copy link
Contributor Author

bpinto commented Sep 13, 2021

As long as I have you mentoring me, I think we can do the changes you think we need for the major bump. I don't know what I'm signing up for yet, but as I said to you in another issue, since I'm using Kefir daily now, I'd like to help it in any way I can.

@mAAdhaTTah
Copy link
Contributor

At a high level, here's what I'm thinking:

  1. Update all of the dependencies in KTU, drop old node versions, & make any breaking changes we need to make.
  2. Update the jest & chai packages with the new KTU package, drop old node versions, & make any breaking changes we need to make.
  3. Update Kefir to use the new chai package, drop old node versions, & make any breaking changes.

None of the packages have major breaking changes, but just a couple of odds & ends that I think would be improvements. We can document this on GitHub projects if this is something you're interested in working on.

@bpinto
Copy link
Contributor Author

bpinto commented Sep 29, 2021

Okay, so let's start with 1? I believe this is a good start.

Or maybe we could look into #321 first? I think it's ready.

@bpinto bpinto force-pushed the fake-timers branch 2 times, most recently from e92cc62 to d238917 Compare October 1, 2021 12:46
@bpinto
Copy link
Contributor Author

bpinto commented Oct 1, 2021

I've rebased this PR now that #314 has been merged, I think this one is ready to be merged as well.

src/index.js Outdated
import lolex from 'lolex'
import * as fakeTimers from '@sinonjs/fake-timers'
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of import * as, let's just import install. Maybe this is an over-optimization, but if we only use install and there are other exports we don't use, this will be more tree-shakable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, I've updated it.

package.json Outdated
"@types/node": "^14.0.1",
"lolex": "^2.0.0"
"@types/sinonjs__fake-timers": "^6.0.3"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the latest version of fake-timers come w/ types? I think it might.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll check the release notes, I don't use TS myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll be upgrading fake timers to latest version, there have been quite a few releases since I first opened this PR.

In a recent release (8.0.0) types have been removed from the library.

@bpinto bpinto force-pushed the fake-timers branch 2 times, most recently from 5acdcc8 to ce80307 Compare October 1, 2021 12:58
@mAAdhaTTah
Copy link
Contributor

I believe the test failure here is the result of a flaky test but do we have any idea why that test sometimes returns 0 and sometimes 1?

@bpinto
Copy link
Contributor Author

bpinto commented Oct 1, 2021

I honestly haven't looked deep yet, but this is what I noticed the last time I looked into it.

I think we will need to mock new Date() in order to remove this flakiness.

@mAAdhaTTah
Copy link
Contributor

Hmmm, I thought Date was mocked by fake-timers... that's weird.

@bpinto
Copy link
Contributor Author

bpinto commented Oct 1, 2021

Okay, so I investigated this further, here is what I found: #335

@bpinto
Copy link
Contributor Author

bpinto commented Nov 8, 2021

@mAAdhaTTah now that #335 has been merged, tests are green with this change.

@mAAdhaTTah mAAdhaTTah merged commit c5364d4 into kefirjs:master Nov 9, 2021
@bpinto bpinto deleted the fake-timers branch November 9, 2021 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to @sinonjs/fake-timers
2 participants