Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure jQuery.ajax pending request detection works with Ember 3.27 under Embroider #1047

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions addon-test-support/@ember/test-helpers/settled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { _backburner } from '@ember/runloop';
import Ember from 'ember';

import EmberApplicationInstance from '@ember/application/instance';

import { nextTick } from './-utils';
import waitUntil from './wait-until';
import { hasPendingTransitions } from './setup-application-context';
Expand Down Expand Up @@ -30,6 +32,32 @@ const _internalPendingRequests = (() => {
return () => 0;
})();

if (typeof jQuery !== 'undefined' && _internalPendingRequests) {
// This exists to ensure that the AJAX listeners setup by Ember itself
// (which as of 2.17 are not properly torn down) get cleared and released
// when the application is destroyed. Without this, any AJAX requests
// that happen _between_ acceptance tests will always share
// `pendingRequests`.
//
// This can be removed once Ember 4.0.0 is released
EmberApplicationInstance.reopen({
willDestroy(...args: any[]) {
const internalPendingRequests = _internalPendingRequests();

if (internalPendingRequests === 0) {
return;
}

jQuery(document).off('ajaxSend', internalPendingRequests.incrementPendingRequests);
jQuery(document).off('ajaxComplete', internalPendingRequests.decrementPendingRequests);

internalPendingRequests.clearPendingRequests();

this._super(...args);
},
});
}

let requests: XMLHttpRequest[];

/**
Expand Down
6 changes: 0 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ const debugTree = BroccoliDebug.buildDebugCallback('ember-test-helpers');
module.exports = {
name: require('./package').name,

included() {
this._super.included.apply(this, arguments);

this.import('vendor/monkey-patches.js', { type: 'test' });
},

treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
Expand Down
39 changes: 0 additions & 39 deletions vendor/monkey-patches.js

This file was deleted.