Ticketfly / ember-mockdate-shim

ES6 accessible module for MockDate within your Ember application
MIT License
15 stars 7 forks source link

Feature/enable acceptance test usage #6

Closed kiwi-josh closed 6 years ago

kiwi-josh commented 6 years ago

This PR solves the issue described in this issue: https://github.com/Ticketfly/ember-mockdate-shim/issues/4

It should be merged after https://github.com/Ticketfly/ember-mockdate-shim/pull/5, as it also contains the ember 2.16 upgrade code.

It also adds a couple of integration and acceptance tests for piece of mind 😄

To demonstrate the issue in action, simply revert the addon/index.js file and you will see that the added acceptance test will hang and never complete.

kiwi-josh commented 6 years ago

Okay so I've got the tests passing now. I've been down a bit of a rabbit hole with this PR this afternoon.

So as it turns out, acceptance test support is only available on Ember 2.15.1 and above. This is when ember upgraded backburner to 1.2.1, which contains the ability to make now configurable.

Previous versions of backburner (and hence ember) don't allow a mechanism to monkey patch now for backburner in acceptance tests.

This issue is only observed when there is async behaviour in an acceptance test. For example, the freezeDateAt helper works fine in an acceptance test, until you do this:

import Route from "@ember/routing/route";
import { Promise } from "rsvp";
import { next } from "@ember/runloop";

export default Route.extend({
  // Return async model to test that embers run loop doesn't fall
  // into an infinite loop when freezing time in acceptance tests.
  model() {
    return new Promise((res => next(() => res())));
  },
});

As soon as you introduce a async model hook, backburner will never advance its internal timers because the js Date object has been overwritten by mockdate here.

This PR fixes this my using the new configurable _platform.now value of backburner before freezing.

spencer516 commented 6 years ago

This is great. Thanks for taking care of this!

I'll try to publish this to npm later today.