Mock modules properly in test runner

As an added bonus, the jasmine web interface now groups tests by file.

Test Plan:
grunt test passes on b2507066, the parent of 566f8b2e (which committed a workaround for buggy module mocking).
This commit is contained in:
Ben Alpert committed 2013-11-21 00:39:37 -08:00
1 parent b2507066b6
commit c7bb3af760
2 files changed
+32 -1

No files matched your search

+10 -1
View File
@@ -10,7 +10,16 @@ require("mock-modules");
require("./mock-timers");
exports.enableTest = function(testID) {
require("../" + testID);
describe(testID, function() {
var mockMap;
beforeEach(function() {
require("mock-modules").setMockMap(mockMap);
});
require("mock-modules").clearMockMap();
require("../" + testID);
mockMap = require("mock-modules").getMockMap();
});
};
exports.removeNextSiblings = function(node) {
+22
View File
@@ -73,6 +73,28 @@ exports.dumpCache = function() {
return exports;
};
exports.getMockMap = function() {
return explicitMockMap;
};
exports.clearMockMap = function() {
explicitMockMap = {};
};
exports.setMockMap = function(mockMap) {
exports.dumpCache();
exports.clearMockMap();
for (var id in mockMap) {
if (mockMap[id]) {
doMock(id);
} else {
doNotMock(id);
}
}
return exports;
};
// Call this function to ensure that require(id) returns the actual
// exports object created by the module.
function doNotMock(id) {