Skip to content

Commit

Permalink
unsee test modules after requiring them. This allows the modules to b…
Browse files Browse the repository at this point in the history
…e released, garbage collected and makes for a happier heap snapshot.

@cibernox & @stefanpenner
  • Loading branch information
stefanpenner committed Aug 4, 2015
1 parent 1965a22 commit 2fca180
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ define("ember-cli/test-loader",
"use strict";

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

TestLoader.prototype = {
shouldLoadModule: function(moduleName) {
return moduleName.match(/\/.*[-_]test$/);
return (moduleName.match(/[-_]test$/));
},

loadModules: function() {
Expand All @@ -19,6 +20,7 @@ define("ember-cli/test-loader",
for (moduleName in requirejs.entries) {
if (this.shouldLoadModule(moduleName)) {
this.require(moduleName);
this.unsee(moduleName);
}
}
}
Expand All @@ -32,6 +34,17 @@ define("ember-cli/test-loader",
}
};

TestLoader.prototype.unsee = function(moduleName) {
if (typeof require.unsee === 'function') {
require.unsee(moduleName);
} else if (!this._didLogMissingUnsee) {
this._didLogMissingUnsee = true;
if (typeof console !== 'undefined') {
console.warn('unable to require.unsee, please upgrade loader.js to >= v3.3.0');
}
}
};

TestLoader.prototype.moduleLoadFailure = function(moduleName, error) {
console.error('Error loading: ' + moduleName, error.stack);
};
Expand Down

0 comments on commit 2fca180

Please sign in to comment.