@@ -37,14 +37,30 @@ describe('amdclean specs', function() {
3737 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
3838 } ) ;
3939
40- it ( 'should correctly normalize relative file paths in deps ' , function ( ) {
40+ it ( 'should correctly normalize relative file paths dependencies ' , function ( ) {
4141 var AMDcode = "define('./modules/example', ['./example1', './example2', '../example3'], function(one, two, three) {var test = true;});" ,
4242 cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
4343 standardJavaScript = "var modules_example=function (one,two,three){var test=true;}(modules_example1,modules_example2,example3);" ;
4444
4545 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
4646 } ) ;
4747
48+ it ( 'should correctly normalize relative file paths dependencies with the globalObject option' , function ( ) {
49+ var AMDcode = "define('./modules/example', ['./example1', './example2', '../example3'], function(one, two, three) {var test = true;});" ,
50+ cleanedCode = amdclean . clean ( { globalObject : true , rememberGlobalObject : false , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
51+ standardJavaScript = "var amdclean={};amdclean['modules_example']=function (one,two,three){var test=true;}(amdclean['modules_example1'],amdclean['modules_example2'],amdclean['example3']);" ;
52+
53+ expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
54+ } ) ;
55+
56+ it ( 'should correctly normalize multi-level relative file paths dependencies' , function ( ) {
57+ var AMDcode = "define('./foo/prototype/subModule/myModule', ['example1','example2', '/anotherModule/example3', '../../example4','../anotherModule/example5'], function(one, two, three, four, five) { var test = true;});" ,
58+ cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
59+ standardJavaScript = "var foo_prototype_subModule_myModule=function (one,two,three,four,five){var test=true;}(example1,example2,anotherModule_example3,foo_example4,foo_prototype_anotherModule_example5);" ;
60+
61+ expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
62+ } ) ;
63+
4864 it ( 'should correctly normalize multi-level relative file paths' , function ( ) {
4965 var AMDcode = "define('./foo/prototype/commonMethodName.js', ['example1', 'example2'], function(one, two) { var test = true;});" ,
5066 cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
@@ -127,8 +143,8 @@ describe('amdclean specs', function() {
127143
128144 it ( 'should support storing modules inside of a global object' , function ( ) {
129145 var AMDcode = "define('foo', ['require', 'exports', './bar'], function(require, exports){exports.bar = require('./bar');});" ,
130- cleanedCode = amdclean . clean ( { globalObject : true , globalObjectName : 'yeabuddy' , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
131- standardJavaScript = "var yeabuddy={};yeabuddy['foo']=function (require,exports,bar){exports.bar=bar;return exports;}({},{},yeabuddy['bar']);" ;
146+ cleanedCode = amdclean . clean ( { globalObject : true , rememberGlobalObject : false , globalObjectName : 'yeabuddy' , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
147+ standardJavaScript = "var yeabuddy={};yeabuddy['foo']=function (require,exports,bar){exports.bar=yeabuddy[' bar'] ;return exports;}({},{},yeabuddy['bar']);" ;
132148
133149 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
134150 } ) ;
@@ -345,8 +361,8 @@ describe('amdclean specs', function() {
345361
346362 it ( 'should convert object return values to a global object' , function ( ) {
347363 var AMDcode = "define('third', { exampleProp: 'This is an example' });" ,
348- cleanedCode = amdclean . clean ( { globalObject : true , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
349- standardJavaScript = "amdclean['third']={exampleProp:'This is an example'};" ;
364+ cleanedCode = amdclean . clean ( { globalObject : true , rememberGlobalObject : false , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
365+ standardJavaScript = "var amdclean={}; amdclean['third']={exampleProp:'This is an example'};" ;
350366
351367 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
352368 } ) ;
@@ -363,6 +379,14 @@ describe('amdclean specs', function() {
363379 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
364380 } ) ;
365381
382+ it ( 'should convert CommonJS require() calls correctly with the globalObject option' , function ( ) {
383+ var AMDcode = "var example = require('anotherModule');" ,
384+ cleanedCode = amdclean . clean ( { code : AMDcode , globalObject : true , rememberGlobalObject : false , escodegen : { format : { compact : true } } } ) ,
385+ standardJavaScript = "var amdclean={};var example=amdclean['anotherModule'];" ;
386+
387+ expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
388+ } ) ;
389+
366390 it ( 'should convert CommonJS require() calls with file paths' , function ( ) {
367391 var AMDcode = "var example = require('./anotherModule');" ,
368392 cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
0 commit comments