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 = {
11
11
} ;
12
12
13
13
function 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" ;
15
16
16
- src = Object . keys ( srcs ) . reduce ( function forEachSrc ( preValue , value ) {
17
+ src + = Object . keys ( srcs ) . reduce ( function forEachSrc ( preValue , value ) {
17
18
return preValue += "Object.defineProperty(module.exports, '" +
18
19
value +
19
20
"', {enumerable: false, value: " +
@@ -22,6 +23,8 @@ function getDefinePropertySrc() {
22
23
"writable: true}); " ;
23
24
} , "" ) ;
24
25
26
+ src += "\n}" ;
27
+
25
28
return src ;
26
29
}
27
30
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 +
220
220
expect ( rewired . __get__ ( "someVar" ) ) . to . be ( "hello" ) ;
221
221
} ) ;
222
222
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
+
223
241
it ( "should not influence the original require if nothing has been required within the rewired module" , function ( ) {
224
242
rewire ( "./emptyModule.js" ) ; // nothing happens here because emptyModule doesn't require anything
225
243
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