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

sinon.useFakeTimers doesn't work in version 19.0.2, prior 18 version it worked #2625

Closed
Ocke-Janssen opened this issue Oct 25, 2024 · 7 comments
Labels
Bug Cannot reproduce For issues we are unable to reproduce.

Comments

@Ocke-Janssen
Copy link

Describe the bug
const clock = sinon.useFakeTimers();
doesn't work any longer in version 19.0.2, in prior 18 version it wokred

To Reproduce
const clock = sinon.useFakeTimers();
clock.tick(1900001);
// here time is not gone by
clock.restore();

@fatso83
Copy link
Contributor

fatso83 commented Oct 28, 2024

cat > test.cjs << EOF
"use strict";
const sinon = require("./lib/sinon.js");
//import * as sinon from "./lib/sinon-esm.js";
const clock = sinon.useFakeTimers();

console.log(Date.now());

clock.tick(1900001);
console.log(Date.now());

clock.restore();
console.log(Date.now());
EOF

node test.cjs
0
1900001
1730154172960

I would say this works fine. Not reproducible.

@fatso83 fatso83 closed this as completed Oct 28, 2024
@fatso83 fatso83 added Cannot reproduce For issues we are unable to reproduce. and removed Unverified labels Oct 28, 2024
@Ocke-Janssen
Copy link
Author

I tried this code

'use strict';
const sinon = require('sinon');
const timeInPast = new Date(new Date() - 1801000);

console.log(Date.now());

const clock = sinon.useFakeTimers(timeInPast);

console.log(Date.now());

process.nextTick(() => {
console.log('nextTick');
console.log(Date.now());
});

clock.tick(3001);
console.log(Date.now());

// sinon 18 output
1730209204149
1730207403149
1730207406150
nextTick
1730209204153

// sinon 19 output
1730209240516
1730207439516
nextTick
1730207439516
1730207442517

In my case the result in a mysql query not executed.

@fatso83
Copy link
Contributor

fatso83 commented Oct 30, 2024

Ah, see that's why adding a reproduction case is important 😉

Now it makes sense. This is not a bug, but a breaking change which is implied by the semantic version increasing. If you checked out the Sinon change log you'd see the fake timer version change from 11 to 13.

The one that affects you is the change where all timers are faked by default, including nextTick. See our migration guide https://sinonjs.org/guides/migration-guide for what to do.

@Ocke-Janssen
Copy link
Author

So the documentation may should be changed ;-)

config.toFake - String[ ] - an array with explicit function names to fake. By default lolex will automatically fake all methods except process.nextTick. You could, however, still fake nextTick by providing it explicitly

@fatso83
Copy link
Contributor

fatso83 commented Oct 30, 2024

Ah, good catch!

@fatso83
Copy link
Contributor

fatso83 commented Oct 30, 2024

I guess you got it from https://sinonjs.org/releases/v19/fake-timers/. I'll update ASAP.

fatso83 added a commit that referenced this issue Oct 30, 2024
The docs were out of sync with the fake-timers docs.
@fatso83
Copy link
Contributor

fatso83 commented Oct 30, 2024

#2628

Is that would you would expect?

fatso83 added a commit that referenced this issue Oct 31, 2024
* Fix documentation issue for fake-timers mentioned in #2625

The docs were out of sync with the fake-timers docs.

* Update dependencies before new patch version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Cannot reproduce For issues we are unable to reproduce.
Projects
None yet
Development

No branches or pull requests

2 participants