moving test helper to a waiter so that clients dont have to be the ones that register it
DELETE
addon-test-support/helpers.js
-import Ember from 'ember';
-
-/**
- * Testing helper to determine whether or not the scheduler services queues have been drained
- *
- * This function is useful for testing, because the default ember async wait helper will not
- * wait until the 'afterFirstRoutePaint' and 'afterContentPaint' queues have been drained,
- * which will cause race conditions for anything using this scheduler.
- *
- * @param app {Application} Ember testing Application
- * @param queueName {String} name of the queue to check emptiness for (i.e afterContentPaint)
- * @return {Boolean} whether or not the queueName queue is empty.
- */
-export default function isQueueDrained(app, queueName) {
- const schedulerService = app.__container__.lookup('service:scheduler');
- const queues = schedulerService.queues;
- if (!queues) {
- return true;
- }
-
- const queue = queues[queueName];
- return queue.tasks.length === 0;
-}

MODIFY
addon/services/scheduler.js
addon/services/scheduler.js
import Ember from 'ember';
+import { DEBUG } from '@glimmer/env';
const {
run,
@@ -33,7 +34,7 @@ class Queue {
}
}
-export default Service.extend({
+var Scheduler = Service.extend({
queueNames: ['afterFirstRoutePaint', 'afterContentPaint'],
init() {
@@ -164,3 +165,34 @@ export default Service.extend({
run.cancel(this._nextPaintTimeout);
}
});
+
+if (DEBUG) {
+ Scheduler.reopen({
+ init() {
+ this._super(...arguments);
+
+ if (Ember.testing) {
+ this._waiter = () => {
+ if (!this.queues) {
+ return;
+ }
+ const lastQueueName = this.queueNames[this.queueNames.length - 1];
+ const lastQueue = this.queues[lastQueueName];
+ return lastQueue.tasks.length === 0;
+ };
+ Ember.Test.registerWaiter(this._waiter);
+ }
+ },
+
+ willDestroy() {
+ if (this._waiter) {
+ Ember.Test.unregisterWaiter(this._waiter);
+ this._waiter = null;
+ }
+
+ this._super(...arguments);
+ }
+ });
+}
+
+export default Scheduler;

moving test helper to a waiter so that clients dont have to be the ones that register it