Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/testModules/moduleB.js')
-rw-r--r--test/testModules/moduleB.js82
1 files changed, 65 insertions, 17 deletions
diff --git a/test/testModules/moduleB.js b/test/testModules/moduleB.js
index 6e655ab..b7646bd 100644
--- a/test/testModules/moduleB.js
+++ b/test/testModules/moduleB.js
@@ -28,21 +28,67 @@ function readFileSync() {
}
function checkSomeGlobals() {
- if (typeof global === "undefined") {
- throw new ReferenceError("global is undefined");
+ if (typeof global !== "object") {
+ throw new ReferenceError("global is not an object");
}
- if (typeof console === "undefined") {
- throw new ReferenceError("console is undefined");
+ if (typeof console !== "object") {
+ throw new ReferenceError("console is not an object");
}
- if (typeof __filename === "undefined") {
- throw new ReferenceError("__filename is undefined");
+ if (typeof require !== "function") {
+ throw new ReferenceError("require is not a function");
}
- if (typeof __dirname === "undefined") {
- throw new ReferenceError("__dirname is undefined");
+ if (typeof module !== "object") {
+ throw new ReferenceError("module is not an object");
}
+ if (typeof exports !== "object") {
+ throw new ReferenceError("exports is not an object");
+ }
+ if (module.exports === exports) {
+ throw new Error("module.exports === exports returns true"); // should be false because we're setting module.exports at the bottom of this file
+ }
+ if (typeof __dirname !== "string") {
+ throw new ReferenceError("__dirname is not a string");
+ }
+ if (typeof __filename !== "string") {
+ throw new ReferenceError("__filename is not a string");
+ }
+ //TODO add accurate checks here
if (typeof setTimeout === "undefined") {
throw new ReferenceError("setTimeout is undefined");
}
+ if (typeof clearTimeout === "undefined") {
+ throw new ReferenceError("clearTimeout is undefined");
+ }
+ if (typeof setInterval === "undefined") {
+ throw new ReferenceError("setInterval is undefined");
+ }
+ if (typeof clearInterval === "undefined") {
+ throw new ReferenceError("clearInterval is undefined");
+ }
+ if (typeof Error === "undefined") {
+ throw new ReferenceError("Error is undefined");
+ }
+ if (typeof parseFloat === "undefined") {
+ throw new ReferenceError("parseFloat is undefined");
+ }
+ if (typeof parseInt === "undefined") {
+ throw new ReferenceError("parseInt is undefined");
+ }
+ if (typeof window === "undefined") {
+ if (typeof process === "undefined") {
+ throw new ReferenceError("process is undefined");
+ }
+ if (typeof Buffer === "undefined") {
+ throw new ReferenceError("Buffer is undefined");
+ }
+ } else {
+ if (typeof encodeURIComponent === "undefined") {
+ throw new ReferenceError("encodeURIComponent is undefined");
+ }
+ if (typeof decodeURIComponent === "undefined") {
+ throw new ReferenceError("decodeURIComponent is undefined");
+ }
+ }
}
function getConsole() {
@@ -54,12 +100,14 @@ function getFilename() {
}
// different styles of exports in moduleA.js and moduleB.js
-exports.setMyNumber = setMyNumber;
-exports.getMyNumber = getMyNumber;
-exports.setMyObj = setMyObj;
-exports.getMyObj = getMyObj;
-exports.readFileSync = readFileSync;
-exports.checkSomeGlobals = checkSomeGlobals;
-exports.getConsole = getConsole;
-exports.getFilename = getFilename;
-exports.someOtherModule = someOtherModule; \ No newline at end of file
+module.exports = {
+ setMyNumber: setMyNumber,
+ getMyNumber: getMyNumber,
+ setMyObj: setMyObj,
+ getMyObj: getMyObj,
+ readFileSync: readFileSync,
+ checkSomeGlobals: checkSomeGlobals,
+ getConsole: getConsole,
+ getFilename: getFilename,
+ someOtherModule: someOtherModule
+};