From c7bb3af760d30c247b934ba5af893d119029e50b Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Thu, 21 Nov 2013 00:39:37 -0800 Subject: [PATCH 1/2] 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). --- src/test/all.js | 11 ++++++++++- src/test/mock-modules.js | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/all.js b/src/test/all.js index 3549f081b3..6f1f9d50ac 100644 --- a/src/test/all.js +++ b/src/test/all.js @@ -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) { diff --git a/src/test/mock-modules.js b/src/test/mock-modules.js index d8bd57f81a..b6fcd0fe10 100644 --- a/src/test/mock-modules.js +++ b/src/test/mock-modules.js @@ -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) { From af95b35f27a16a9e1714c5e8efd2cd79e3f56b42 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Thu, 21 Nov 2013 10:31:20 -0800 Subject: [PATCH 2/2] Have faith in var hoisting --- src/test/all.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/all.js b/src/test/all.js index 6f1f9d50ac..1d0b9f5c28 100644 --- a/src/test/all.js +++ b/src/test/all.js @@ -11,14 +11,13 @@ require("./mock-timers"); exports.enableTest = function(testID) { describe(testID, function() { - var mockMap; beforeEach(function() { require("mock-modules").setMockMap(mockMap); }); require("mock-modules").clearMockMap(); require("../" + testID); - mockMap = require("mock-modules").getMockMap(); + var mockMap = require("mock-modules").getMockMap(); }); };