diff --git a/packages/ember-application/lib/system/engine-instance.js b/packages/ember-application/lib/system/engine-instance.js index c480644aeb3..afce71314d2 100644 --- a/packages/ember-application/lib/system/engine-instance.js +++ b/packages/ember-application/lib/system/engine-instance.js @@ -181,9 +181,12 @@ const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixi '-view-registry:main', `renderer:-${env.isInteractive ? 'dom' : 'inert'}`, 'service:-document', - 'event_dispatcher:main' ]; + if (env.isInteractive) { + singletons.push('event_dispatcher:main'); + } + singletons.forEach(key => this.register(key, parent.lookup(key), { instantiate: false })); this.inject('view', '_environment', '-environment:main'); diff --git a/packages/ember-application/tests/system/application_instance_test.js b/packages/ember-application/tests/system/application_instance_test.js index 6995296b1f7..c427023b979 100644 --- a/packages/ember-application/tests/system/application_instance_test.js +++ b/packages/ember-application/tests/system/application_instance_test.js @@ -63,6 +63,7 @@ QUnit.test('customEvents added to the application before setupEventDispatcher', assert.expect(1); appInstance = run(() => ApplicationInstance.create({ application })); + appInstance.setupRegistry(); application.customEvents = { awesome: 'sauce' @@ -80,6 +81,7 @@ QUnit.test('customEvents added to the application before setupEventDispatcher', assert.expect(1); run(() => appInstance = ApplicationInstance.create({ application })); + appInstance.setupRegistry(); application.customEvents = { awesome: 'sauce' @@ -97,6 +99,7 @@ QUnit.test('customEvents added to the application instance before setupEventDisp assert.expect(1); appInstance = run(() => ApplicationInstance.create({ application })); + appInstance.setupRegistry(); appInstance.customEvents = { awesome: 'sauce' diff --git a/packages/ember-application/tests/system/visit_test.js b/packages/ember-application/tests/system/visit_test.js index cd66de11d6f..2ef8696d9a9 100644 --- a/packages/ember-application/tests/system/visit_test.js +++ b/packages/ember-application/tests/system/visit_test.js @@ -369,6 +369,52 @@ moduleFor('Ember.Application - visit()', class extends ApplicationTestCase { }); } + [`@test visit() does not setup the event_dispatcher:main if isInteractive is false (with Engines) GH#15615`](assert) { + assert.expect(3); + + this.router.map(function() { + this.mount('blog'); + }); + + this.addTemplate('application', '

Hello world

{{outlet}}'); + this.add('event_dispatcher:main', { + create() { throw new Error('should not happen!'); } + }); + + // Register engine + let BlogEngine = Engine.extend({ + init(...args) { + this._super.apply(this, args); + this.register('template:application', compile('{{cache-money}}')); + this.register('template:components/cache-money', compile(` +

Dis cache money

+ `)); + this.register('component:cache-money', Component.extend({})); + } + }); + this.add('engine:blog', BlogEngine); + + // Register engine route map + let BlogMap = function() {}; + this.add('route-map:blog', BlogMap); + + assert.strictEqual( + this.$('#qunit-fixture').children().length, 0, + 'there are no elements in the fixture element' + ); + + return this.visit('/blog', { isInteractive: false }).then(instance => { + assert.ok( + instance instanceof ApplicationInstance, + 'promise is resolved with an ApplicationInstance' + ); + assert.strictEqual( + this.$().find('p').text(), 'Dis cache money', + 'Engine component is resolved' + ); + }); + } + [`@test visit() on engine resolves engine component`](assert) { assert.expect(2); diff --git a/packages/ember-glimmer/tests/integration/event-dispatcher-test.js b/packages/ember-glimmer/tests/integration/event-dispatcher-test.js index 58f68169a62..d861d9ae74c 100644 --- a/packages/ember-glimmer/tests/integration/event-dispatcher-test.js +++ b/packages/ember-glimmer/tests/integration/event-dispatcher-test.js @@ -209,15 +209,6 @@ moduleFor('EventDispatcher#setup', class extends RenderingTest { this.render(`{{x-foo}}`); } - ['@test canDispatchToEventManager is deprecated in EventDispatcher'](assert) { - let MyDispatcher = EventDispatcher.extend({ - canDispatchToEventManager: null - }); - - expectDeprecation(/`canDispatchToEventManager` has been deprecated/); - MyDispatcher.create(); - } - ['@test a rootElement can be specified'](assert) { this.$().append('
'); this.dispatcher.setup({ myevent: 'myEvent' }, '#app'); @@ -260,6 +251,27 @@ moduleFor('EventDispatcher#setup', class extends RenderingTest { } }); +moduleFor('custom EventDispatcher subclass with #setup', class extends RenderingTest { + constructor() { + super(); + + let dispatcher = this.owner.lookup('event_dispatcher:main'); + run(dispatcher, 'destroy'); + this.owner.__container__.reset('event_dispatcher:main'); + this.owner.unregister('event_dispatcher:main'); + } + + ['@test canDispatchToEventManager is deprecated in EventDispatcher'](assert) { + let MyDispatcher = EventDispatcher.extend({ + canDispatchToEventManager: null + }); + this.owner.register('event_dispatcher:main', MyDispatcher); + + expectDeprecation(/`canDispatchToEventManager` has been deprecated/); + this.owner.lookup('event_dispatcher:main'); + } +}); + if (EMBER_IMPROVED_INSTRUMENTATION) { moduleFor('EventDispatcher - Instrumentation', class extends RenderingTest { teardown() { diff --git a/packages/ember-views/lib/system/event_dispatcher.js b/packages/ember-views/lib/system/event_dispatcher.js index 2a631bcbef4..c91d0031218 100644 --- a/packages/ember-views/lib/system/event_dispatcher.js +++ b/packages/ember-views/lib/system/event_dispatcher.js @@ -10,7 +10,6 @@ import { deprecate } from 'ember-debug'; import { Object as EmberObject } from 'ember-runtime'; import jQuery from './jquery'; import ActionManager from './action_manager'; -import { environment } from 'ember-environment'; import fallbackViewRegistry from '../compat/fallback-view-registry'; const ROOT_ELEMENT_CLASS = 'ember-application'; @@ -136,7 +135,13 @@ export default EmberObject.extend({ init() { this._super(); - assert('EventDispatcher should never be instantiated in fastboot mode. Please report this as an Ember bug.', environment.hasDOM); + + assert('EventDispatcher should never be instantiated in fastboot mode. Please report this as an Ember bug.', (() => { + let owner = getOwner(this); + let environment = owner.lookup('-environment:main'); + + return environment.isInteractive; + })()); deprecate( `\`canDispatchToEventManager\` has been deprecated in ${this}.`, diff --git a/packages/internal-test-helpers/lib/test-cases/abstract-rendering.js b/packages/internal-test-helpers/lib/test-cases/abstract-rendering.js index 0ccc7d65ec4..56833587425 100644 --- a/packages/internal-test-helpers/lib/test-cases/abstract-rendering.js +++ b/packages/internal-test-helpers/lib/test-cases/abstract-rendering.js @@ -12,10 +12,12 @@ const TextNode = window.Text; export default class AbstractRenderingTestCase extends AbstractTestCase { constructor() { super(); + let bootOptions = this.getBootOptions(); + let owner = this.owner = buildOwner({ ownerOptions: this.getOwnerOptions(), - bootOptions: this.getBootOptions(), - resolver: this.getResolver() + resolver: this.getResolver(), + bootOptions, }); this.renderer = this.owner.lookup('renderer:-dom'); @@ -24,7 +26,9 @@ export default class AbstractRenderingTestCase extends AbstractTestCase { owner.register('event_dispatcher:main', EventDispatcher); owner.inject('event_dispatcher:main', '_viewRegistry', '-view-registry:main'); - owner.lookup('event_dispatcher:main').setup(this.getCustomDispatcherEvents(), this.element); + if (!bootOptions || bootOptions.isInteractive !== false) { + owner.lookup('event_dispatcher:main').setup(this.getCustomDispatcherEvents(), this.element); + } } compile() {