The library for web and native user interfaces.
Call require("mock-modules").register in every mockable module.
Mocking happens only when config.constants.__MOCK__ is true.
Ben Newman committed
Jul 3, 2013 at 11:37 UTC
37014e1002a0fd6bcb32f71482e231705b5bb872
3 files changed
+26
-3
bin/jsx
+19
-1
@@ -32,5 +32,23 @@ require("commoner").resolve(function(id) {
32
33
// Constant propagation means removing any obviously dead code after
34
// replacing constant expressions with literal (boolean) values.
35
- return propagate(constants, source);
35
+ source = propagate(constants, source);
36
+
37
+ if (constants.__MOCK__) {
38
+ // Make sure there is exactly one newline at the end of the module.
39
+ source = source.replace(/\s+$/m, "\n");
40
+
41
+ return context.getProvidedP().then(function(idToPath) {
42
+ if (id !== "mock-modules" &&
43
+ id !== "mocks" &&
44
+ idToPath.hasOwnProperty("mock-modules")) {
45
+ return source + '\nrequire("mock-modules").register(' +
46
+ JSON.stringify(id) + ', module);\n';
47
+ }
48
+
49
+ return source;
50
+ });
51
+ }
52
+
53
+ return source;
54
});
grunt/config/jsx/debug.json
+1
@@ -1,6 +1,7 @@
1
{
2
"debug": true,
3
"constants": {
4
+ "__MOCK__": true,
5
"__DEV__": true
6
}
7
}
src/test/mock-modules.js
+6
-2
@@ -16,8 +16,9 @@
16
* @providesModule mock-modules
17
*/
18
19
-var global = Function("return this")();
20
-require('test/mock-timers').installMockTimers(global);
19
+exports.register = function(id, module) {
20
+ // TODO
21
+};
22
23
exports.dumpCache = function() {
24
require("mocks").clear();
@@ -31,3 +32,6 @@ exports.dontMock = function() {
32
exports.mock = function() {
33
return exports;
34
};
35
+
36
+var global = Function("return this")();
37
+require('test/mock-timers').installMockTimers(global);