Skip to content
Open
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
9 changes: 9 additions & 0 deletions addon/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ let __application__: Application | undefined;
export function setApplication(application: Application): void {
__application__ = application;

/**
* For RFC#1132, the strict resolver is not accessible.
* It is closed off from extension.
*
* SAFETY: modules is a new API, so older Application
* types will not have it.
*/
if ((application as any)?.modules) return;

if (!getResolver()) {
const Resolver = (application as any).Resolver;
const resolver = Resolver.create({ namespace: application });
Expand Down
1 change: 1 addition & 0 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"ember-resolver": "^13.1.0",
"ember-source": "~5.12.0",
"ember-source-channel-url": "^3.0.0",
"ember-strict-application-resolver": "^0.1.1",
"ember-template-lint": "^5.7.2",
"ember-try": "^3.0.0",
"eslint": "^8.37.0",
Expand Down
14 changes: 14 additions & 0 deletions test-app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions test-app/tests/unit/application-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Application from '@ember/application';
import { module, test } from 'qunit';
import { application, resolver } from '../helpers/resolver';
import ApplicationPolyfill from 'ember-strict-application-resolver';
import {
getApplication,
setApplication,
Expand All @@ -18,6 +20,43 @@ module('application', function (hooks) {
setResolver(resolver);
});

test('RFC#1132: calling set application does not set resolver if the application has modules = {}', function (assert) {
class App extends Application {
modules = {};

// TODO: This isn't needed once we upgrade to
// a new enough ember that supports this.
// But to support the implementation PR, @ember/test-helpers
// needs to be compatible with modules = {} first for the smoke tests
// to pass in https://github.com/emberjs/ember.js/pull/21303
//
// Once the above PR lands, we'll want to wrap this test in a macroCondition
buildRegistry() {}
}

setApplication(
App.create({ autoboot: false, rootElement: '#ember-testing' })
);

let actualResolver = getResolver();
assert.notOk(actualResolver, 'there is no resolver');
assert.deepEqual(getApplication().constructor, App);
});

test('RFC#1132 (polyfilled): calling set application does not set resolver if the application has modules = {}', function (assert) {
class App extends ApplicationPolyfill {
modules = {};
}

setApplication(
App.create({ autoboot: false, rootElement: '#ember-testing' })
);

let actualResolver = getResolver();
assert.notOk(actualResolver, 'there is no resolver');
assert.deepEqual(getApplication().constructor, App);
});

test('calling setApplication sets resolver when resolver is unset', function (assert) {
setApplication(application);

Expand Down
Loading