Skip to content

Commit

Permalink
Expose Ember.ApplicationInstance.setupRegistry for tooling.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Robert Jackson committed Jul 30, 2016
1 parent 031915a commit ffc29cd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
40 changes: 25 additions & 15 deletions packages/ember-application/lib/system/application-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
});
}

0 comments on commit ffc29cd

Please sign in to comment.