File tree Expand file tree Collapse file tree 5 files changed +29
-2
lines changed Expand file tree Collapse file tree 5 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,10 @@ var srcs = {
1111} ;
1212
1313function getDefinePropertySrc ( ) {
14- var src ;
14+ var src = "if (typeof(module.exports) === 'function' || \n" +
15+ "(typeof(module.exports) === 'object' && module.exports !== null && Object.isExtensible(module.exports))) {\n" ;
1516
16- src = Object . keys ( srcs ) . reduce ( function forEachSrc ( preValue , value ) {
17+ src + = Object . keys ( srcs ) . reduce ( function forEachSrc ( preValue , value ) {
1718 return preValue += "Object.defineProperty(module.exports, '" +
1819 value +
1920 "', {enumerable: false, value: " +
@@ -22,6 +23,8 @@ function getDefinePropertySrc() {
2223 "writable: true}); " ;
2324 } , "" ) ;
2425
26+ src += "\n}" ;
27+
2528 return src ;
2629}
2730
Original file line number Diff line number Diff line change 1+ module . exports = true ;
Original file line number Diff line number Diff line change 1+ module . exports = null ;
Original file line number Diff line number Diff line change 1+ var obj = { } ;
2+ Object . seal ( obj ) ;
3+
4+ module . exports = obj ;
Original file line number Diff line number Diff line change @@ -220,6 +220,24 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
220220 expect ( rewired . __get__ ( "someVar" ) ) . to . be ( "hello" ) ;
221221 } ) ;
222222
223+ it ( "should not be a problem to have a module that exports a boolean" , function ( ) {
224+ expect ( function ( ) {
225+ var rewired = rewire ( "./boolean.js" ) ;
226+ } ) . to . not . throwException ( ) ;
227+ } ) ;
228+
229+ it ( "should not be a problem to have a module that exports null" , function ( ) {
230+ expect ( function ( ) {
231+ var rewired = rewire ( "./null.js" ) ;
232+ } ) . to . not . throwException ( ) ;
233+ } ) ;
234+
235+ it ( "should not be a problem to have a module that exports a sealed object" , function ( ) {
236+ expect ( function ( ) {
237+ var rewired = rewire ( "./sealedObject.js" ) ;
238+ } ) . to . not . throwException ( ) ;
239+ } ) ;
240+
223241 it ( "should not influence the original require if nothing has been required within the rewired module" , function ( ) {
224242 rewire ( "./emptyModule.js" ) ; // nothing happens here because emptyModule doesn't require anything
225243 expect ( require ( "./moduleA.js" ) . __set__ ) . to . be ( undefined ) ; // if restoring the original node require didn't worked, the module would have a setter
You can’t perform that action at this time.
0 commit comments