Skip to content

Commit 38b7720

Browse files
Merge pull request #1486 from emberjs/re-enable-embroider-optimized-testing
Remove old code that existed for now unsupported ember-sources (2.4, etc)
2 parents 1885813 + 1ca8f4c commit 38b7720

File tree

10 files changed

+1816
-2372
lines changed

10 files changed

+1816
-2372
lines changed

.github/workflows/ci-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
- ember-canary
106106
- ember-default
107107
- embroider-safe
108-
# - embroider-optimized # see comments in ember-try.js
108+
- embroider-optimized
109109

110110
steps:
111111
- uses: actions/checkout@v4

addon/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@
101101
"externals": [
102102
"@glimmer/manager",
103103
"@ember/-internals",
104-
"@ember/renderer"
104+
"@ember/renderer",
105+
"ember-testing"
105106
]
107+
},
108+
"volta": {
109+
"extends": "../package.json"
106110
}
107111
}

addon/pnpm-lock.yaml

+419-482
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addon/src/settled.ts

+3-103
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// "provides" this public API, but does not for earlier versions. As a result,
33
// this type will be `any`.
44
import { _backburner } from '@ember/runloop';
5-
import Ember from 'ember';
6-
7-
import EmberApplicationInstance from '@ember/application/instance';
5+
import { Test } from 'ember-testing';
6+
export const checkWaiters = Test.checkWaiters;
7+
import { pendingRequests as _internalGetPendingRequestsCount } from 'ember-testing/lib/test/pending_requests';
88

99
import { nextTick } from './-utils.ts';
1010
import waitUntil from './wait-until.ts';
@@ -13,68 +13,6 @@ import { hasPendingWaiters } from '@ember/test-waiters';
1313
import type DebugInfo from './-internal/debug-info.ts';
1414
import { TestDebugInfo } from './-internal/debug-info.ts';
1515

16-
// Ember internally tracks AJAX requests in the same way that we do here for
17-
// legacy style "acceptance" tests using the `ember-testing.js` asset provided
18-
// by emberjs/ember.js itself. When `@ember/test-helpers`'s `settled` utility
19-
// is used in a legacy acceptance test context any pending AJAX requests are
20-
// not properly considered during the `isSettled` check below.
21-
//
22-
// This utilizes a local utility method present in Ember since around 2.8.0 to
23-
// properly consider pending AJAX requests done within legacy acceptance tests.
24-
const _internalPendingRequestsModule = (() => {
25-
const loader = (Ember as any).__loader;
26-
27-
if (loader.registry['ember-testing/test/pending_requests']) {
28-
// Ember <= 3.1
29-
return loader.require('ember-testing/test/pending_requests');
30-
} else if (loader.registry['ember-testing/lib/test/pending_requests']) {
31-
// Ember >= 3.2
32-
return loader.require('ember-testing/lib/test/pending_requests');
33-
}
34-
35-
return null;
36-
})();
37-
38-
const _internalGetPendingRequestsCount = () => {
39-
if (_internalPendingRequestsModule) {
40-
return _internalPendingRequestsModule.pendingRequests();
41-
}
42-
return 0;
43-
};
44-
45-
if (
46-
typeof (globalThis as any).jQuery !== 'undefined' &&
47-
_internalPendingRequestsModule
48-
) {
49-
// This exists to ensure that the AJAX listeners setup by Ember itself
50-
// (which as of 2.17 are not properly torn down) get cleared and released
51-
// when the application is destroyed. Without this, any AJAX requests
52-
// that happen _between_ acceptance tests will always share
53-
// `pendingRequests`.
54-
//
55-
// This can be removed once Ember 4.0.0 is released
56-
EmberApplicationInstance.reopen({
57-
willDestroy(this: EmberApplicationInstance, ...args: any[]) {
58-
(globalThis as any)
59-
.jQuery(document)
60-
.off(
61-
'ajaxSend',
62-
_internalPendingRequestsModule.incrementPendingRequests,
63-
);
64-
(globalThis as any)
65-
.jQuery(document)
66-
.off(
67-
'ajaxComplete',
68-
_internalPendingRequestsModule.decrementPendingRequests,
69-
);
70-
71-
_internalPendingRequestsModule.clearPendingRequests();
72-
73-
this._super(...args);
74-
},
75-
});
76-
}
77-
7816
let requests: XMLHttpRequest[];
7917

8018
/**
@@ -167,44 +105,6 @@ export function _setupAJAXHooks() {
167105
.on('ajaxComplete', decrementAjaxPendingRequests);
168106
}
169107

170-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
171-
let _internalCheckWaiters: Function;
172-
173-
const loader = (Ember as any).__loader;
174-
if (loader.registry['ember-testing/test/waiters']) {
175-
// Ember <= 3.1
176-
_internalCheckWaiters = loader.require(
177-
'ember-testing/test/waiters',
178-
).checkWaiters;
179-
} else if (loader.registry['ember-testing/lib/test/waiters']) {
180-
// Ember >= 3.2
181-
_internalCheckWaiters = loader.require(
182-
'ember-testing/lib/test/waiters',
183-
).checkWaiters;
184-
}
185-
186-
/**
187-
@private
188-
@returns {boolean} true if waiters are still pending
189-
*/
190-
function checkWaiters() {
191-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
192-
type Waiter = [any, Function];
193-
const EmberTest = Ember.Test as any as { waiters: Array<Waiter> };
194-
195-
if (_internalCheckWaiters) {
196-
return _internalCheckWaiters();
197-
} else if (EmberTest.waiters) {
198-
if (
199-
EmberTest.waiters.some(([context, callback]) => !callback.call(context))
200-
) {
201-
return true;
202-
}
203-
}
204-
205-
return false;
206-
}
207-
208108
export interface SettledState {
209109
hasRunLoop: boolean;
210110
hasPendingTimers: boolean;

0 commit comments

Comments
 (0)