mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
0e09c5837f
In my original PR (#9647) I attempted to solve the problem of using fake timers in acceptance tests by using the new sinon clock.tickAsync methods. This way of doing things seems to be flawed, however, as we are getting random spec timeouts starting with the bookmark acceptance test where this was introduced. I think I was going about things the wrong way. This commit introduces a new function with callback (acceptanceUseFakeClock) that sets up the fake timers using sinon.useFakeTimers with the shouldAdvanceTime option set to true. This advances time at a normal rate of 20ms per tick, which means that we are not freezing any time and existing setTimeout funcs. should proceed as normal. Along with this the callback passed will run clock.reset() at the end to make sure all the timers are cleaned up correctly. There is an optional third parameter after the callback, which is the timezone. If the user is logged in for the acceptance test then their timezone is used, otherwise we default to America/Denver. Usage is (inside an acceptance test): ``` test("Name of the test", async assert => { // first parameter is time to start fake clock at await acceptanceUseFakeClock("2020-05-04T13:00:00", async () => { // test code goes here e.g. await visit("/url"); }); }); ``` |
||
---|---|---|
.. | ||
javascripts | ||
stylesheets | ||
run-qunit.js | ||
smoke_test.js |