diff --git a/addon-test-support/-private/patch-test-loader.js b/addon-test-support/-private/patch-test-loader.js index 7c5d5870c..b950f9b21 100644 --- a/addon-test-support/-private/patch-test-loader.js +++ b/addon-test-support/-private/patch-test-loader.js @@ -3,44 +3,4 @@ import splitTestModules from './split-test-modules'; export default function patchTestLoader(TestLoader) { TestLoader._urlParams = getUrlParams(); - - const _super = { - require: TestLoader.prototype.require, - unsee: TestLoader.prototype.unsee, - loadModules: TestLoader.prototype.loadModules, - }; - - // "Require" the module by adding it to the array of test modules to load - TestLoader.prototype.require = function _emberExamRequire(name) { - this._testModules.push(name); - }; - - // Make unsee a no-op to avoid any unwanted resets - TestLoader.prototype.unsee = function _emberExamUnsee() {}; - - TestLoader.prototype.loadModules = function _emberExamLoadModules() { - const urlParams = TestLoader._urlParams; - let partitions = urlParams._partition; - let split = parseInt(urlParams._split, 10); - - split = isNaN(split) ? 1 : split; - - if (partitions === undefined) { - partitions = [1]; - } else if (!Array.isArray(partitions)) { - partitions = [partitions]; - } - - const testLoader = this; - - testLoader._testModules = []; - _super.loadModules.apply(testLoader, arguments); - - const splitModules = splitTestModules(testLoader._testModules, split, partitions); - - splitModules.forEach((moduleName) => { - _super.require.call(testLoader, moduleName); - _super.unsee.call(testLoader, moduleName); - }); - }; } diff --git a/addon-test-support/load.js b/addon-test-support/load.js index d3f08d59c..67eed982c 100644 --- a/addon-test-support/load.js +++ b/addon-test-support/load.js @@ -1,6 +1,8 @@ import getTestLoader from './-private/get-test-loader'; -import patchTestLoader from './-private/patch-test-loader'; import patchTestemOutput from './-private/patch-testem-output'; +import patchTestLoader from './-private/patch-test-loader'; +import qunit from 'qunit'; +import { loadTests, start as qunitStart } from 'ember-cli-qunit'; let loaded = false; @@ -23,3 +25,41 @@ export default function loadEmberExam() { return LOAD_SUCCESS; } + +export function start() { + loadTests(); + + let urlParams = qunit.urlParams; + let totalPartitions = parseInt(urlParams._split) || 1; + let partitions = urlParams._partition; + + if (partitions === undefined) { + partitions = [1]; + } else if (!Array.isArray(partitions)) { + partitions = [partitions]; + } + + partitions = partitions.map(function(num) { + return +num; + }); + + if (totalPartitions > 0) { + let testIds = qunit.config.modules.reduce(function(tests, m) { + return tests.concat(m.tests); + }, []).map(function(test) { return test.testId }).sort(); + + qunit.config.testId = []; + for (let i = 0; i < testIds.length; ++i) { + let testPartition = (i % totalPartitions) + 1; + if (partitions.includes(testPartition)) { + qunit.config.testId.push(testIds[i]); + } + } + + // refill the queue + qunit.config.queue = []; + loadTests(); + } + + qunitStart({ loadTests: false }); +}