text: define('ember-test-helpers/test-module', ['exports', 'ember-test-helpers/abstract-test-module', 'ember-test-helpers/test-resolver', 'ember-test-helpers/build-registry', 'ember-test-helpers/has-ember-version'], function (exports, _abstractTestModule, _testResolver, _buildRegistry, _hasEmberVersion) {
    'use strict';
  
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
  
    var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
      return typeof obj;
    } : function (obj) {
      return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
    };
  
    function _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }
  
    var _createClass = function () {
      function defineProperties(target, props) {
        for (var i = 0; i < props.length; i++) {
          var descriptor = props[i];
          descriptor.enumerable = descriptor.enumerable || false;
          descriptor.configurable = true;
          if ("value" in descriptor) descriptor.writable = true;
          Object.defineProperty(target, descriptor.key, descriptor);
        }
      }
  
      return function (Constructor, protoProps, staticProps) {
        if (protoProps) defineProperties(Constructor.prototype, protoProps);
        if (staticProps) defineProperties(Constructor, staticProps);
        return Constructor;
      };
    }();
  
    function _possibleConstructorReturn(self, call) {
      if (!self) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }
  
      return call && (typeof call === "object" || typeof call === "function") ? call : self;
    }
  
    var _get = function get(object, property, receiver) {
      if (object === null) object = Function.prototype;
      var desc = Object.getOwnPropertyDescriptor(object, property);
  
      if (desc === undefined) {
        var parent = Object.getPrototypeOf(object);
  
        if (parent === null) {
          return undefined;
        } else {
          return get(parent, property, receiver);
        }
      } else if ("value" in desc) {
        return desc.value;
      } else {
        var getter = desc.get;
  
        if (getter === undefined) {
          return undefined;
        }
  
        return getter.call(receiver);
      }
    };
  
    function _inherits(subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
      }
  
      subClass.prototype = Object.create(superClass && superClass.prototype, {
        constructor: {
          value: subClass,
          enumerable: false,
          writable: true,
          configurable: true
        }
      });
      if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
    }
  
    var _class = function (_AbstractTestModule) {
      _inherits(_class, _AbstractTestModule);
  
      function _class(subjectName, description, callbacks) {
        _classCallCheck(this, _class);
  
        // Allow `description` to be omitted, in which case it should
        // default to `subjectName`
        if (!callbacks && (typeof description === 'undefined' ? 'undefined' : _typeof(description)) === 'object') {
          callbacks = description;
          description = subjectName;
        }
  
        var _this2 = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this, description || subjectName, callbacks));
  
        _this2.subjectName = subjectName;
        _this2.description = description || subjectName;
        _this2.resolver = _this2.callbacks.resolver || (0, _testResolver.getResolver)();
  
        if (_this2.callbacks.integration && _this2.callbacks.needs) {
          throw new Error("cannot declare 'integration: true' and 'needs' in the same module");
        }
  
        if (_this2.callbacks.integration) {
          _this2.initIntegration(callbacks);
          delete callbacks.integration;
        }
  
        _this2.initSubject();
        _this2.initNeeds();
        return _this2;
      }
  
      _createClass(_class, [{
        key: 'initIntegration',
        value: function initIntegration(options) {
          if (options.integration === 'legacy') {
            throw new Error('`integration: \'legacy\'` is only valid for component tests.');
          }
          this.isIntegration = true;
        }
      }, {
        key: 'initSubject',
        value: function initSubject() {
          this.callbacks.subject = this.callbacks.subject || this.defaultSubject;
        }
      }, {
        key: 'initNeeds',
        value: function initNeeds() {
          this.needs = [this.subjectName];
          if (this.callbacks.needs) {
            this.needs = this.needs.concat(this.callbacks.needs);
            delete this.callbacks.needs;
          }
        }
      }, {
        key: 'initSetupSteps',
        value: function 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);
  
          if (this.callbacks.setup) {
            this.contextualizedSetupSteps.push(this.callbacks.setup);
            delete this.callbacks.setup;
          }
        }
      }, {
        key: 'initTeardownSteps',
        value: function initTeardownSteps() {
          this.teardownSteps = [];
          this.contextualizedTeardownSteps = [];
  
          if (this.callbacks.teardown) {
            this.contextualizedTeardownSteps.push(this.callbacks.teardown);
            delete this.callbacks.teardown;
          }
  
          this.teardownSteps.push(this.teardownSubject);
          this.teardownSteps.push(this.teardownContainer);
          this.teardownSteps.push(this.teardownContext);
          this.teardownSteps.push(this.teardownTestElements);
          this.teardownSteps.push(this.teardownAJAXListeners);
  
          if (this.callbacks.afterTeardown) {
            this.teardownSteps.push(this.callbacks.afterTeardown);
            delete this.callbacks.afterTeardown;
          }
        }
      }, {
        key: 'setupContainer',
        value: function setupContainer() {
          if (this.isIntegration || this.isLegacy) {
            this._setupIntegratedContainer();
          } else {
            this._setupIsolatedContainer();
          }
        }
      }, {
        key: 'setupContext',
        value: function setupContext() {
          var subjectName = this.subjectName;
          var container = this.container;
  
          var factory = function factory() {
            return container.factoryFor ? container.factoryFor(subjectName) : container.lookupFactory(subjectName);
          };
  
          _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'setupContext', this).call(this, {
            container: this.container,
            registry: this.registry,
            factory: factory,
            register: function register() {
              var target = this.registry || this.container;
              return target.register.apply(target, arguments);
            }
          });
  
          if (Ember.setOwner) {
            Ember.setOwner(this.context, this.container.owner);
          }
  
          this.setupInject();
        }
      }, {
        key: 'setupInject',
        value: function setupInject() {
          var module = this;
          var context = this.context;
  
          if (Ember.inject) {
            var keys = (Object.keys || Ember.keys)(Ember.inject);
  
            keys.forEach(function (typeName) {
              context.inject[typeName] = function (name, opts) {
                var alias = opts && opts.as || name;
                Ember.run(function () {
                  Ember.set(context, alias, module.container.lookup(typeName + ':' + name));
                });
              };
            });
          }
        }
      }, {
        key: 'teardownSubject',
        value: function teardownSubject() {
          var subject = this.cache.subject;
  
          if (subject) {
            Ember.run(function () {
              Ember.tryInvoke(subject, 'destroy');
            });
          }
        }
      }, {
        key: 'teardownContainer',
        value: function teardownContainer() {
          var container = this.container;
          Ember.run(function () {
            container.destroy();
          });
        }
      }, {
        key: 'defaultSubject',
        value: function defaultSubject(options, factory) {
          return factory.create(options);
        }
      }, {
        key: 'contextualizeCallbacks',
        value: function contextualizeCallbacks() {
          var callbacks = this.callbacks;
          var context = this.context;
  
          this.cache = this.cache || {};
          this.cachedCalls = this.cachedCalls || {};
  
          var keys = (Object.keys || Ember.keys)(callbacks);
          var keysLength = keys.length;
  
          if (keysLength) {
            var deprecatedContext = this._buildDeprecatedContext(this, context);
            for (var i = 0; i < keysLength; i++) {
              this._contextualizeCallback(context, keys[i], deprecatedContext);
            }
          }
        }
      }, {
        key: '_contextualizeCallback',
        value: function _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;
          };
        }
      }, {
        key: '_buildDeprecatedContext',
        value: function _buildDeprecatedContext(module, context) {
          var deprecatedContext = Object.create(context);
  
          var keysForDeprecation = Object.keys(module);
  
          for (var i = 0, l = keysForDeprecation.length; i < l; i++) {
            this._proxyDeprecation(module, deprecatedContext, keysForDeprecation[i]);
          }
  
          return deprecatedContext;
        }
      }, {
        key: '_proxyDeprecation',
        value: function _proxyDeprecation(obj, proxy, key) {
          if (typeof proxy[key] === 'undefined') {
            Object.defineProperty(proxy, key, {
              get: function get() {
                Ember.deprecate('Accessing the test module property "' + key + '" from a callback is deprecated.', false, { id: 'ember-test-helpers.test-module.callback-context', until: '0.6.0' });
                return obj[key];
              }
            });
          }
        }
      }, {
        key: '_setupContainer',
        value: function _setupContainer(isolated) {
          var resolver = this.resolver;
  
          var items = (0, _buildRegistry.default)(!isolated ? resolver : Object.create(resolver, {
            resolve: {
              value: function value() {}
            }
          }));
  
          this.container = items.container;
          this.registry = items.registry;
  
          if ((0, _hasEmberVersion.default)(1, 13)) {
            var thingToRegisterWith = this.registry || this.container;
            var router = resolver.resolve('router:main');
            router = router || Ember.Router.extend();
            thingToRegisterWith.register('router:main', router);
          }
        }
      }, {
        key: '_setupIsolatedContainer',
        value: function _setupIsolatedContainer() {
          var resolver = this.resolver;
          this._setupContainer(true);
  
          var thingToRegisterWith = this.registry || this.container;
  
          for (var i = this.needs.length; i > 0; i--) {
            var fullName = this.needs[i - 1];
            var normalizedFullName = resolver.normalize(fullName);
            thingToRegisterWith.register(fullName, resolver.resolve(normalizedFullName));
          }
  
          if (!this.registry) {
            this.container.resolver = function () {};
          }
        }
      }, {
        key: '_setupIntegratedContainer',
        value: function _setupIntegratedContainer() {
          this._setupContainer();
        }
      }]);
  
      return _class;
    }(_abstractTestModule.default);
  
    exports.default = _class;
  });