Skip to content

Commit

Permalink
Allow additional matchers to be added without monkey patching prototype.
Browse files Browse the repository at this point in the history
Currently, `TestLoader.prototype.shouldLoadModule` is monkey patched by
ember-cli-qunit / ember-cli-mocha to add their own custom rules for
matching modules.

This change allows additional addons to add their own custom matchers
(for example adding additional extension types) or to suppress a certain
subset of modules (for example JSHint or JSCS tests).
  • Loading branch information
rwjblue committed Sep 10, 2015
1 parent 6a09220 commit ba78280
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions test-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,32 @@ define("ember-cli/test-loader",
function() {
"use strict";

var TestLoader = function() {
var moduleIncludeMatchers = [];
var moduleExcludeMatchers = [];

function addModuleIncludeMatcher(fn) {
moduleIncludeMatchers.push(fn);
};

function addModuleExcludeMatcher(fn) {
moduleExcludeMatchers.push(fn);
};

function checkMatchers(matchers, moduleName) {
var matcher;

for (var i = 0, l = matchers.length; i < l; i++) {
matcher = matchers[i];

if (matcher(moduleName)) {
return true;
}
}

return false;
}

function TestLoader() {
this._didLogMissingUnsee = false;
};

Expand All @@ -18,7 +43,11 @@ define("ember-cli/test-loader",
var moduleName;

for (moduleName in requirejs.entries) {
if (this.shouldLoadModule(moduleName)) {
if (!checkMatchers(moduleExcludeMatchers, moduleName)) {
continue;
}

if (checkMatchers(moduleIncludeMatchers, moduleName) || this.shouldLoadModule(moduleName)) {
this.require(moduleName);
this.unsee(moduleName);
}
Expand Down Expand Up @@ -53,9 +82,14 @@ define("ember-cli/test-loader",
new TestLoader().loadModules();
};

TestLoader.addModuleIncludeMatcher = addModuleIncludeMatcher;
TestLoader.addModuleExcludeMatcher = addModuleExcludeMatcher;

return {
'default': TestLoader
}
'default': TestLoader,
addModuleIncludeMatcher: addModuleIncludeMatcher,
addModuleExcludeMatcher: addModuleExcludeMatcher
};
}
);
})();

0 comments on commit ba78280

Please sign in to comment.