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

[CLEANUP] Change resolver function deprecations in to assert #15911

Merged
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
13 changes: 11 additions & 2 deletions packages/container/lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { assert, deprecate } from 'ember-debug';
import { EMBER_MODULE_UNIFICATION } from 'ember/features';
import Container from './container';
import { DEBUG } from 'ember-env-flags';
import { ENV } from 'ember-environment';

const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
let missingResolverFunctionsDeprecation = 'Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.';

/**
A registry used to store factory and option information keyed
Expand All @@ -24,7 +26,14 @@ export default class Registry {
this.fallback = options.fallback || null;
this.resolver = options.resolver || null;

if (typeof this.resolver === 'function') {
Copy link
Member

Choose a reason for hiding this comment

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

I think we are going to have to put an ENV guard around this. Here is an example of how I just did a similar thing.

Copy link
Member

Choose a reason for hiding this comment

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

Also here is an example of adding the config to ember-2-legacy

Copy link
Author

@gowthamrm gowthamrm Dec 1, 2017

Choose a reason for hiding this comment

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

@thoov @rwjblue I have updated the PR with the ENV guard and created a PR in ember-2-legacy to update the config with the ENV.

Please have a look.

if (ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT !== true) {
assert(
missingResolverFunctionsDeprecation,
typeof this.resolver !== 'function'
);
}

if (typeof this.resolver === 'function' && ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT === true) {
deprecateResolverFunction(this);
}

Expand Down Expand Up @@ -604,7 +613,7 @@ export default class Registry {

function deprecateResolverFunction(registry) {
deprecate(
'Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.',
missingResolverFunctionsDeprecation,
false,
{ id: 'ember-application.registry-resolver-as-function', until: '3.0.0', url: 'https://emberjs.com/deprecations/v2.x#toc_registry-resolver-as-function' }
);
Expand Down
38 changes: 34 additions & 4 deletions packages/container/tests/registry_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { Registry, privatize } from '..';
import { factory } from 'internal-test-helpers';
import { EMBER_MODULE_UNIFICATION } from 'ember/features';
import { ENV } from 'ember-environment';

QUnit.module('Registry');
let originalResolverFunctionSupport;

QUnit.module('Registry', {
setup() {
originalResolverFunctionSupport = ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT;
ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT = true;
},

teardown() {
ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT = originalResolverFunctionSupport;
}
});

QUnit.test('A registered factory is returned from resolve', function() {
let registry = new Registry();
Expand Down Expand Up @@ -473,8 +485,10 @@ QUnit.test('`knownForType` is called on the resolver if present', function() {
});
});

QUnit.test('A registry can be created with a deprecated `resolver` function instead of an object', function() {
expect(2);
QUnit.test('A registry created with `resolver` function instead of an object throws deprecation', (assert) => {
assert.expect(2);

ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT = true;

let registry;

Expand All @@ -486,7 +500,23 @@ QUnit.test('A registry can be created with a deprecated `resolver` function inst
});
}, 'Passing a `resolver` function into a Registry is deprecated. Please pass in a Resolver object with a `resolve` method.');

equal(registry.resolve('foo:bar'), 'foo:bar-resolved', '`resolve` still calls the deprecated function');
assert.equal(registry.resolve('foo:bar'), 'foo:bar-resolved', '`resolve` still calls the deprecated function');
});

QUnit.test('A registry created with `resolver` function instead of an object throws assertion', (assert) => {
assert.expect(1);

ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT = false;

let registry;

expectAssertion(() => {
registry = new Registry({
resolver(fullName) {
return `${fullName}-resolved`;
}
});
}, /Passing a \`resolver\` function into a Registry is deprecated\. Please pass in a Resolver object with a \`resolve\` method\./);
});

QUnit.test('resolver.expandLocalLookup is not required', function(assert) {
Expand Down