From fb9a71587d135f16bf764d3807faea479ae7b648 Mon Sep 17 00:00:00 2001 From: "gowtham.mk" Date: Sat, 2 Dec 2017 03:04:04 +0530 Subject: [PATCH] Change resolver function deprecations in to assert --- packages/container/lib/registry.js | 13 +++++++-- packages/container/tests/registry_test.js | 32 +++++++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packages/container/lib/registry.js b/packages/container/lib/registry.js index fd9237d347b..1e510961c29 100644 --- a/packages/container/lib/registry.js +++ b/packages/container/lib/registry.js @@ -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 @@ -24,7 +26,14 @@ export default class Registry { this.fallback = options.fallback || null; this.resolver = options.resolver || null; - if (typeof this.resolver === 'function') { + 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); } @@ -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' } ); diff --git a/packages/container/tests/registry_test.js b/packages/container/tests/registry_test.js index 2b579f8a57c..47069771dac 100644 --- a/packages/container/tests/registry_test.js +++ b/packages/container/tests/registry_test.js @@ -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(); @@ -473,9 +485,11 @@ 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() { +QUnit.test('A registry created with `resolver` function instead of an object throws deprecation', function() { expect(2); + ENV._ENABLE_RESOLVER_FUNCTION_SUPPORT = true; + let registry; expectDeprecation(() => { @@ -489,6 +503,20 @@ QUnit.test('A registry can be created with a deprecated `resolver` function inst 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', function() { + expect(1); + + let registry; + + throws(() => { + 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) { assert.expect(1);