From 5f5ae40772517166084e266c6bfc63ac9aecfc15 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Thu, 18 Apr 2019 09:46:26 -0700 Subject: [PATCH 1/7] Adding ember-test-waiters dependency --- package.json | 3 ++- yarn.lock | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c65b388f..3e9e24359 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "broccoli-funnel": "^2.0.2", "ember-assign-polyfill": "^2.6.0", "ember-cli-babel": "^7.7.3", - "ember-cli-htmlbars-inline-precompile": "^2.1.0" + "ember-cli-htmlbars-inline-precompile": "^2.1.0", + "ember-test-waiters": "scalvert/ember-test-waiters#76c5bb14b4954ac8f6feb124288153721e54a919" }, "devDependencies": { "@ember/optional-features": "^0.7.0", diff --git a/yarn.lock b/yarn.lock index 19c9cf686..38a48f69c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4548,6 +4548,12 @@ ember-source@~3.9.1: jquery "^3.3.1" resolve "^1.10.0" +ember-test-waiters@scalvert/ember-test-waiters#76c5bb14b4954ac8f6feb124288153721e54a919: + version "0.0.0" + resolved "https://codeload.github.com/scalvert/ember-test-waiters/tar.gz/76c5bb14b4954ac8f6feb124288153721e54a919" + dependencies: + ember-cli-babel "^7.1.2" + ember-try-config@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/ember-try-config/-/ember-try-config-3.0.0.tgz#012d8c90cae9eb624e2b62040bf7e76a1aa58edc" From c99d49103f2f4f09cb64068407f689221472decf Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Tue, 23 Apr 2019 14:49:23 -0700 Subject: [PATCH 2/7] Adding ember-test-waiters into settled checks and updating tests --- .../test-helpers/-internal/debug-info.ts | 45 ++++++- .../@ember/test-helpers/settled.ts | 24 ++-- addon-test-support/ember-test-helpers/wait.js | 5 +- package.json | 2 +- tests/unit/settled-test.js | 117 +++++++++++++----- tests/unit/test-debug-info-test.js | 51 ++++++-- tests/unit/utils/test-isolation-helpers.js | 6 +- yarn.lock | 7 +- 8 files changed, 200 insertions(+), 57 deletions(-) diff --git a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts index a223444db..2cf7d0123 100644 --- a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts +++ b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts @@ -6,6 +6,12 @@ import { } from '@ember/runloop'; import { DebugInfoHelper, debugInfoHelpers } from './debug-info-helpers'; import { assign } from '@ember/polyfills'; +// @ts-ignore +import { + getPendingWaiterState, + IPendingWaiterState, + ITestWaiterDebugInfo, +} from 'ember-test-waiters'; const PENDING_AJAX_REQUESTS = 'Pending AJAX requests'; const PENDING_TEST_WAITERS = 'Pending test waiters'; @@ -17,13 +23,16 @@ type MaybeDebugInfo = BackburnerDebugInfo | null; interface SettledState { hasPendingTimers: boolean; hasRunLoop: boolean; - hasPendingWaiters: boolean; + hasPendingLegacyWaiters: boolean; + hasPendingTestWaiters: boolean; hasPendingRequests: boolean; } interface SummaryInfo { hasPendingRequests: boolean; - hasPendingWaiters: boolean; + hasPendingLegacyWaiters: boolean; + hasPendingTestWaiters: boolean; + pendingTestWaiterInfo: IPendingWaiterState; autorunStackTrace: string | undefined | null; pendingTimersCount: number; hasPendingTimers: boolean; @@ -79,14 +88,16 @@ export class TestDebugInfo implements DebugInfo { constructor( hasPendingTimers: boolean, hasRunLoop: boolean, - hasPendingWaiters: boolean, + hasPendingLegacyWaiters: boolean, + hasPendingTestWaiters: boolean, hasPendingRequests: boolean, debugInfo: MaybeDebugInfo = getDebugInfo() ) { this._settledState = { hasPendingTimers, hasRunLoop, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasPendingRequests, }; @@ -127,6 +138,10 @@ export class TestDebugInfo implements DebugInfo { return stacks; }, []); } + + if (this._summaryInfo.hasPendingTestWaiters) { + this._summaryInfo.pendingTestWaiterInfo = getPendingWaiterState(); + } } return this._summaryInfo; @@ -139,10 +154,30 @@ export class TestDebugInfo implements DebugInfo { _console.log(PENDING_AJAX_REQUESTS); } - if (summary.hasPendingWaiters) { + if (summary.hasPendingLegacyWaiters) { _console.log(PENDING_TEST_WAITERS); } + if (summary.hasPendingTestWaiters) { + if (!summary.hasPendingLegacyWaiters) { + _console.log(PENDING_TEST_WAITERS); + } + + Object.keys(summary.pendingTestWaiterInfo.waiters).forEach(waiter => { + _console.log(waiter); + // array of { stack: string, label: string } + let waiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiter]; + + if (Array.isArray(waiterDebugInfo)) { + waiterDebugInfo.forEach((debugInfo: ITestWaiterDebugInfo) => { + _console.log(`${debugInfo.label ? debugInfo.label : 'stack'}: ${debugInfo.stack}`); + }); + } else { + _console.log(waiterDebugInfo); + } + }); + } + if (summary.hasPendingTimers || summary.pendingScheduledQueueItemCount > 0) { _console.group(SCHEDULED_ASYNC); diff --git a/addon-test-support/@ember/test-helpers/settled.ts b/addon-test-support/@ember/test-helpers/settled.ts index 2a594698f..83babf327 100644 --- a/addon-test-support/@ember/test-helpers/settled.ts +++ b/addon-test-support/@ember/test-helpers/settled.ts @@ -5,6 +5,7 @@ import Ember from 'ember'; import { nextTick } from './-utils'; import waitUntil from './wait-until'; import { hasPendingTransitions } from './setup-application-context'; +import { hasPendingWaiters } from 'ember-test-waiters'; import DebugInfo, { TestDebugInfo } from './-internal/debug-info'; // Ember internally tracks AJAX requests in the same way that we do here for @@ -146,7 +147,8 @@ function checkWaiters() { export interface SettledState { hasRunLoop: boolean; hasPendingTimers: boolean; - hasPendingWaiters: boolean; + hasPendingLegacyWaiters: boolean; + hasPendingTestWaiters: boolean; hasPendingRequests: boolean; hasPendingTransitions: boolean | null; pendingRequestCount: number; @@ -161,7 +163,10 @@ export interface SettledState { - `hasPendingTimers` - Checks if there are scheduled timers in the run-loop. These pending timers are primarily registered by `Ember.run.schedule`. If there are pending timers, this will be `true`, otherwise `false`. - - `hasPendingWaiters` - Checks if any registered test waiters are still + - `hasPendingLegacyWaiters` - Checks if any registered legacy test waiters are still + pending (e.g. the waiter returns `true`). If there are pending waiters, + this will be `true`, otherwise `false`. + - `hasPendingTestWaiters` - Checks if any registered ember test waiters are still pending (e.g. the waiter returns `true`). If there are pending waiters, this will be `true`, otherwise `false`. - `hasPendingRequests` - Checks if there are pending AJAX requests (based on @@ -180,21 +185,24 @@ export interface SettledState { export function getSettledState(): SettledState { let hasPendingTimers = Boolean((run as any).hasScheduledTimers()); let hasRunLoop = Boolean((run as any).currentRunLoop); - let hasPendingWaiters = checkWaiters(); + let hasPendingLegacyWaiters = checkWaiters(); + let hasPendingTestWaiters = hasPendingWaiters(); let pendingRequestCount = pendingRequests(); let hasPendingRequests = pendingRequestCount > 0; return { hasPendingTimers, hasRunLoop, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasPendingRequests, hasPendingTransitions: hasPendingTransitions(), pendingRequestCount, debugInfo: new TestDebugInfo( hasPendingTimers, hasRunLoop, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasPendingRequests ), }; @@ -215,7 +223,8 @@ export function isSettled(): boolean { hasPendingTimers, hasRunLoop, hasPendingRequests, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasPendingTransitions, } = getSettledState(); @@ -223,7 +232,8 @@ export function isSettled(): boolean { hasPendingTimers || hasRunLoop || hasPendingRequests || - hasPendingWaiters || + hasPendingLegacyWaiters || + hasPendingTestWaiters || hasPendingTransitions ) { return false; diff --git a/addon-test-support/ember-test-helpers/wait.js b/addon-test-support/ember-test-helpers/wait.js index 1652c17f1..cb449c680 100644 --- a/addon-test-support/ember-test-helpers/wait.js +++ b/addon-test-support/ember-test-helpers/wait.js @@ -29,7 +29,8 @@ export default function wait(options = {}) { hasPendingTimers, hasRunLoop, hasPendingRequests, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, } = getSettledState(); if (waitForTimers && (hasPendingTimers || hasRunLoop)) { @@ -40,7 +41,7 @@ export default function wait(options = {}) { return false; } - if (waitForWaiters && hasPendingWaiters) { + if (waitForWaiters && (hasPendingLegacyWaiters || hasPendingTestWaiters)) { return false; } diff --git a/package.json b/package.json index 3e9e24359..fef4646a3 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "ember-assign-polyfill": "^2.6.0", "ember-cli-babel": "^7.7.3", "ember-cli-htmlbars-inline-precompile": "^2.1.0", - "ember-test-waiters": "scalvert/ember-test-waiters#76c5bb14b4954ac8f6feb124288153721e54a919" + "ember-test-waiters": "^0.9.0" }, "devDependencies": { "@ember/optional-features": "^0.7.0", diff --git a/tests/unit/settled-test.js b/tests/unit/settled-test.js index 929485e66..bcbab7fd4 100644 --- a/tests/unit/settled-test.js +++ b/tests/unit/settled-test.js @@ -5,10 +5,13 @@ import { TestDebugInfo } from '@ember/test-helpers/-internal/debug-info'; import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { _setupAJAXHooks, _teardownAJAXHooks } from '@ember/test-helpers/settled'; import { next, later, run, schedule } from '@ember/runloop'; +import { buildWaiter, _reset as resetWaiters } from 'ember-test-waiters'; import Pretender from 'pretender'; import hasjQuery from '../helpers/has-jquery'; import ajax from '../helpers/ajax'; +const WAITER_NAME = 'custom-waiter'; + module('settled', function(hooks) { if (!hasEmberVersion(2, 4)) { return; @@ -26,11 +29,12 @@ module('settled', function(hooks) { { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, false, false, false), + debugInfo: new TestDebugInfo(false, false, false, false, false), }, 'post cond - getSettledState' ); @@ -50,7 +54,7 @@ module('settled', function(hooks) { ); }); - this._waiter = () => { + this._legacyWaiter = () => { return !this.isWaiterPending; }; @@ -61,11 +65,14 @@ module('settled', function(hooks) { // use: // // import { registerWaiter } from '@ember/test'; - Ember.Test.registerWaiter(this._waiter); + Ember.Test.registerWaiter(this._legacyWaiter); + + this._testWaiter = buildWaiter(WAITER_NAME); }); hooks.afterEach(function() { - Ember.Test.unregisterWaiter(this._waiter); + Ember.Test.unregisterWaiter(this._legacyWaiter); + resetWaiters(); this.server.shutdown(); _teardownAJAXHooks(); }); @@ -134,7 +141,7 @@ module('settled', function(hooks) { assert.strictEqual(isSettled(), false); }); - test('when waiters are pending', function(assert) { + test('when legacy waiters are pending', function(assert) { assert.expect(3); assert.strictEqual(isSettled(), true, 'precond'); @@ -147,6 +154,22 @@ module('settled', function(hooks) { assert.strictEqual(isSettled(), true, 'post cond'); }); + + test('when test waiters are pending', function(assert) { + assert.expect(3); + + let waiterItem = {}; + + assert.strictEqual(isSettled(), true, 'precond'); + + this._testWaiter.beginAsync(waiterItem); + + assert.strictEqual(isSettled(), false); + + this._testWaiter.endAsync(waiterItem); + + assert.strictEqual(isSettled(), true, 'post cond'); + }); }); module('getSettledState', function() { @@ -154,11 +177,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, false, false, false), + debugInfo: new TestDebugInfo(false, false, false, false, false), }); }); @@ -173,11 +197,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(true, true, false, false), + debugInfo: new TestDebugInfo(true, true, false, false, false), }); }); @@ -193,11 +218,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(true, false, false, false), + debugInfo: new TestDebugInfo(true, false, false, false, false), }); }); @@ -213,11 +239,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(true, false, false, false), + debugInfo: new TestDebugInfo(true, false, false, false, false), }); }); @@ -230,11 +257,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, true, false, false), + debugInfo: new TestDebugInfo(false, true, false, false, false), }); }); @@ -259,26 +287,28 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: true, hasPendingTimers: false, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 1, - debugInfo: new TestDebugInfo(false, false, false, true), + debugInfo: new TestDebugInfo(false, false, false, false, true), }); } else { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: true, + hasPendingLegacyWaiters: true, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, false, true, false), + debugInfo: new TestDebugInfo(false, false, true, false, false), }); } }); - test('when waiters are pending', function(assert) { + test('when legacy waiters are pending', function(assert) { assert.expect(3); assert.strictEqual(isSettled(), true, 'precond'); @@ -288,11 +318,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: true, + hasPendingLegacyWaiters: true, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, false, true, false), + debugInfo: new TestDebugInfo(false, false, true, false, false), }); this.isWaiterPending = false; @@ -300,6 +331,31 @@ module('settled', function(hooks) { assert.strictEqual(isSettled(), true, 'post cond'); }); + test('when test waiters are pending', function(assert) { + assert.expect(3); + + let waiterItem = {}; + + assert.strictEqual(isSettled(), true, 'precond'); + + this._testWaiter.beginAsync(waiterItem); + + assert.deepEqual(getSettledState(), { + hasPendingRequests: false, + hasPendingTimers: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: true, + hasPendingTransitions: null, + hasRunLoop: false, + pendingRequestCount: 0, + debugInfo: new TestDebugInfo(false, false, false, true, false), + }); + + this._testWaiter.endAsync(waiterItem); + + assert.strictEqual(isSettled(), true, 'post cond'); + }); + test('all the things!', function(assert) { assert.expect(6); let done = assert.async(); @@ -310,22 +366,24 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: true, + hasPendingLegacyWaiters: true, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, false, true, false), + debugInfo: new TestDebugInfo(false, false, true, false, false), }); run(() => { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: true, + hasPendingLegacyWaiters: true, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(false, true, true, false), + debugInfo: new TestDebugInfo(false, true, true, false, false), }); next(this.confirmSettles(done)); @@ -333,11 +391,12 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingWaiters: true, + hasPendingLegacyWaiters: true, + hasPendingTestWaiters: false, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, - debugInfo: new TestDebugInfo(true, true, true, false), + debugInfo: new TestDebugInfo(true, true, true, false, false), }); this.isWaiterPending = false; diff --git a/tests/unit/test-debug-info-test.js b/tests/unit/test-debug-info-test.js index 00e695c82..e571ff6d4 100644 --- a/tests/unit/test-debug-info-test.js +++ b/tests/unit/test-debug-info-test.js @@ -8,6 +8,7 @@ import MockStableError, { overrideError, resetError } from './utils/mock-stable- import { MockConsole, getRandomBoolean, getMockDebugInfo } from './utils/test-isolation-helpers'; import { registerDebugInfoHelper } from '@ember/test-helpers'; import { debugInfoHelpers } from '@ember/test-helpers/-internal/debug-info-helpers'; +import { buildWaiter, _reset as resetWaiters } from 'ember-test-waiters'; module('TestDebugInfo', function(hooks) { hooks.beforeEach(function() { @@ -22,20 +23,23 @@ module('TestDebugInfo', function(hooks) { assert.expect(1); let hasPendingTimers = getRandomBoolean(); - let hasPendingWaiters = getRandomBoolean(); + let hasPendingLegacyWaiters = getRandomBoolean(); + let hasPendingTestWaiters = false; let hasRunLoop = getRandomBoolean(); let hasPendingRequests = Boolean(Math.floor(Math.random(10)) > 0); let testDebugInfo = new TestDebugInfo( hasPendingTimers, hasRunLoop, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasPendingRequests ); assert.deepEqual(testDebugInfo.summary, { hasPendingRequests, hasPendingTimers, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasRunLoop, }); }); @@ -70,6 +74,7 @@ module('TestDebugInfo', function(hooks) { false, false, false, + false, run.backburner.getDebugInfo() ); @@ -77,7 +82,8 @@ module('TestDebugInfo', function(hooks) { autorunStackTrace: null, hasPendingRequests: false, hasPendingTimers: false, - hasPendingWaiters: false, + hasPendingLegacyWaiters: false, + hasPendingTestWaiters: false, hasRunLoop: false, pendingScheduledQueueItemCount: 0, pendingScheduledQueueItemStackTraces: [], @@ -93,7 +99,7 @@ module('TestDebugInfo', function(hooks) { let mockConsole = new MockConsole(); - let testDebugInfo = new TestDebugInfo(false, false, false, false); + let testDebugInfo = new TestDebugInfo(false, false, false, false, false); testDebugInfo.toConsole(mockConsole); @@ -110,6 +116,7 @@ module('TestDebugInfo', function(hooks) { true, false, false, + false, getMockDebugInfo(new MockStableError('STACK'), 0, null) ); @@ -127,25 +134,51 @@ STACK` let mockConsole = new MockConsole(); - let testDebugInfo = new TestDebugInfo(false, false, false, true); + let testDebugInfo = new TestDebugInfo(false, false, false, false, true); testDebugInfo.toConsole(mockConsole); assert.deepEqual(mockConsole.toString(), `Pending AJAX requests`); }); - test('toConsole correctly prints pending test waiter information', function(assert) { + test('toConsole correctly prints pending legacy test waiter information', function(assert) { assert.expect(1); let mockConsole = new MockConsole(); - let testDebugInfo = new TestDebugInfo(false, false, true, false); + let testDebugInfo = new TestDebugInfo(false, false, true, false, false); testDebugInfo.toConsole(mockConsole); assert.deepEqual(mockConsole.toString(), `Pending test waiters`); }); + test('toConsole correctly prints pending test waiter information', function(assert) { + assert.expect(1); + + let waiterItem = {}; + let mockConsole = new MockConsole(); + let testWaiter = buildWaiter('custom-waiter'); + + overrideError(MockStableError); + + testWaiter.beginAsync(waiterItem); + + let testDebugInfo = new TestDebugInfo(false, false, false, true, false); + + testDebugInfo.toConsole(mockConsole); + + assert.deepEqual( + mockConsole.toString(), + `Pending test waiters +custom-waiter +stack: STACK` + ); + + resetError(); + resetWaiters(); + }); + test('toConsole correctly prints scheduled async information', function(assert) { assert.expect(1); @@ -156,6 +189,7 @@ STACK` true, false, false, + false, getMockDebugInfo(false, 2, [{ name: 'one', count: 1 }, { name: 'two', count: 1 }]) ); @@ -181,6 +215,7 @@ STACK` false, false, false, + false, getMockDebugInfo(false, 0, [{ name: 'one', count: 1 }, { name: 'two', count: 1 }]) ); diff --git a/tests/unit/utils/test-isolation-helpers.js b/tests/unit/utils/test-isolation-helpers.js index c62eda44a..a1c9f372b 100644 --- a/tests/unit/utils/test-isolation-helpers.js +++ b/tests/unit/utils/test-isolation-helpers.js @@ -48,14 +48,16 @@ export function getMockDebugInfo(autorun = null, timersCount = 0, queues) { export function getMockSettledState( hasPendingTimers = false, hasRunLoop = false, - hasPendingWaiters = false, + hasPendingLegacyWaiters = false, + hasPendingTestWaiters = false, hasPendingRequests = false, pendingRequestCount = 0 ) { return { hasPendingTimers, hasRunLoop, - hasPendingWaiters, + hasPendingLegacyWaiters, + hasPendingTestWaiters, hasPendingRequests, pendingRequestCount, }; diff --git a/yarn.lock b/yarn.lock index 38a48f69c..e2a05a622 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4548,9 +4548,10 @@ ember-source@~3.9.1: jquery "^3.3.1" resolve "^1.10.0" -ember-test-waiters@scalvert/ember-test-waiters#76c5bb14b4954ac8f6feb124288153721e54a919: - version "0.0.0" - resolved "https://codeload.github.com/scalvert/ember-test-waiters/tar.gz/76c5bb14b4954ac8f6feb124288153721e54a919" +ember-test-waiters@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/ember-test-waiters/-/ember-test-waiters-0.9.0.tgz#601129bbf482dfd1b2615d1eef0316a886df0937" + integrity sha512-+8w4DbelsIW6jU1sZ+4V1knIvdhyYFOUxy/3aYhwbPObPdiNzWvW/D/xuAOTRAZqLsN6u47zAdh/Z7qVtb83pQ== dependencies: ember-cli-babel "^7.1.2" From 2994f1e4158b3f1b2dc18cf7d11d50d504285f06 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Tue, 23 Apr 2019 15:41:54 -0700 Subject: [PATCH 3/7] Remove @ts-ignore on imports --- addon-test-support/@ember/test-helpers/-internal/debug-info.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts index 2cf7d0123..1ae0b020c 100644 --- a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts +++ b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts @@ -6,7 +6,6 @@ import { } from '@ember/runloop'; import { DebugInfoHelper, debugInfoHelpers } from './debug-info-helpers'; import { assign } from '@ember/polyfills'; -// @ts-ignore import { getPendingWaiterState, IPendingWaiterState, From 281096b0060ed7266a7b77b376e7cea582407f1f Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Tue, 23 Apr 2019 15:43:25 -0700 Subject: [PATCH 4/7] Removing unnecessary comment --- addon-test-support/@ember/test-helpers/-internal/debug-info.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts index 1ae0b020c..a6c15a291 100644 --- a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts +++ b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts @@ -164,7 +164,7 @@ export class TestDebugInfo implements DebugInfo { Object.keys(summary.pendingTestWaiterInfo.waiters).forEach(waiter => { _console.log(waiter); - // array of { stack: string, label: string } + let waiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiter]; if (Array.isArray(waiterDebugInfo)) { From 841cff8f6e4256549f968a2a0597c2c9c0a91fac Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Thu, 25 Apr 2019 14:35:54 -0700 Subject: [PATCH 5/7] Refining type for waiterDebugInfo --- addon-test-support/@ember/test-helpers/-internal/debug-info.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts index a6c15a291..eee88bb79 100644 --- a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts +++ b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts @@ -18,6 +18,7 @@ const SCHEDULED_ASYNC = 'Scheduled async'; const SCHEDULED_AUTORUN = 'Scheduled autorun'; type MaybeDebugInfo = BackburnerDebugInfo | null; +type WaiterDebugInfo = true | unknown[]; interface SettledState { hasPendingTimers: boolean; @@ -165,7 +166,7 @@ export class TestDebugInfo implements DebugInfo { Object.keys(summary.pendingTestWaiterInfo.waiters).forEach(waiter => { _console.log(waiter); - let waiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiter]; + let waiterDebugInfo: WaiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiter]; if (Array.isArray(waiterDebugInfo)) { waiterDebugInfo.forEach((debugInfo: ITestWaiterDebugInfo) => { From a4e3e474fb3619007fccd19cf894579def60e1f6 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Fri, 26 Apr 2019 12:11:17 -0700 Subject: [PATCH 6/7] Reverting public settled interface to hide the multiple waiters implementation behind a single flag --- .../test-helpers/-internal/debug-info.ts | 10 ++--- .../@ember/test-helpers/settled.ts | 17 +++----- tests/unit/settled-test.js | 39 +++++++------------ 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts index eee88bb79..2cc787316 100644 --- a/addon-test-support/@ember/test-helpers/-internal/debug-info.ts +++ b/addon-test-support/@ember/test-helpers/-internal/debug-info.ts @@ -163,17 +163,17 @@ export class TestDebugInfo implements DebugInfo { _console.log(PENDING_TEST_WAITERS); } - Object.keys(summary.pendingTestWaiterInfo.waiters).forEach(waiter => { - _console.log(waiter); - - let waiterDebugInfo: WaiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiter]; + Object.keys(summary.pendingTestWaiterInfo.waiters).forEach(waiterName => { + let waiterDebugInfo: WaiterDebugInfo = summary.pendingTestWaiterInfo.waiters[waiterName]; if (Array.isArray(waiterDebugInfo)) { + _console.group(waiterName); waiterDebugInfo.forEach((debugInfo: ITestWaiterDebugInfo) => { _console.log(`${debugInfo.label ? debugInfo.label : 'stack'}: ${debugInfo.stack}`); }); + _console.groupEnd(); } else { - _console.log(waiterDebugInfo); + _console.log(waiterName); } }); } diff --git a/addon-test-support/@ember/test-helpers/settled.ts b/addon-test-support/@ember/test-helpers/settled.ts index 83babf327..e7b519250 100644 --- a/addon-test-support/@ember/test-helpers/settled.ts +++ b/addon-test-support/@ember/test-helpers/settled.ts @@ -147,8 +147,7 @@ function checkWaiters() { export interface SettledState { hasRunLoop: boolean; hasPendingTimers: boolean; - hasPendingLegacyWaiters: boolean; - hasPendingTestWaiters: boolean; + hasPendingWaiters: boolean; hasPendingRequests: boolean; hasPendingTransitions: boolean | null; pendingRequestCount: number; @@ -163,10 +162,7 @@ export interface SettledState { - `hasPendingTimers` - Checks if there are scheduled timers in the run-loop. These pending timers are primarily registered by `Ember.run.schedule`. If there are pending timers, this will be `true`, otherwise `false`. - - `hasPendingLegacyWaiters` - Checks if any registered legacy test waiters are still - pending (e.g. the waiter returns `true`). If there are pending waiters, - this will be `true`, otherwise `false`. - - `hasPendingTestWaiters` - Checks if any registered ember test waiters are still + - `hasPendingWaiters` - Checks if any registered test waiters are still pending (e.g. the waiter returns `true`). If there are pending waiters, this will be `true`, otherwise `false`. - `hasPendingRequests` - Checks if there are pending AJAX requests (based on @@ -193,8 +189,7 @@ export function getSettledState(): SettledState { return { hasPendingTimers, hasRunLoop, - hasPendingLegacyWaiters, - hasPendingTestWaiters, + hasPendingWaiters: hasPendingLegacyWaiters || hasPendingTestWaiters, hasPendingRequests, hasPendingTransitions: hasPendingTransitions(), pendingRequestCount, @@ -223,8 +218,7 @@ export function isSettled(): boolean { hasPendingTimers, hasRunLoop, hasPendingRequests, - hasPendingLegacyWaiters, - hasPendingTestWaiters, + hasPendingWaiters, hasPendingTransitions, } = getSettledState(); @@ -232,8 +226,7 @@ export function isSettled(): boolean { hasPendingTimers || hasRunLoop || hasPendingRequests || - hasPendingLegacyWaiters || - hasPendingTestWaiters || + hasPendingWaiters || hasPendingTransitions ) { return false; diff --git a/tests/unit/settled-test.js b/tests/unit/settled-test.js index bcbab7fd4..dfe40f5dd 100644 --- a/tests/unit/settled-test.js +++ b/tests/unit/settled-test.js @@ -29,8 +29,7 @@ module('settled', function(hooks) { { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -177,8 +176,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -197,8 +195,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, @@ -218,8 +215,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -239,8 +235,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -257,8 +252,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, @@ -287,8 +281,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: true, hasPendingTimers: false, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, + hasPendingWaiters: false, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 1, @@ -298,8 +291,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: true, - hasPendingTestWaiters: false, + hasPendingWaiters: true, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -318,8 +310,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: true, - hasPendingTestWaiters: false, + hasPendingWaiters: true, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -343,8 +334,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: true, + hasPendingWaiters: true, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -366,8 +356,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: true, - hasPendingTestWaiters: false, + hasPendingWaiters: true, hasPendingTransitions: null, hasRunLoop: false, pendingRequestCount: 0, @@ -378,8 +367,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: false, - hasPendingLegacyWaiters: true, - hasPendingTestWaiters: false, + hasPendingWaiters: true, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, @@ -391,8 +379,7 @@ module('settled', function(hooks) { assert.deepEqual(getSettledState(), { hasPendingRequests: false, hasPendingTimers: true, - hasPendingLegacyWaiters: true, - hasPendingTestWaiters: false, + hasPendingWaiters: true, hasPendingTransitions: null, hasRunLoop: true, pendingRequestCount: 0, From 9c7cd0fae64275f03dea7b9d5fd549f264c06257 Mon Sep 17 00:00:00 2001 From: Steve Calvert Date: Fri, 26 Apr 2019 12:16:28 -0700 Subject: [PATCH 7/7] Reverting wait.js --- addon-test-support/ember-test-helpers/wait.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addon-test-support/ember-test-helpers/wait.js b/addon-test-support/ember-test-helpers/wait.js index cb449c680..1652c17f1 100644 --- a/addon-test-support/ember-test-helpers/wait.js +++ b/addon-test-support/ember-test-helpers/wait.js @@ -29,8 +29,7 @@ export default function wait(options = {}) { hasPendingTimers, hasRunLoop, hasPendingRequests, - hasPendingLegacyWaiters, - hasPendingTestWaiters, + hasPendingWaiters, } = getSettledState(); if (waitForTimers && (hasPendingTimers || hasRunLoop)) { @@ -41,7 +40,7 @@ export default function wait(options = {}) { return false; } - if (waitForWaiters && (hasPendingLegacyWaiters || hasPendingTestWaiters)) { + if (waitForWaiters && hasPendingWaiters) { return false; }