@@ -37,6 +37,30 @@ describe('amdclean specs', function() {
3737 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
3838 } ) ;
3939
40+ it ( 'should correctly normalize relative file paths dependencies' , function ( ) {
41+ var AMDcode = "define('./modules/example', ['./example1', './example2', '../example3'], function(one, two, three) {var test = true;});" ,
42+ cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
43+ standardJavaScript = "var modules_example=function (one,two,three){var test=true;}(modules_example1,modules_example2,example3);" ;
44+
45+ expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
46+ } ) ;
47+
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+
4064 it ( 'should correctly normalize multi-level relative file paths' , function ( ) {
4165 var AMDcode = "define('./foo/prototype/commonMethodName.js', ['example1', 'example2'], function(one, two) { var test = true;});" ,
4266 cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
@@ -119,8 +143,8 @@ describe('amdclean specs', function() {
119143
120144 it ( 'should support storing modules inside of a global object' , function ( ) {
121145 var AMDcode = "define('foo', ['require', 'exports', './bar'], function(require, exports){exports.bar = require('./bar');});" ,
122- cleanedCode = amdclean . clean ( { globalObject : true , globalObjectName : 'yeabuddy' , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
123- 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']);" ;
124148
125149 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
126150 } ) ;
@@ -337,8 +361,8 @@ describe('amdclean specs', function() {
337361
338362 it ( 'should convert object return values to a global object' , function ( ) {
339363 var AMDcode = "define('third', { exampleProp: 'This is an example' });" ,
340- cleanedCode = amdclean . clean ( { globalObject : true , code : AMDcode , escodegen : { format : { compact : true } } } ) ,
341- 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'};" ;
342366
343367 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
344368 } ) ;
@@ -355,6 +379,14 @@ describe('amdclean specs', function() {
355379 expect ( cleanedCode ) . toBe ( standardJavaScript ) ;
356380 } ) ;
357381
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+
358390 it ( 'should convert CommonJS require() calls with file paths' , function ( ) {
359391 var AMDcode = "var example = require('./anotherModule');" ,
360392 cleanedCode = amdclean . clean ( { code : AMDcode , escodegen : { format : { compact : true } } } ) ,
0 commit comments