discourse/test/javascripts
Martin Brennan 0e09c5837f DEV: Try once more to make acceptance test fake timers work
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");
  });
});
```
2020-05-13 15:16:07 +10:00
..
acceptance DEV: Try once more to make acceptance test fake timers work 2020-05-13 15:16:07 +10:00
admin Retry: Rename all test files from JS -> ES6 2020-03-26 12:25:46 -04:00
components DEV: allows buttons to define aria-label (#9747) 2020-05-11 22:09:44 +02:00
controllers FIX: CurrentUser now must be passed to resolveTimezone and user card local time issues (#9734) 2020-05-11 11:01:47 +10:00
ember Retry: Rename all test files from JS -> ES6 2020-03-26 12:25:46 -04:00
fixtures FIX: Change /bookmarks URL back to topic list and add bookmark poster avatars (#9759) 2020-05-13 14:03:24 +10:00
helpers DEV: Try once more to make acceptance test fake timers work 2020-05-13 15:16:07 +10:00
initializers Retry: Rename all test files from JS -> ES6 2020-03-26 12:25:46 -04:00
lib DEV: Remove INLINE_ONEBOX_* constants 2020-05-07 16:14:38 -04:00
mixins Retry: Rename all test files from JS -> ES6 2020-03-26 12:25:46 -04:00
models FIX: CurrentUser now must be passed to resolveTimezone and user card local time issues (#9734) 2020-05-11 11:01:47 +10:00
utils Retry: Rename all test files from JS -> ES6 2020-03-26 12:25:46 -04:00
widgets DEV: Add remove button function to PluginAPI (#9627) 2020-05-05 09:18:02 -04:00
plugin_tests.js.erb Support for Acceptance tests in plugins 2015-08-27 17:07:11 -04:00
test_helper.js DEV: calling preload-store is deprecated (#9703) 2020-05-08 17:04:28 +02:00