<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Ember</title>
    <link rel="stylesheet" href="../qunit/qunit.css">
    <style type="text/css">
      #qunit-tests.hideskipped li.skipped {
        display: none;
      }
    </style>
    <script src="../qunit/qunit.js"></script>
    <script src="/testem.js"></script>

    <script type="text/javascript">
      window.loadScript = function(url) {
        document.write(unescape('%3Cscript src="'+url+'"%3E%3C/script%3E'));
      };
    </script>

    <script type="text/javascript">
      // Load custom version of jQuery if possible (assign to window so IE8 can use in later blocks)
      var jQueryVersion = QUnit.urlParams.jquery;
      if (jQueryVersion && jQueryVersion !== 'none') {
        loadScript('https://code.jquery.com/jquery-'+jQueryVersion+'.js');
      }
      // Close the script tag to make sure document.write happens
    </script>

    <script type="text/javascript">
      // Fallback to default jQuery
      if (jQueryVersion !== 'none' && !window.jQuery) {
        loadScript('../jquery/jquery.js');
      }
      // Close the script tag to make sure document.write happens
    </script>

    <script>
      (function() {
        window.ENV = window.ENV || {};

        window.printTestCounts = function() {
          var passing = $("li[id^='qunit-'].pass").length;
          var failing = $("li[id^='qunit-'].fail").length;
          var total = passing + failing;

          console.table([{ passing: passing, failing: failing, total: total }], ["passing", "failing", "total"]);
        }

        window.findPassingSkippedTests = function() {
          console.log($("li[id^='qunit-'].pass:contains(SKIPPED)").map(function() { return $("strong", this).text() }).toArray().join("\n"));
        };

        // Test for "hooks in ENV.EMBER_LOAD_HOOKS['hookName'] get executed"
        ENV.EMBER_LOAD_HOOKS = ENV.EMBER_LOAD_HOOKS || {};
        ENV.EMBER_LOAD_HOOKS.__before_ember_test_hook__ = ENV.EMBER_LOAD_HOOKS.__before_ember_test_hook__ || [];
        ENV.__test_hook_count__ = 0;
        ENV.EMBER_LOAD_HOOKS.__before_ember_test_hook__.push(function(object) {
          ENV.__test_hook_count__ += object;
        });


        // Handle extending prototypes
        ENV['EXTEND_PROTOTYPES'] = !!QUnit.urlParams.extendprototypes;

        // Handle testing feature flags
        if (QUnit.urlParams.enableoptionalfeatures) {
          ENV.ENABLE_OPTIONAL_FEATURES = true;
        }

        ENV['RAISE_ON_DEPRECATION'] = true;
      })();
    </script>

    <script>
      var dist = QUnit.urlParams.dist;
      var legacy = QUnit.urlParams.legacy;

      var relativePath = legacy ? '../legacy' : '..';

      switch (dist) {
        case 'prod':
        case 'min':
          loadScript(relativePath + '/ember.' + dist + '.js');
          break;
        case 'es':
          loadScript(relativePath + '/ember-all.debug.js');
          break;
        default:
          loadScript(relativePath + '/ember.debug.js');
          break;
      }
    </script>

    <script type="text/javascript">
      var setTesting = Ember.__loader.require('@ember/debug')['setTesting'];
      setTesting(true);
    </script>

    <script>
      var dist = QUnit.urlParams.dist;
      var legacy = QUnit.urlParams.legacy;

      var relativePath = legacy ? '../legacy' : '..';

      if (dist === 'es') {
        // do nothing template compiler already included
      } else {
        loadScript(relativePath + '/ember-template-compiler.js');
      }
    </script>

    <script>
      var prod = QUnit.urlParams.prod;
      var dist = QUnit.urlParams.dist;
      var legacy = QUnit.urlParams.legacy;

      var relativePath = legacy ? '../legacy' : '..';

      if (dist === 'es') {
        // do nothing, tests are included
      } else if (prod) {
        loadScript(relativePath + '/ember-tests.prod.js');
      } else {
        loadScript(relativePath + '/ember-tests.js');
      }
    </script>

    <script>
      (function() {
        if (QUnit.urlParams.forceskip) {
          QUnit.skip = function(string, callback) {
            string = "SKIPPED: " + string;
            return QUnit.test(string, callback);
          };
        } else {
          var skip = QUnit.skip;
          QUnit.skip = function(string, callback) {
            string = "SKIPPED: " + string;
            return skip(string, callback);
          }
        }

        window.EmberDev = window.EmberDev || {};
        EmberDev.runningProdBuild = !!QUnit.urlParams.prod;

        var EmberDevTestHelperAssert = window.Ember.__loader.require('internal-test-helpers/lib/ember-dev/index')['default'];
        var setupQUnit = window.Ember.__loader.require('internal-test-helpers/lib/ember-dev/setup-qunit')['default'];
        var debugModule = window.Ember.__loader.require('@ember/debug');
        var testHelpers = new EmberDevTestHelperAssert({
          Ember: window.Ember,
          runningProdBuild: EmberDev.runningProdBuild,
          getDebugFunction: debugModule.getDebugFunction,
          setDebugFunction: debugModule.setDebugFunction
        });
        setupQUnit(testHelpers);

        // Tests should time out after 15 seconds
        QUnit.config.testTimeout = QUnit.urlParams.timeout ? parseInt(QUnit.urlParams.timeout, 10) : 15000;
        // Hide skipped tests
        QUnit.config.urlConfig.push({ id: 'hideskipped', label: "Hide skipped tests"});
        // Handle testing feature flags
        QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', label: "Enable Opt Features"});
        // Handle extending prototypes
        QUnit.config.urlConfig.push({ id: 'extendprototypes', label: 'Extend Prototypes'});
        // Enable/disable livereload
        QUnit.config.urlConfig.push({ id: 'livereload', label: 'Live Reload'});
        // Handle JSHint
        QUnit.config.urlConfig.push({ id: 'nolint', label: 'Skip ESLint'});
        QUnit.config.urlConfig.push('forceskip');

        if (QUnit.config.seed) {
          QUnit.config.reorder = false;
        }

        var testsTotal, testsPassed, testsFailed;

        QUnit.begin(function() {
          testsTotal = testsPassed = testsFailed = 0;

          if (QUnit.urlParams.hideskipped) {
            $('#qunit-tests').addClass('hideskipped');
          }
        });

        // work around https://github.com/qunitjs/qunit/issues/1224
        QUnit.testStart(function() {
          var existingFixture = document.getElementById('qunit-fixture');

          // create a new pristine fixture element
          var newFixture = document.createElement('div');
          newFixture.setAttribute('id', 'qunit-fixture');

          // replace the old (possibly mutated fixture) with the new pristine one
          existingFixture.parentNode.replaceChild(newFixture, existingFixture);
        });

        QUnit.testDone(function(results) {
          // release the test callback (polyfill for https://github.com/qunitjs/qunit/pull/1279)
          QUnit.config.current.callback = undefined;

          var oldFixture = document.getElementById('qunit-fixture');
          var parent = oldFixture.parentElement;
          var newFixture = document.createElement('div');
          newFixture.id = 'qunit-fixture';
          parent.replaceChild(newFixture, oldFixture);

          testsTotal++;

          if (results.failed) {
            testsFailed++;
          } else {
            testsPassed++;
          }
        });

        QUnit.moduleDone(function() {
          // release the module hooks (polyfill for https://github.com/qunitjs/qunit/pull/1279)
          QUnit.config.current.module.hooks = {};
        });

        QUnit.done(function(result) {
            console.log('\n' + 'Took ' + result.runtime + 'ms to run ' + testsTotal + ' tests. ' + testsPassed + ' passed, ' + testsFailed + ' failed.');
        });
      })();
    </script>

    <script>
      var packages     = QUnit.urlParams.package;
      packages = (packages && packages.split(',')) || [".*"];
      var packageRegexp   = new RegExp('^('+packages.join('|')+')/');

      var skipPackages = QUnit.urlParams.skipPackage;
      skipPackages = (skipPackages && skipPackages.split(',')) || [];
      var skipPackageRegexp   = new RegExp('^('+skipPackages.join('|')+')/');

      for (var moduleName in Ember.__loader.registry) {
        if (!moduleName.match(packageRegexp))   { continue; }
        if (moduleName.match(skipPackageRegexp)) { continue; }
        if (QUnit.urlParams.nolint && moduleName.match(/lint-test$/)) { continue; }

        if (moduleName.match(/[_-]test$/)) { Ember.__loader.require(moduleName); }
      }
    </script>

    <script>
      if (QUnit.urlParams.livereload) {
        (function() {
          var src = (location.protocol || 'http:') + '//' + (location.hostname || 'localhost') + ':' + (parseInt(location.port, 10) + 31529) + '/livereload.js?snipver=1';
          var script    = document.createElement('script');
          script.type   = 'text/javascript';
          script.src    = src;
          document.getElementsByTagName('head')[0].appendChild(script);
        }());
      }
    </script>

  </head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>
</body>
</html>