diff --git a/API.md b/API.md index 963ad17bd..f85e55b2a 100644 --- a/API.md +++ b/API.md @@ -678,7 +678,7 @@ Returns **[Promise][71]\** resolves when settled Checks various settledness metrics (via `getSettledState()`) to determine if things are settled or not. Settled generally means that there are no pending timers, no pending waiters, -no pending AJAX requests, and no current run loop. However, new settledness +no pending requests, and no current run loop. However, new settledness metrics may be added and used as they become available. Returns **[boolean][76]** `true` if settled, `false` otherwise @@ -695,13 +695,12 @@ Check various settledness metrics, and return an object with the following prope * `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 - `ajaxSend` / `ajaxComplete` events triggered by `jQuery.ajax`). If there +* `hasPendingRequests` - Checks if there are pending requests. If there are pending requests, this will be `true`, otherwise `false`. * `hasPendingTransitions` - Checks if there are pending route transitions. If the router has not been instantiated / setup for the test yet this will return `null`, if there are pending transitions, this will be `true`, otherwise `false`. -* `pendingRequestCount` - The count of pending AJAX requests. +* `pendingRequestCount` - The count of pending requests. * `debugInfo` - Debug information that's combined with info return from backburner's getDebugInfo method. * `isRenderPending` - Checks if there are any pending render operations. This will be true as long @@ -821,7 +820,6 @@ Responsible for: * sets the "global testing context" to the provided context (`setContext`) * create an owner object and set it on the provided context (e.g. `this.owner`) * setup `this.set`, `this.setProperties`, `this.get`, and `this.getProperties` to the provided context -* setting up AJAX listeners * setting up `pauseTest` (also available as `this.pauseTest()`) and `resumeTest` helpers #### Parameters @@ -863,7 +861,6 @@ Responsible for: * un-setting the "global testing context" (`unsetContext`) * destroy the contexts owner object -* remove AJAX listeners #### Parameters @@ -1030,7 +1027,7 @@ etc. that are then used in a template) has been updated in the DOM. For example, in a test you might want to update some tracked state and then run some assertions after rendering has completed. You *could* use `await settled()` in that location, but in some contexts you don't want to -wait for full settledness (which includes test waiters, pending AJAX/fetch, +wait for full settledness (which includes test waiters, pending fetch, run loops, etc) but instead only want to know when that updated value has been rendered in the DOM. **THAT** is what `await rerender()` is *perfect* for. diff --git a/addon/src/-internal/debug-info.ts b/addon/src/-internal/debug-info.ts index d3bb09f9b..62d176203 100644 --- a/addon/src/-internal/debug-info.ts +++ b/addon/src/-internal/debug-info.ts @@ -12,7 +12,7 @@ import { type PendingWaiterState, } from '@ember/test-waiters'; -const PENDING_AJAX_REQUESTS = 'Pending AJAX requests'; +const PENDING_REQUESTS = 'Pending requests'; const PENDING_TEST_WAITERS = 'Pending test waiters'; const SCHEDULED_ASYNC = 'Scheduled async'; const SCHEDULED_AUTORUN = 'Scheduled autorun'; @@ -158,7 +158,7 @@ export class TestDebugInfo implements DebugInfo { const summary = this.summary; if (summary.hasPendingRequests) { - _console.log(PENDING_AJAX_REQUESTS); + _console.log(PENDING_REQUESTS); } if (summary.hasPendingLegacyWaiters) { diff --git a/addon/src/rerender.ts b/addon/src/rerender.ts index 143e7dc0c..c3a871b92 100644 --- a/addon/src/rerender.ts +++ b/addon/src/rerender.ts @@ -9,7 +9,7 @@ import renderSettled from './-internal/render-settled.ts'; For example, in a test you might want to update some tracked state and then run some assertions after rendering has completed. You _could_ use `await settled()` in that location, but in some contexts you don't want to - wait for full settledness (which includes test waiters, pending AJAX/fetch, + wait for full settledness (which includes test waiters, pending fetch, run loops, etc) but instead only want to know when that updated value has been rendered in the DOM. **THAT** is what `await rerender()` is _perfect_ for. diff --git a/addon/src/settled.ts b/addon/src/settled.ts index 859a4e745..d07f0c149 100644 --- a/addon/src/settled.ts +++ b/addon/src/settled.ts @@ -5,14 +5,12 @@ import { _backburner } from '@ember/runloop'; import { Test } from 'ember-testing'; import { pendingRequests as _internalGetPendingRequestsCount } from 'ember-testing/lib/test/pending_requests'; -import { nextTick } from './-utils.ts'; import waitUntil from './wait-until.ts'; import { hasPendingTransitions } from './setup-application-context.ts'; import { hasPendingWaiters } from '@ember/test-waiters'; import type DebugInfo from './-internal/debug-info.ts'; import { TestDebugInfo } from './-internal/debug-info.ts'; -let requests: XMLHttpRequest[]; const checkWaiters = Test.checkWaiters; /** @@ -20,89 +18,7 @@ const checkWaiters = Test.checkWaiters; @returns {number} the count of pending requests */ function pendingRequests() { - const localRequestsPending = requests !== undefined ? requests.length : 0; - const internalRequestsPending = _internalGetPendingRequestsCount(); - - return localRequestsPending + internalRequestsPending; -} - -/** - @private - @param {Event} event (unused) - @param {XMLHTTPRequest} xhr the XHR that has initiated a request -*/ -function incrementAjaxPendingRequests(event: any, xhr: XMLHttpRequest): void { - requests.push(xhr); -} - -/** - @private - @param {Event} event (unused) - @param {XMLHTTPRequest} xhr the XHR that has initiated a request -*/ -function decrementAjaxPendingRequests(event: any, xhr: XMLHttpRequest): void { - // In most Ember versions to date (current version is 2.16) RSVP promises are - // configured to flush in the actions queue of the Ember run loop, however it - // is possible that in the future this changes to use "true" micro-task - // queues. - // - // The entire point here, is that _whenever_ promises are resolved will be - // before the next run of the JS event loop. Then in the next event loop this - // counter will decrement. In the specific case of AJAX, this means that any - // promises chained off of `$.ajax` will properly have their `.then` called - // _before_ this is decremented (and testing continues) - nextTick(() => { - for (let i = 0; i < requests.length; i++) { - if (xhr === requests[i]) { - requests.splice(i, 1); - } - } - }); -} - -/** - Clears listeners that were previously setup for `ajaxSend` and `ajaxComplete`. - - @private -*/ -export function _teardownAJAXHooks() { - // jQuery will not invoke `ajaxComplete` if - // 1. `transport.send` throws synchronously and - // 2. it has an `error` option which also throws synchronously - - // We can no longer handle any remaining requests - requests = []; - - if (typeof (globalThis as any).jQuery === 'undefined') { - return; - } - - (globalThis as any) - .jQuery(document) - .off('ajaxSend', incrementAjaxPendingRequests); - (globalThis as any) - .jQuery(document) - .off('ajaxComplete', decrementAjaxPendingRequests); -} - -/** - Sets up listeners for `ajaxSend` and `ajaxComplete`. - - @private -*/ -export function _setupAJAXHooks() { - requests = []; - - if (typeof (globalThis as any).jQuery === 'undefined') { - return; - } - - (globalThis as any) - .jQuery(document) - .on('ajaxSend', incrementAjaxPendingRequests); - (globalThis as any) - .jQuery(document) - .on('ajaxComplete', decrementAjaxPendingRequests); + return _internalGetPendingRequestsCount(); } export interface SettledState { @@ -127,13 +43,12 @@ export interface SettledState { - `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 - `ajaxSend` / `ajaxComplete` events triggered by `jQuery.ajax`). If there + - `hasPendingRequests` - Checks if there are pending requests. If there are pending requests, this will be `true`, otherwise `false`. - `hasPendingTransitions` - Checks if there are pending route transitions. If the router has not been instantiated / setup for the test yet this will return `null`, if there are pending transitions, this will be `true`, otherwise `false`. - - `pendingRequestCount` - The count of pending AJAX requests. + - `pendingRequestCount` - The count of pending requests. - `debugInfo` - Debug information that's combined with info return from backburner's getDebugInfo method. - `isRenderPending` - Checks if there are any pending render operations. This will be true as long @@ -176,7 +91,7 @@ export function getSettledState(): SettledState { Checks various settledness metrics (via `getSettledState()`) to determine if things are settled or not. Settled generally means that there are no pending timers, no pending waiters, - no pending AJAX requests, and no current run loop. However, new settledness + no pending requests, and no current run loop. However, new settledness metrics may be added and used as they become available. @public diff --git a/addon/src/setup-context.ts b/addon/src/setup-context.ts index 39bbcb088..b7b09d5bf 100644 --- a/addon/src/setup-context.ts +++ b/addon/src/setup-context.ts @@ -7,7 +7,6 @@ import type { Resolver } from '@ember/owner'; import { setOwner } from '@ember/application'; import buildOwner, { type Owner } from './build-owner.ts'; -import { _setupAJAXHooks } from './settled.ts'; import { _prepareOnerror } from './setup-onerror.ts'; import { setTesting } from '@ember/debug'; import { @@ -363,7 +362,6 @@ export function getWarningsDuringCallback( - sets the "global testing context" to the provided context (`setContext`) - create an owner object and set it on the provided context (e.g. `this.owner`) - setup `this.set`, `this.setProperties`, `this.get`, and `this.getProperties` to the provided context - - setting up AJAX listeners - setting up `pauseTest` (also available as `this.pauseTest()`) and `resumeTest` helpers @public @@ -486,8 +484,6 @@ export default function setupContext( }); }; - _setupAJAXHooks(); - return context; }); } diff --git a/addon/src/teardown-context.ts b/addon/src/teardown-context.ts index 518ad7177..f1e5fae2c 100644 --- a/addon/src/teardown-context.ts +++ b/addon/src/teardown-context.ts @@ -1,7 +1,7 @@ import type { TestContext } from './setup-context'; import { setTesting } from '@ember/debug'; import { unsetContext } from './setup-context.ts'; -import settled, { _teardownAJAXHooks } from './settled.ts'; +import settled from './settled.ts'; import { _cleanupOnerror } from './setup-onerror.ts'; import { destroy } from '@ember/destroyable'; @@ -16,7 +16,6 @@ export interface TeardownContextOptions { - un-setting the "global testing context" (`unsetContext`) - destroy the contexts owner object - - remove AJAX listeners @public @param {Object} context the context to setup @@ -31,7 +30,6 @@ export default function teardownContext( return Promise.resolve() .then(() => { _cleanupOnerror(context); - _teardownAJAXHooks(); setTesting(false); unsetContext(); diff --git a/test-app/.eslintrc.js b/test-app/.eslintrc.js index d977c3f40..0ce305951 100644 --- a/test-app/.eslintrc.js +++ b/test-app/.eslintrc.js @@ -66,8 +66,6 @@ module.exports = { 'ember/no-empty-glimmer-component-classes': 'off', 'ember/no-get': 'off', 'ember/require-super-in-lifecycle-hooks': 'off', - 'ember/no-global-jquery': 'off', - 'ember/no-jquery': 'off', 'ember/no-legacy-test-waiters': 'off', 'ember/no-pause-test': 'off', 'ember/no-settled-after-test-helper': 'off', diff --git a/test-app/package.json b/test-app/package.json index 817e896cc..362e1cc3a 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -18,7 +18,7 @@ "lint:hbs:fix": "ember-template-lint . --fix", "lint:js": "eslint . --cache", "lint:js:fix": "eslint . --fix", - "start": "pnpm _syncPnpm && concurrently 'ember serve' 'pnpm _syncPnpm --watch' --names 'tests serve,tests sync deps'", + "start": "pnpm _syncPnpm && concurrently 'ember serve --port=0' 'pnpm _syncPnpm --watch' --names 'tests serve,tests sync deps'", "test": "pnpm _syncPnpm; ember test", "test:ember": "ember test", "_syncPnpm": "DEBUG=sync-pnpm pnpm sync-dependencies-meta-injected" @@ -31,7 +31,6 @@ "devDependencies": { "@babel/eslint-parser": "^7.21.3", "@babel/plugin-proposal-decorators": "^7.21.0", - "@ember/jquery": "^2.0.0", "@ember/optional-features": "^2.0.0", "@ember/string": "^3.0.1", "@ember/test-helpers": "workspace:*", @@ -67,7 +66,6 @@ "latest-version": "^5.0.0", "loader.js": "^4.7.0", "pnpm-sync-dependencies-meta-injected": "^0.0.14", - "pretender": "^3.4.7", "prettier": "^2.8.7", "qunit": "^2.21.1", "qunit-console-grouper": "^0.3.0", diff --git a/test-app/pnpm-lock.yaml b/test-app/pnpm-lock.yaml index 523e4d8a1..2a95d5613 100644 --- a/test-app/pnpm-lock.yaml +++ b/test-app/pnpm-lock.yaml @@ -18,9 +18,6 @@ importers: '@babel/plugin-proposal-decorators': specifier: ^7.21.0 version: 7.24.7(@babel/core@7.25.2) - '@ember/jquery': - specifier: ^2.0.0 - version: 2.0.0 '@ember/optional-features': specifier: ^2.0.0 version: 2.1.0 @@ -29,7 +26,7 @@ importers: version: 3.1.1 '@ember/test-helpers': specifier: workspace:* - version: file:../addon(@babel/core@7.25.2)(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0)) + version: file:../addon(@babel/core@7.25.2) '@embroider/macros': specifier: ^1.16.10 version: 1.16.10 @@ -83,7 +80,7 @@ importers: version: 7.0.0 ember-qunit: specifier: ^8.1.0 - version: 8.1.0(@ember/test-helpers@file:../addon(@babel/core@7.25.2)(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0)))(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0))(qunit@2.22.0) + version: 8.1.0(@ember/test-helpers@file:../addon(@babel/core@7.25.2))(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0))(qunit@2.22.0) ember-resolver: specifier: ^10.0.0 version: 10.1.1(@ember/string@3.1.1)(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0)) @@ -126,9 +123,6 @@ importers: pnpm-sync-dependencies-meta-injected: specifier: ^0.0.14 version: 0.0.14 - pretender: - specifier: ^3.4.7 - version: 3.4.7 prettier: specifier: ^2.8.7 version: 2.8.8 @@ -894,10 +888,6 @@ packages: '@ember/edition-utils@1.2.0': resolution: {integrity: sha512-VmVq/8saCaPdesQmftPqbFtxJWrzxNGSQ+e8x8LLe3Hjm36pJ04Q8LeORGZkAeOhldoUX9seLGmSaHeXkIqoog==} - '@ember/jquery@2.0.0': - resolution: {integrity: sha512-f8+WNqzXBNxl96jo0IwJBO5QCi0bnUlba9I7WbZcGhgnzszC76INJkw6l8UepZ1PMGG1H1wYpoIGoBBp5ZVmFA==} - engines: {node: 12.* || 14.* || >= 16} - '@ember/optional-features@2.1.0': resolution: {integrity: sha512-IXjDpTFhsjPk9h3OXwXjlRfhM/Wjtw2E71Xos/81ZsTTwZMB9H+DWhsxePXOkzYy7Jvw4TIzKbMfcnT8mrtwWQ==} engines: {node: 10.* || 12.* || >= 14} @@ -908,8 +898,6 @@ packages: '@ember/test-helpers@file:../addon': resolution: {directory: ../addon, type: directory} - peerDependencies: - ember-source: '>= 4.0.0' '@ember/test-waiters@3.1.0': resolution: {integrity: sha512-bb9h95ktG2wKY9+ja1sdsFBdOms2lB19VWs8wmNpzgHv1NCetonBoV5jHBV4DHt0uS1tg9z66cZqhUVlYs96KQ==} @@ -3151,9 +3139,6 @@ packages: resolution: {integrity: sha512-AEo4zm+TenK7zQorGK1f9mJ8L14hnTDi2ZQPR+Mub1NX8zimka1mXpV5LpH8x9HoUmFSHZCfLHqWvp0Y4FxxzQ==} engines: {node: '>=8'} - fake-xml-http-request@2.1.2: - resolution: {integrity: sha512-HaFMBi7r+oEC9iJNpc3bvcW7Z7iLmM26hPDmlb0mFwyANSsOQAtJxbdWsXITKOzZUyMYK0zYCv3h5yDj9TsiXg==} - fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -3953,9 +3938,6 @@ packages: resolution: {integrity: sha512-7vuh85V5cdDofPyxn58nrPjBktZo0u9x1g8WtjQol+jZDaE+fhN+cIvTj11GndBnMnyfrUOG1sZQxCdjKh+DKg==} engines: {node: '>= 10.13.0'} - jquery@3.7.1: - resolution: {integrity: sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==} - js-string-escape@1.0.1: resolution: {integrity: sha512-Smw4xcfIQ5LVjAOuJCvN/zIodzA/BBSsluuoSykP+lUvScIi4U6RJLfwHet5cxFnCswUjISV8oAXaqaJDY3chg==} engines: {node: '>= 0.8'} @@ -4882,9 +4864,6 @@ packages: resolution: {integrity: sha512-ravE6m9Atw9Z/jjttRUZ+clIXogdghyZAuWJ3qEzjT+jI/dL1ifAqhZeC5VHzQp1MSt1+jxKkFNemj/iO7tVUA==} engines: {node: '>=4'} - pretender@3.4.7: - resolution: {integrity: sha512-jkPAvt1BfRi0RKamweJdEcnjkeu7Es8yix3bJ+KgBC5VpG/Ln4JE3hYN6vJym4qprm8Xo5adhWpm3HCoft1dOw==} - prettier-linter-helpers@1.0.0: resolution: {integrity: sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==} engines: {node: '>=6.0.0'} @@ -5211,9 +5190,6 @@ packages: engines: {node: '>=10.0.0'} hasBin: true - route-recognizer@0.3.4: - resolution: {integrity: sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g==} - rsvp@3.2.1: resolution: {integrity: sha512-Rf4YVNYpKjZ6ASAmibcwTNciQ5Co5Ztq6iZPEykHpkoflnD/K5ryE/rHehFsTm4NJj8nKDhbi3eKBWGogmNnkg==} @@ -7140,16 +7116,6 @@ snapshots: '@ember/edition-utils@1.2.0': {} - '@ember/jquery@2.0.0': - dependencies: - broccoli-funnel: 3.0.8 - broccoli-merge-trees: 4.2.0 - ember-cli-babel: 7.26.11 - jquery: 3.7.1 - resolve: 1.22.8 - transitivePeerDependencies: - - supports-color - '@ember/optional-features@2.1.0': dependencies: chalk: 4.1.2 @@ -7167,7 +7133,7 @@ snapshots: transitivePeerDependencies: - supports-color - '@ember/test-helpers@file:../addon(@babel/core@7.25.2)(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0))': + '@ember/test-helpers@file:../addon(@babel/core@7.25.2)': dependencies: '@ember/test-waiters': 3.1.0 '@embroider/addon-shim': 1.8.9 @@ -7175,7 +7141,6 @@ snapshots: '@simple-dom/interface': 1.4.0 decorator-transforms: 2.0.0(@babel/core@7.25.2) dom-element-descriptors: 0.5.1 - ember-source: 4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0) transitivePeerDependencies: - '@babel/core' - '@glint/template' @@ -9843,9 +9808,9 @@ snapshots: transitivePeerDependencies: - supports-color - ember-qunit@8.1.0(@ember/test-helpers@file:../addon(@babel/core@7.25.2)(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0)))(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0))(qunit@2.22.0): + ember-qunit@8.1.0(@ember/test-helpers@file:../addon(@babel/core@7.25.2))(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0))(qunit@2.22.0): dependencies: - '@ember/test-helpers': file:../addon(@babel/core@7.25.2)(ember-source@4.12.4(@babel/core@7.25.2)(@glimmer/component@1.1.2(@babel/core@7.25.2))(webpack@5.94.0)) + '@ember/test-helpers': file:../addon(@babel/core@7.25.2) '@embroider/addon-shim': 1.8.9 '@embroider/macros': 1.16.10 ember-cli-test-loader: 3.1.0 @@ -10426,8 +10391,6 @@ snapshots: extract-stack@2.0.0: {} - fake-xml-http-request@2.1.2: {} - fast-deep-equal@3.1.3: {} fast-diff@1.3.0: {} @@ -11372,8 +11335,6 @@ snapshots: merge-stream: 2.0.0 supports-color: 8.1.1 - jquery@3.7.1: {} - js-string-escape@1.0.1: {} js-tokens@4.0.0: {} @@ -12262,11 +12223,6 @@ snapshots: prepend-http@2.0.0: {} - pretender@3.4.7: - dependencies: - fake-xml-http-request: 2.1.2 - route-recognizer: 0.3.4 - prettier-linter-helpers@1.0.0: dependencies: fast-diff: 1.3.0 @@ -12601,8 +12557,6 @@ snapshots: optionalDependencies: fsevents: 2.3.3 - route-recognizer@0.3.4: {} - rsvp@3.2.1: {} rsvp@3.6.2: {} diff --git a/test-app/tests/helpers/ajax.js b/test-app/tests/helpers/ajax.js deleted file mode 100644 index 9273fdcdb..000000000 --- a/test-app/tests/helpers/ajax.js +++ /dev/null @@ -1,22 +0,0 @@ -/* globals jQuery */ -import { Promise } from 'rsvp'; -import hasjQuery from '../helpers/has-jquery'; -import require from 'require'; -import { join } from '@ember/runloop'; - -export default function ajax(url) { - if (hasjQuery()) { - return new Promise((resolve, reject) => { - jQuery.ajax(url, { - success: resolve, - error(reason) { - join(null, reject, reason); - }, - cache: false, - }); - }); - } else { - let fetch = require('fetch').default; - return fetch(url).then((response) => response.text()); - } -} diff --git a/test-app/tests/helpers/has-jquery.js b/test-app/tests/helpers/has-jquery.js deleted file mode 100644 index 3b9c29c3c..000000000 --- a/test-app/tests/helpers/has-jquery.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function () { - return !!self.jQuery; -} diff --git a/test-app/tests/integration/settled-test.js b/test-app/tests/integration/settled-test.js index 38410a75f..5d2f37582 100644 --- a/test-app/tests/integration/settled-test.js +++ b/test-app/tests/integration/settled-test.js @@ -1,4 +1,4 @@ -import { later, run } from '@ember/runloop'; +import { later } from '@ember/runloop'; import { registerWaiter, unregisterWaiter } from '@ember/test'; import Component from '@ember/component'; import { @@ -15,8 +15,6 @@ import { import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { module, test } from 'qunit'; import { hbs } from 'ember-cli-htmlbars'; -import Pretender from 'pretender'; -import ajax from '../helpers/ajax'; const TestComponent1 = Component.extend({ layout: hbs`{{this.internalValue}}`, @@ -40,48 +38,6 @@ const TestComponent2 = Component.extend({ }, }); -const TestComponent3 = Component.extend({ - layout: hbs`
{{this.internalValue}}
`, - - internalValue: '', - - click() { - ajax('/whazzits').then((data) => { - let value = this.get('internalValue'); - - run(this, 'set', 'internalValue', value + data); - }); - }, -}); - -const TestComponent4 = Component.extend({ - layout: hbs`
{{this.internalValue}}
`, - - internalValue: '', - - click() { - later(() => run(this, 'set', 'internalValue', 'Local Data!'), 10); - - ajax('/whazzits').then((data) => { - let value = this.get('internalValue'); - - run(this, 'set', 'internalValue', value + data); - - later(() => { - ajax('/whazzits').then((data) => { - if (this.isDestroyed) { - return; - } - - let value = this.get('internalValue'); - - run(this, 'set', 'internalValue', value + data); - }); - }, 15); - }); - }, -}); - const TestComponent5 = Component.extend({ layout: hbs`{{this.internalValue}}`, @@ -118,23 +74,10 @@ module('settled real-world scenarios', function (hooks) { hooks.beforeEach(async function () { await setupContext(this); await setupRenderingContext(this); - - this.server = new Pretender(function () { - this.get( - '/whazzits', - function () { - return [200, { 'Content-Type': 'text/plain' }, 'Remote Data!']; - }, - 25 - ); - }); }); hooks.afterEach(async function () { await settled(); - - this.server.shutdown(); - await teardownContext(this); }); @@ -188,29 +131,6 @@ module('settled real-world scenarios', function (hooks) { assert.equal(this.element.textContent, 'async value'); }); - test('it waits for AJAX requests to finish', async function (assert) { - this.owner.register('component:x-test-3', TestComponent3); - - await render(hbs`{{x-test-3}}`); - - await click('.test-component'); - - assert.equal(this.element.textContent, 'Remote Data!'); - }); - - test('it waits for interleaved AJAX and run loops to finish', async function (assert) { - this.owner.register('component:x-test-4', TestComponent4); - - await render(hbs`{{x-test-4}}`); - - await click('.test-component'); - - assert.equal( - this.element.textContent, - 'Local Data!Remote Data!Remote Data!' - ); - }); - test('it waits for Ember test waiters', async function (assert) { this.owner.register('component:x-test-5', TestComponent5); diff --git a/test-app/tests/integration/setup-rendering-context-test.js b/test-app/tests/integration/setup-rendering-context-test.js index d59dd3fbd..a606a37e3 100644 --- a/test-app/tests/integration/setup-rendering-context-test.js +++ b/test-app/tests/integration/setup-rendering-context-test.js @@ -94,7 +94,7 @@ module('setupRenderingContext "real world"', function (hooks) { let deferred = defer(); this.set('promise', deferred.promise); - // force the waiter to pause, emulating a pending AJAX or fetch request + // force the waiter to pause, emulating a pending fetch request this.isWaiterPending = true; // Does not use `await` intentionally diff --git a/test-app/tests/unit/settled-test.js b/test-app/tests/unit/settled-test.js index a29b508f1..bc6cfa41c 100644 --- a/test-app/tests/unit/settled-test.js +++ b/test-app/tests/unit/settled-test.js @@ -4,15 +4,8 @@ import { isSettled, getSettledState } from '@ember/test-helpers'; import { macroCondition, dependencySatisfies } from '@embroider/macros'; 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'; @@ -22,8 +15,6 @@ module('settled', function (hooks) { } hooks.beforeEach(function (assert) { - _setupAJAXHooks(); - this.confirmSettles = (done) => { return function () { setTimeout(() => { @@ -55,16 +46,6 @@ module('settled', function (hooks) { }; }; - this.server = new Pretender(function () { - this.get( - '/whazzits', - function () { - return [200, { 'Content-Type': 'text/plain' }, 'Remote Data!']; - }, - 25 - ); - }); - this._legacyWaiter = () => { return !this.isWaiterPending; }; @@ -77,8 +58,6 @@ module('settled', function (hooks) { hooks.afterEach(function () { unregisterWaiter(this._legacyWaiter); resetWaiters(); - this.server.shutdown(); - _teardownAJAXHooks(); }); module('isSettled', function () { @@ -133,18 +112,6 @@ module('settled', function (hooks) { assert.strictEqual(isSettled(), true, 'post cond'); }); - test('when AJAX requests are pending', function (assert) { - assert.expect(4); - - let done = assert.async(); - - assert.strictEqual(isSettled(), true, 'precond'); - - ajax('/whazzits').then(this.confirmSettles(done)); - - assert.strictEqual(isSettled(), false); - }); - test('when legacy waiters are pending', function (assert) { assert.expect(3); @@ -308,59 +275,6 @@ module('settled', function (hooks) { assert.strictEqual(isSettled(), true, 'post cond'); }); - test('when AJAX requests are pending', function (assert) { - assert.expect(4); - - let done = assert.async(); - - assert.strictEqual(isSettled(), true, 'precond'); - - ajax('/whazzits').then(this.confirmSettles(done)); - - /* - When testing without jQuery `ajax` is provided by ember-fetch which uses a test waiter - to ensure tests wait for pending `fetch` requests, but under jQuery.ajax we use global - ajax start/stop timers - */ - if (hasjQuery()) { - assert.deepEqual(getSettledState(), { - hasPendingRequests: true, - hasPendingTimers: false, - hasPendingWaiters: false, - hasPendingTransitions: null, - hasRunLoop: false, - pendingRequestCount: 1, - isRenderPending: false, - debugInfo: new TestDebugInfo({ - hasPendingTimers: false, - hasRunLoop: false, - hasPendingLegacyWaiters: false, - hasPendingTestWaiters: false, - hasPendingRequests: true, - isRenderPending: false, - }), - }); - } else { - assert.deepEqual(getSettledState(), { - hasPendingRequests: false, - hasPendingTimers: false, - hasPendingWaiters: true, - hasPendingTransitions: null, - hasRunLoop: false, - isRenderPending: false, - pendingRequestCount: 0, - debugInfo: new TestDebugInfo({ - hasPendingTimers: false, - hasRunLoop: false, - hasPendingLegacyWaiters: true, - hasPendingTestWaiters: false, - hasPendingRequests: false, - isRenderPending: false, - }), - }); - } - }); - test('when legacy waiters are pending', function (assert) { assert.expect(3); diff --git a/test-app/tests/unit/teardown-context-test.js b/test-app/tests/unit/teardown-context-test.js index 122d3aad5..5829eb6e5 100644 --- a/test-app/tests/unit/teardown-context-test.js +++ b/test-app/tests/unit/teardown-context-test.js @@ -4,7 +4,6 @@ import { getContext, setupContext, teardownContext, - getSettledState, settled, isSettled, } from '@ember/test-helpers'; @@ -12,9 +11,6 @@ import { setResolverRegistry } from '../helpers/resolver'; import hasEmberVersion from '@ember/test-helpers/has-ember-version'; import { isTesting } from '@ember/debug'; -import hasjQuery from '../helpers/has-jquery'; -import ajax from '../helpers/ajax'; -import Pretender from 'pretender'; import setupManualTestWaiter from '../helpers/manual-test-waiter'; module('teardownContext', function (hooks) { @@ -26,7 +22,6 @@ module('teardownContext', function (hooks) { let context; hooks.beforeEach(function () { - this.pretender = new Pretender(); setResolverRegistry({ 'service:foo': Service.extend({ isFoo: true }), }); @@ -34,10 +29,6 @@ module('teardownContext', function (hooks) { return setupContext(context); }); - hooks.afterEach(function () { - this.pretender.shutdown(); - }); - test('it destroys any instances created', async function (assert) { let instance = context.owner.lookup('service:foo'); assert.notOk(instance.isDestroyed, 'precond - not destroyed'); @@ -89,28 +80,6 @@ module('teardownContext', function (hooks) { ); }); - if (hasjQuery()) { - test('out of balance xhr semaphores are cleaned up on teardown', async function (assert) { - this.pretender.unhandledRequest = function (/* verb, path, request */) { - throw new Error( - `Synchronous error from Pretender.prototype.unhandledRequest` - ); - }; - - ajax('/some/totally/invalid/url'); - - await teardownContext(context); - - let state = getSettledState(); - assert.equal( - state.hasPendingRequests, - false, - 'hasPendingRequests is false' - ); - assert.equal(state.pendingRequestCount, 0, 'pendingRequestCount is 0'); - }); - } - test('can opt out of waiting for settledness', async function (assert) { this.shouldWait = true; diff --git a/test-app/tests/unit/test-debug-info-test.js b/test-app/tests/unit/test-debug-info-test.js index 557f8d58e..348484476 100644 --- a/test-app/tests/unit/test-debug-info-test.js +++ b/test-app/tests/unit/test-debug-info-test.js @@ -146,7 +146,7 @@ STACK` ); }); - test('toConsole correctly prints AJAX information', function (assert) { + test('toConsole correctly prints pending requests information', function (assert) { assert.expect(1); let mockConsole = new MockConsole(); @@ -161,7 +161,7 @@ STACK` testDebugInfo.toConsole(mockConsole); - assert.deepEqual(mockConsole.toString(), `Pending AJAX requests`); + assert.deepEqual(mockConsole.toString(), `Pending requests`); }); test('toConsole correctly prints pending legacy test waiter information', function (assert) {