diff --git a/lib/getDefinePropertySrc.js b/lib/getDefinePropertySrc.js index 3094f4e..71964be 100644 --- a/lib/getDefinePropertySrc.js +++ b/lib/getDefinePropertySrc.js @@ -11,9 +11,8 @@ var srcs = { }; function getDefinePropertySrc() { - var src = "if ((typeof(module.exports) === 'function' || \n" + - "typeof(module.exports) === 'object') &&\n"+ - "Object.isExtensible(module.exports)) {\n"; + var src = "if (typeof(module.exports) === 'function' || \n" + + "typeof(module.exports) === 'object') {\n"; src += Object.keys(srcs).reduce(function forEachSrc(preValue, value) { return preValue += "Object.defineProperty(module.exports, '" + diff --git a/test/testModules/sealedObject.js b/test/testModules/sealedObject.js new file mode 100644 index 0000000..f053ebf --- /dev/null +++ b/test/testModules/sealedObject.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/test/testModules/sharedTestCases.js b/test/testModules/sharedTestCases.js index 72f1409..242f881 100644 --- a/test/testModules/sharedTestCases.js +++ b/test/testModules/sharedTestCases.js @@ -226,6 +226,12 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + }).to.not.throwException(); }); + it("should not be a problem to have a module that exports a sealed object", function() { + expect(function() { + var rewired = rewire("./sealedObject.js"); + }).to.not.throwException(); + }); + it("should not influence the original require if nothing has been required within the rewired module", function () { rewire("./emptyModule.js"); // nothing happens here because emptyModule doesn't require anything expect(require("./moduleA.js").__set__).to.be(undefined); // if restoring the original node require didn't worked, the module would have a setter