Ticketfly / ember-mockdate-shim

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

Issue with acceptance tests since ember 2.15. #4

Closed kiwi-josh closed 6 years ago

kiwi-josh commented 6 years ago

I have experienced issues with this addon in acceptance tests ever since I updated from Ember 2.14 to 2.15. My acceptance tests get stuck in an infinite loop when calling platform.now on this line of backburner.js

I believe its because backburner.js v1.1.2 made some changes to the way that v0.4.0 (which was in 2.14) used to handle getting now. A PR that is now in v1.1.2 exposed a way to configure now seperate to the global Date object - https://github.com/BackburnerJS/backburner.js/pull/264. Unfortunately by calling freezeDateAt in an acceptance test, it now also freezes backburners concept of now, which means all of its internal timers never progress and the tests lock up.

I have managed to get around this problem by implementing my own helpers methods.

import { freezeDateAt as fda, unfreezeDate as ufd } from 'ember-mockdate-shim';

const ogDate = Date;
const ogPlatformNow = Ember.run.backburner._platform.now;

// Create our own version of freezeDateAt that first calls the freeze date mock date
// function, AND then monkeypatches the backburner now function back to the og date
// reference so that ember run loop doesn't get stuck in a loop.
export const freezeDateAt = function(date) {
  fda(date);
  Ember.run.backburner._platform.now = () => ogDate();
};

// Restore the original platform now function before calling the mockdate unfreeze
// function.
export const unfreezeDate = function() {
  Ember.run.backburner._platform.now = ogPlatformNow;
  ufd();
};

Perhaps these functions could be worked back into this shim properly?

spencer516 commented 6 years ago

Absolutely they can — thanks for figuring this out!

Totally open to PR's for this. If not, I'll try to see if I can get to it this week.

spencer516 commented 6 years ago

Fixed by #6