2
2
// "provides" this public API, but does not for earlier versions. As a result,
3
3
// this type will be `any`.
4
4
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 ' ;
8
8
9
9
import { nextTick } from './-utils.ts' ;
10
10
import waitUntil from './wait-until.ts' ;
@@ -13,68 +13,6 @@ import { hasPendingWaiters } from '@ember/test-waiters';
13
13
import type DebugInfo from './-internal/debug-info.ts' ;
14
14
import { TestDebugInfo } from './-internal/debug-info.ts' ;
15
15
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
-
78
16
let requests : XMLHttpRequest [ ] ;
79
17
80
18
/**
@@ -167,44 +105,6 @@ export function _setupAJAXHooks() {
167
105
. on ( 'ajaxComplete' , decrementAjaxPendingRequests ) ;
168
106
}
169
107
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
-
208
108
export interface SettledState {
209
109
hasRunLoop : boolean ;
210
110
hasPendingTimers : boolean ;
0 commit comments