Skip to content

Commit e9bc60c

Browse files
authored
Merge pull request #1537 from emberjs/nvp/resolve-deprecations-barrel
Resolve deprecations from ember barrel file
2 parents eaf7294 + 5b784f2 commit e9bc60c

20 files changed

Lines changed: 98 additions & 182 deletions

addon/src/-internal/-owner-mixin-imports.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

addon/src/-internal/build-registry.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ import type { Resolver } from '@ember/owner';
22
import ApplicationInstance from '@ember/application/instance';
33
import Application from '@ember/application';
44
import EmberObject from '@ember/object';
5-
6-
import Ember from 'ember';
5+
import { Registry } from '@ember/-internals/container';
6+
import { ComponentLookup } from '@ember/-internals/views';
77

88
import type { FullName } from '@ember/owner';
99

10-
// These shenanigans work around the fact that the import locations are not
11-
// public API and are not stable, so we jump through hoops to get the right
12-
// types and values to use.
1310
import {
1411
ContainerProxyMixin,
1512
RegistryProxyMixin,
16-
} from './-owner-mixin-imports.ts';
13+
} from '@ember/-internals/runtime';
1714

1815
/**
1916
* Adds methods that are normally only on registry to the container. This is largely to support the legacy APIs
@@ -102,10 +99,9 @@ export default function buildRegistry(resolver: Resolver) {
10299
const fallbackRegistry = Application.buildRegistry(namespace);
103100
// TODO: only do this on Ember < 3.13
104101
// @ts-ignore: this is private API.
105-
fallbackRegistry.register('component-lookup:main', Ember.ComponentLookup);
102+
fallbackRegistry.register('component-lookup:main', ComponentLookup);
106103

107-
// @ts-ignore: this is private API.
108-
const registry = new Ember.Registry({
104+
const registry = new Registry({
109105
fallback: fallbackRegistry,
110106
});
111107

addon/src/setup-context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { setOwner } from '@ember/application';
99
import buildOwner, { type Owner } from './build-owner.ts';
1010
import { _setupAJAXHooks } from './settled.ts';
1111
import { _prepareOnerror } from './setup-onerror.ts';
12-
import Ember from 'ember';
12+
import { setTesting } from '@ember/debug';
1313
import {
1414
assert,
1515
registerDeprecationHandler,
@@ -379,7 +379,7 @@ export default function setupContext<T extends object>(
379379
const context = base as T & TestContext;
380380

381381
// SAFETY: this is intimate API *designed* for us to override.
382-
(Ember as any).testing = true;
382+
setTesting(true);
383383
setContext(context);
384384

385385
const testMetadata = getTestMetadata(context);

addon/src/setup-onerror.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Ember from 'ember';
1+
import { getOnerror, setOnerror } from '@ember/-internals/error-handling';
22
import { type BaseContext, getContext } from './setup-context.ts';
33

44
const cachedOnerror: Map<BaseContext, ((error: Error) => void) | undefined> =
@@ -39,7 +39,7 @@ export default function setupOnerror(onError?: (error: Error) => void): void {
3939
onError = cachedOnerror.get(context);
4040
}
4141

42-
Ember.onerror = onError;
42+
setOnerror(onError);
4343
}
4444

4545
/**
@@ -60,7 +60,7 @@ export function resetOnerror(): void {
6060
const context = getContext();
6161

6262
if (context && cachedOnerror.has(context)) {
63-
Ember.onerror = cachedOnerror.get(context);
63+
setOnerror(cachedOnerror.get(context));
6464
}
6565
}
6666

@@ -76,7 +76,8 @@ export function _prepareOnerror(context: BaseContext) {
7676
throw new Error('_prepareOnerror should only be called once per-context');
7777
}
7878

79-
cachedOnerror.set(context, Ember.onerror);
79+
// SAFETY: getOnerror doesn't have correct types
80+
cachedOnerror.set(context, getOnerror() as any);
8081
}
8182

8283
/**

addon/src/setup-rendering-context.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { run } from '@ember/runloop';
2-
import Ember from 'ember';
2+
import { EventDispatcher } from '@ember/-internals/views';
33
import global from './global.ts';
44
import {
55
type BaseContext,
@@ -265,9 +265,8 @@ export default function setupRenderingContext(
265265
// manually start the event dispatcher.
266266
if (owner._emberTestHelpersMockOwner) {
267267
const dispatcher =
268-
owner.lookup('event_dispatcher:main') ||
269-
(Ember.EventDispatcher as any).create();
270-
dispatcher.setup({}, '#ember-testing');
268+
owner.lookup('event_dispatcher:main') || EventDispatcher.create();
269+
(dispatcher as any).setup({}, '#ember-testing');
271270
}
272271

273272
const OutletView = owner.factoryFor

addon/src/teardown-context.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { TestContext } from './setup-context';
2-
import Ember from 'ember';
2+
import { setTesting } from '@ember/debug';
33
import { unsetContext } from './setup-context.ts';
44
import settled, { _teardownAJAXHooks } from './settled.ts';
55
import { _cleanupOnerror } from './setup-onerror.ts';
@@ -31,14 +31,10 @@ export default function teardownContext(
3131
return Promise.resolve()
3232
.then(() => {
3333
_cleanupOnerror(context);
34-
3534
_teardownAJAXHooks();
3635

37-
// SAFETY: this is intimate API *designed* for us to override.
38-
(Ember as any).testing = false;
39-
36+
setTesting(false);
4037
unsetContext();
41-
4238
destroy(context.owner);
4339
})
4440
.finally(() => {

addon/src/validate-error-handler.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import Ember from 'ember';
1+
// Private API
2+
import { getOnerror } from '@ember/-internals/error-handling';
3+
// Private API
4+
import { isTesting, setTesting } from '@ember/debug';
25

36
type ErrorHandlerValidation =
47
| Readonly<{ isValid: true; message: null }>
@@ -34,24 +37,24 @@ const INVALID = Object.freeze({
3437
* });
3538
*/
3639
export default function validateErrorHandler(
37-
callback = Ember.onerror,
40+
callback = getOnerror(),
3841
): ErrorHandlerValidation {
3942
if (callback === undefined || callback === null) {
4043
return VALID;
4144
}
4245

4346
const error = new Error('Error handler validation error!');
4447

45-
const originalEmberTesting = Ember.testing;
46-
(Ember as any).testing = true;
48+
const originalEmberTesting = isTesting();
49+
setTesting(true);
4750
try {
4851
callback(error);
4952
} catch (e) {
5053
if (e === error) {
5154
return VALID;
5255
}
5356
} finally {
54-
(Ember as any).testing = originalEmberTesting;
57+
setTesting(originalEmberTesting);
5558
}
5659

5760
return INVALID;

test-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"pretender": "^3.4.7",
7171
"prettier": "^2.8.7",
7272
"qunit": "^2.21.1",
73+
"qunit-console-grouper": "^0.3.0",
7374
"qunit-dom": "^3.2.0",
7475
"tracked-built-ins": "^3.1.1",
7576
"webpack": "^5.78.0"

test-app/pnpm-lock.yaml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-app/tests/helpers/module-for-acceptance.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { resolve } from 'rsvp';
2+
import { setTesting } from '@ember/debug';
23
import { module } from 'qunit';
34
import startApp from '../helpers/start-app';
45
import destroyApp from '../helpers/destroy-app';
56
import { setResolverRegistry } from './resolver';
67
import QUnitTestAdapter from './qunit-test-adapter';
7-
import Ember from 'ember';
8+
import { setAdapter } from 'ember-testing/lib/setup_for_testing';
89

910
export default function (name, options = {}) {
1011
module(name, {
1112
beforeEach() {
12-
Ember.Test.adapter = QUnitTestAdapter.create();
13+
setAdapter(QUnitTestAdapter.create());
1314

1415
if (options.registry) {
1516
setResolverRegistry(options.registry);
@@ -20,7 +21,7 @@ export default function (name, options = {}) {
2021
);
2122
this.fixtureResetValue = testElementContainer.innerHTML;
2223

23-
Ember.testing = true;
24+
setTesting(true);
2425
this.application = startApp();
2526

2627
if (options.beforeEach) {
@@ -34,7 +35,7 @@ export default function (name, options = {}) {
3435
return resolve(afterEach)
3536
.then(() => destroyApp(this.application))
3637
.finally(() => {
37-
Ember.testing = false;
38+
setTesting(false);
3839

3940
document.getElementById('ember-testing-container').innerHTML =
4041
this.fixtureResetValue;

0 commit comments

Comments
 (0)