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

Remove old code that existed for now unsupported ember-sources (2.4, etc) #1486

Merged
merged 10 commits into from
Sep 3, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
- ember-canary
- ember-default
- embroider-safe
# - embroider-optimized # see comments in ember-try.js
- embroider-optimized

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 5 additions & 1 deletion addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
"externals": [
"@glimmer/manager",
"@ember/-internals",
"@ember/renderer"
"@ember/renderer",
"ember-testing"
]
},
"volta": {
"extends": "../package.json"
}
}
901 changes: 419 additions & 482 deletions addon/pnpm-lock.yaml

Large diffs are not rendered by default.

106 changes: 3 additions & 103 deletions addon/src/settled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// "provides" this public API, but does not for earlier versions. As a result,
// this type will be `any`.
import { _backburner } from '@ember/runloop';
import Ember from 'ember';

import EmberApplicationInstance from '@ember/application/instance';
import { Test } from 'ember-testing';
export const checkWaiters = Test.checkWaiters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being exported? This seems to have caused a type regression, see #1502

Copy link
Sponsor Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great question -- I had originally thought that the original implementation was exported -- but I see in this diff that it is not. let's see if not exporting it resolves that issue

import { pendingRequests as _internalGetPendingRequestsCount } from 'ember-testing/lib/test/pending_requests';

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

// Ember internally tracks AJAX requests in the same way that we do here for
// legacy style "acceptance" tests using the `ember-testing.js` asset provided
// by emberjs/ember.js itself. When `@ember/test-helpers`'s `settled` utility
// is used in a legacy acceptance test context any pending AJAX requests are
// not properly considered during the `isSettled` check below.
//
// This utilizes a local utility method present in Ember since around 2.8.0 to
// properly consider pending AJAX requests done within legacy acceptance tests.
const _internalPendingRequestsModule = (() => {
const loader = (Ember as any).__loader;

if (loader.registry['ember-testing/test/pending_requests']) {
// Ember <= 3.1
return loader.require('ember-testing/test/pending_requests');
} else if (loader.registry['ember-testing/lib/test/pending_requests']) {
// Ember >= 3.2
return loader.require('ember-testing/lib/test/pending_requests');
}

return null;
})();

const _internalGetPendingRequestsCount = () => {
if (_internalPendingRequestsModule) {
return _internalPendingRequestsModule.pendingRequests();
}
return 0;
};

if (
typeof (globalThis as any).jQuery !== 'undefined' &&
_internalPendingRequestsModule
) {
// 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(this: EmberApplicationInstance, ...args: any[]) {
(globalThis as any)
.jQuery(document)
.off(
'ajaxSend',
_internalPendingRequestsModule.incrementPendingRequests,
);
(globalThis as any)
.jQuery(document)
.off(
'ajaxComplete',
_internalPendingRequestsModule.decrementPendingRequests,
);

_internalPendingRequestsModule.clearPendingRequests();

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

let requests: XMLHttpRequest[];

/**
Expand Down Expand Up @@ -167,44 +105,6 @@ export function _setupAJAXHooks() {
.on('ajaxComplete', decrementAjaxPendingRequests);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
let _internalCheckWaiters: Function;

const loader = (Ember as any).__loader;
if (loader.registry['ember-testing/test/waiters']) {
// Ember <= 3.1
_internalCheckWaiters = loader.require(
'ember-testing/test/waiters',
).checkWaiters;
} else if (loader.registry['ember-testing/lib/test/waiters']) {
// Ember >= 3.2
_internalCheckWaiters = loader.require(
'ember-testing/lib/test/waiters',
).checkWaiters;
}

/**
@private
@returns {boolean} true if waiters are still pending
*/
function checkWaiters() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
type Waiter = [any, Function];
const EmberTest = Ember.Test as any as { waiters: Array<Waiter> };

if (_internalCheckWaiters) {
return _internalCheckWaiters();
} else if (EmberTest.waiters) {
if (
EmberTest.waiters.some(([context, callback]) => !callback.call(context))
) {
return true;
}
}

return false;
}

export interface SettledState {
hasRunLoop: boolean;
hasPendingTimers: boolean;
Expand Down
Loading