From ffc29cd237613507e915c7cf9972ef8dd3b16453 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 29 Jul 2016 20:23:47 -0700 Subject: [PATCH] Expose `Ember.ApplicationInstance.setupRegistry` for tooling. Glimmer requires that a number of factories and injections added by `ApplicationInstance#setupRegistry` are present, but the testing harness only has access to calling `Ember.Application.buildRegistry` which leaves the registry in a partially populated state. This exposes `Ember.ApplicationInstance.setupRegistry` so that `ember-test-helpers` can ensure that its registry is properly populated. --- .../lib/system/application-instance.js | 40 ++++++++++++------- .../tests/system/application_instance_test.js | 13 ++++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/packages/ember-application/lib/system/application-instance.js b/packages/ember-application/lib/system/application-instance.js index 76c835802ba..7cc466585a5 100644 --- a/packages/ember-application/lib/system/application-instance.js +++ b/packages/ember-application/lib/system/application-instance.js @@ -131,21 +131,7 @@ const ApplicationInstance = EngineInstance.extend({ }, setupRegistry(options) { - let registry = this.__registry__; - - registry.register('-environment:main', options.toEnvironment(), { instantiate: false }); - registry.injection('view', '_environment', '-environment:main'); - registry.injection('route', '_environment', '-environment:main'); - - registry.register('service:-document', options.document, { instantiate: false }); - - if (options.isInteractive) { - registry.injection('view', 'renderer', 'renderer:-dom'); - registry.injection('component', 'renderer', 'renderer:-dom'); - } else { - registry.injection('view', 'renderer', 'renderer:-inert'); - registry.injection('component', 'renderer', 'renderer:-inert'); - } + this.constructor.setupRegistry(this.__registry__, options); }, router: computed(function() { @@ -288,6 +274,30 @@ const ApplicationInstance = EngineInstance.extend({ } }); +ApplicationInstance.reopenClass({ + /** + @private + @method setupRegistry + @param {Registry} registry + @param {BootOptions} options + */ + setupRegistry(registry, options = new BootOptions()) { + registry.register('-environment:main', options.toEnvironment(), { instantiate: false }); + registry.injection('view', '_environment', '-environment:main'); + registry.injection('route', '_environment', '-environment:main'); + + registry.register('service:-document', options.document, { instantiate: false }); + + if (options.isInteractive) { + registry.injection('view', 'renderer', 'renderer:-dom'); + registry.injection('component', 'renderer', 'renderer:-dom'); + } else { + registry.injection('view', 'renderer', 'renderer:-inert'); + registry.injection('component', 'renderer', 'renderer:-inert'); + } + } +}); + /** A list of boot-time configuration options for customizing the behavior of an `Ember.ApplicationInstance`. diff --git a/packages/ember-application/tests/system/application_instance_test.js b/packages/ember-application/tests/system/application_instance_test.js index cb41a85f2e7..4d05d71fd4f 100644 --- a/packages/ember-application/tests/system/application_instance_test.js +++ b/packages/ember-application/tests/system/application_instance_test.js @@ -6,6 +6,7 @@ import jQuery from 'ember-views/system/jquery'; import factory from 'container/tests/test-helpers/factory'; import isEnabled from 'ember-metal/features'; import { privatize as P } from 'container/registry'; +import EmberObject from 'ember-runtime/system/object'; let application, appInstance; @@ -179,4 +180,16 @@ if (isEnabled('ember-application-engines')) { }); }); }); + + QUnit.test('can build a registry via Ember.ApplicationInstance.setupRegistry() -- simulates ember-test-helpers', function(assert) { + let namespace = EmberObject.create({ + Resolver: { create: function() { } } + }); + + let registry = Application.buildRegistry(namespace); + + ApplicationInstance.setupRegistry(registry); + + assert.equal(registry.resolve('service:-document'), document); + }); }