From f990dd57cc42b8bab0054c9b7bfa5a7af5c318b3 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Mon, 9 Oct 2017 14:30:04 -0400 Subject: [PATCH] Remove `TestModuleForIntegration`. This was added in an early attempt to simplify / separate things for the "grand testing unification" RFC, but ultimately was never rolled out to folks. At this point, it has become clear that this class based system for managing test setup is not the way forward (see emberjs/rfcs#230 for details) and this module (that is unused) has just become "dead weight" maintenance wise. --- addon-test-support/index.js | 3 - .../test-module-for-integration.js | 217 ----------- .../unit/test-module-for-integration-test.js | 353 ------------------ 3 files changed, 573 deletions(-) delete mode 100644 addon-test-support/test-module-for-integration.js delete mode 100644 tests/unit/test-module-for-integration-test.js diff --git a/addon-test-support/index.js b/addon-test-support/index.js index e57e409b5..a72c921e7 100644 --- a/addon-test-support/index.js +++ b/addon-test-support/index.js @@ -2,9 +2,6 @@ export { default as TestModule } from './test-module'; export { default as TestModuleForAcceptance, } from './test-module-for-acceptance'; -export { - default as TestModuleForIntegration, -} from './test-module-for-integration'; export { default as TestModuleForComponent } from './test-module-for-component'; export { default as TestModuleForModel } from './test-module-for-model'; export { getContext, setContext, unsetContext } from './test-context'; diff --git a/addon-test-support/test-module-for-integration.js b/addon-test-support/test-module-for-integration.js deleted file mode 100644 index 5d3a7b88c..000000000 --- a/addon-test-support/test-module-for-integration.js +++ /dev/null @@ -1,217 +0,0 @@ -import { set } from '@ember/object'; -import { run } from '@ember/runloop'; -import { setOwner } from '@ember/application'; -import EmberRouter from '@ember/routing/router'; -import Ember from 'ember'; -import AbstractTestModule from './abstract-test-module'; -import { getResolver } from './test-resolver'; -import buildRegistry from './build-registry'; -import hasEmberVersion from './has-ember-version'; -import { preGlimmerSetupIntegrationForComponent } from './-legacy-overrides'; -import { setupComponentIntegrationTest } from './test-module-for-component'; - -const isPreGlimmer = !hasEmberVersion(1, 13); - -export default class extends AbstractTestModule { - constructor() { - super(...arguments); - this.resolver = this.callbacks.resolver || getResolver(); - } - - initSetupSteps() { - this.setupSteps = []; - this.contextualizedSetupSteps = []; - - if (this.callbacks.beforeSetup) { - this.setupSteps.push(this.callbacks.beforeSetup); - delete this.callbacks.beforeSetup; - } - - this.setupSteps.push(this.setupContainer); - this.setupSteps.push(this.setupContext); - this.setupSteps.push(this.setupTestElements); - this.setupSteps.push(this.setupAJAXListeners); - this.setupSteps.push(this.setupComponentIntegrationTest); - - if (Ember.View && Ember.View.views) { - this.setupSteps.push(this._aliasViewRegistry); - } - - if (this.callbacks.setup) { - this.contextualizedSetupSteps.push(this.callbacks.setup); - delete this.callbacks.setup; - } - } - - initTeardownSteps() { - this.teardownSteps = []; - this.contextualizedTeardownSteps = []; - - if (this.callbacks.teardown) { - this.contextualizedTeardownSteps.push(this.callbacks.teardown); - delete this.callbacks.teardown; - } - - this.teardownSteps.push(this.teardownContainer); - this.teardownSteps.push(this.teardownContext); - this.teardownSteps.push(this.teardownAJAXListeners); - this.teardownSteps.push(this.teardownComponent); - - if (Ember.View && Ember.View.views) { - this.teardownSteps.push(this._resetViewRegistry); - } - - this.teardownSteps.push(this.teardownTestElements); - - if (this.callbacks.afterTeardown) { - this.teardownSteps.push(this.callbacks.afterTeardown); - delete this.callbacks.afterTeardown; - } - } - - setupContainer() { - var resolver = this.resolver; - var items = buildRegistry(resolver); - - this.container = items.container; - this.registry = items.registry; - - if (hasEmberVersion(1, 13)) { - var thingToRegisterWith = this.registry || this.container; - var router = resolver.resolve('router:main'); - router = router || EmberRouter.extend(); - thingToRegisterWith.register('router:main', router); - } - } - - setupContext() { - var subjectName = this.subjectName; - var container = this.container; - - var factory = function() { - return container.factoryFor - ? container.factoryFor(subjectName) - : container.lookupFactory(subjectName); - }; - - super.setupContext({ - container: this.container, - registry: this.registry, - factory: factory, - register() { - var target = this.registry || this.container; - return target.register.apply(target, arguments); - }, - }); - - var context = this.context; - - if (setOwner) { - setOwner(context, this.container.owner); - } - - if (Ember.inject) { - var keys = (Object.keys || keys)(Ember.inject); - keys.forEach(function(typeName) { - context.inject[typeName] = function(name, opts) { - var alias = (opts && opts.as) || name; - run(function() { - set( - context, - alias, - context.container.lookup(typeName + ':' + name) - ); - }); - }; - }); - } - - // only setup the injection if we are running against a version - // of Ember that has `-view-registry:main` (Ember >= 1.12) - if ( - this.container.factoryFor - ? this.container.factoryFor('-view-registry:main') - : this.container.lookupFactory('-view-registry:main') - ) { - (this.registry || this.container).injection( - 'component', - '_viewRegistry', - '-view-registry:main' - ); - } - } - - setupComponentIntegrationTest() { - if (isPreGlimmer) { - return preGlimmerSetupIntegrationForComponent.apply(this, arguments); - } else { - return setupComponentIntegrationTest.apply(this, arguments); - } - } - - teardownComponent() { - var component = this.component; - if (component) { - run(function() { - component.destroy(); - }); - } - } - - teardownContainer() { - var container = this.container; - run(function() { - container.destroy(); - }); - } - - // allow arbitrary named factories, like rspec let - contextualizeCallbacks() { - var callbacks = this.callbacks; - var context = this.context; - - this.cache = this.cache || {}; - this.cachedCalls = this.cachedCalls || {}; - - var keys = (Object.keys || keys)(callbacks); - var keysLength = keys.length; - - if (keysLength) { - for (var i = 0; i < keysLength; i++) { - this._contextualizeCallback(context, keys[i], context); - } - } - } - - _contextualizeCallback(context, key, callbackContext) { - var _this = this; - var callbacks = this.callbacks; - var factory = context.factory; - - context[key] = function(options) { - if (_this.cachedCalls[key]) { - return _this.cache[key]; - } - - var result = callbacks[key].call(callbackContext, options, factory()); - - _this.cache[key] = result; - _this.cachedCalls[key] = true; - - return result; - }; - } - - _aliasViewRegistry() { - this._originalGlobalViewRegistry = Ember.View.views; - var viewRegistry = this.container.lookup('-view-registry:main'); - - if (viewRegistry) { - Ember.View.views = viewRegistry; - } - } - - _resetViewRegistry() { - Ember.View.views = this._originalGlobalViewRegistry; - } -} diff --git a/tests/unit/test-module-for-integration-test.js b/tests/unit/test-module-for-integration-test.js deleted file mode 100644 index 3594af46f..000000000 --- a/tests/unit/test-module-for-integration-test.js +++ /dev/null @@ -1,353 +0,0 @@ -import QUnit, { test } from 'qunit'; -import TextField from '@ember/component/text-field'; -import { on } from '@ember/object/evented'; -import Component from '@ember/component'; -import EmberObject from '@ember/object'; -import EmberService, { inject as service } from '@ember/service'; -import hasEmberVersion from 'ember-test-helpers/has-ember-version'; -import { TestModuleForIntegration } from 'ember-test-helpers'; -import { setResolverRegistry, createCustomResolver } from '../helpers/resolver'; -import qunitModuleFor from '../helpers/qunit-module-for'; -import hbs from 'htmlbars-inline-precompile'; -import { fireEvent, focus, blur } from '../helpers/events'; - -const Service = EmberService || EmberObject; - -function moduleForIntegration(description, callbacks) { - var module = new TestModuleForIntegration(description, callbacks); - qunitModuleFor(module); -} - -moduleForIntegration('Component Integration Tests', { - beforeSetup() { - setResolverRegistry({ - 'template:components/my-component': hbs`{{name}}`, - }); - }, -}); - -test('it can render a template', function(assert) { - this.render(hbs`Hello`); - let actual = this._element.querySelector('span').textContent; - assert.equal(actual, 'Hello'); -}); - -if (hasEmberVersion(1, 11)) { - test('it can render a link-to', function(assert) { - this.render(hbs`{{link-to 'Hi' 'index'}}`); - assert.ok(true, 'it renders without fail'); - }); -} - -test('it complains if you try to use bare render', function(assert) { - var self = this; - assert.throws(function() { - self.render(); - }, /in a component integration test you must pass a template to `render\(\)`/); -}); - -test('it can access the full container', function(assert) { - this.set('myColor', 'red'); - this.render(hbs`{{my-component name=myColor}}`); - - assert.equal(this._element.querySelector('span').textContent, 'red'); - this.set('myColor', 'blue'); - assert.equal(this._element.querySelector('span').textContent, 'blue'); -}); - -test('it can handle actions', function(assert) { - var handlerArg; - this.render(hbs`