DEV: Upgrade sinon and fix time based bookmark tests (#9647)

Update sinon.js to 9.0.2 to access async fake timers https://sinonjs.org/releases/v9.0.2/fake-timers/ which can then be used with acceptance tests (previously useFakeTimers didn't work with await, e.g. for visit).

Fix the bookmark acceptance test that was time based to use these new fake timers.

Add a fakeTime function that uses moment and the provided date string + timezone to freeze time using useFakeTimers and return a clock.

Add a timeStep function that accepts a clock from fakeTime and a function to run. Once the function is run we call clock.tickAsync(1000) to progress the fake clock forward 1s to progress promises/callbacks.
This commit is contained in:
Martin Brennan
2020-05-07 09:10:32 +10:00
committed by GitHub
parent 3d6c952c3e
commit 7e303f9320
6 changed files with 109 additions and 86 deletions

View File

@ -1,10 +1,13 @@
import { formattedReminderTime } from "discourse/lib/bookmark";
import { fakeTime } from "helpers/qunit-helpers";
QUnit.module("lib:bookmark", {
beforeEach() {
// set the current now time for all tests
let now = moment.tz("2020-04-11 08:00:00", "Australia/Brisbane");
sandbox.useFakeTimers(now.valueOf());
fakeTime("2020-04-11 08:00:00", "Australia/Brisbane");
},
afterEach() {
sandbox.restore();
}
});