Skip to content

Commit

Permalink
[Bugfix release] Ensure jQuery “monkey patch” are included via modules.
Browse files Browse the repository at this point in the history
This both tidies up the code, but also ensures embroider compatibility
For those users with ember 2.27.x but still have jQuery
  • Loading branch information
stefanpenner committed Jun 14, 2021
1 parent 16118c3 commit 5c18add
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 45 deletions.
27 changes: 27 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,31 @@ 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.

0 comments on commit 5c18add

Please sign in to comment.