Skip to content

Commit

Permalink
Merge pull request #14 from ember-cli/allow-additional-matchers
Browse files Browse the repository at this point in the history
Allow additional matchers to be added without monkey patching prototype.
  • Loading branch information
rwjblue committed Sep 11, 2015
2 parents 6a09220 + eecfbc1 commit 683c3d8
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 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 @@ -54,8 +83,10 @@ define("ember-cli/test-loader",
};

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

0 comments on commit 683c3d8

Please sign in to comment.