Skip to content

Commit 531f3f8

Browse files
Fixed tests related to new behaviour for exports (to allow for circular dependencies).
1 parent 3a14e09 commit 531f3f8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

test/specs/convert.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe('amdclean specs', function() {
181181
'globalModules': ['foo']
182182
}),
183183
cleanedCode = amdclean.clean(AMDcode, options),
184-
standardJavaScript = "var foo;foo=function (exports){exports.bar=bar;return exports;}({});window.foo=foo;";
184+
standardJavaScript = "var foo={};foo=function (exports){exports.bar=bar;return exports;}(foo);window.foo=foo;";
185185

186186
expect(cleanedCode).toBe(standardJavaScript);
187187
});
@@ -236,7 +236,7 @@ describe('amdclean specs', function() {
236236
it('should support converting define() methods with identifiers', function() {
237237
var AMDcode = "define('esprima', ['exports'], factory);",
238238
cleanedCode = amdclean.clean(AMDcode, defaultOptions),
239-
standardJavaScript = "var esprima;esprima=function (){return typeof factory==='function'?factory():factory;}();";
239+
standardJavaScript = "var esprima={};esprima=function (){return typeof factory==='function'?factory():factory;}();";
240240

241241
expect(cleanedCode).toBe(standardJavaScript);
242242
});
@@ -603,23 +603,23 @@ describe('amdclean specs', function() {
603603
it('should support the simplified CJS wrapper', function() {
604604
var AMDcode = "define('foo', ['require', 'exports', './bar'], function(require, exports, bar){exports.bar = require('./bar');});",
605605
cleanedCode = amdclean.clean(AMDcode, defaultOptions),
606-
standardJavaScript = "var foo;foo=function (exports,bar){exports.bar=bar;return exports;}({},bar);";
606+
standardJavaScript = "var foo={};foo=function (exports,bar){exports.bar=bar;return exports;}(foo,bar);";
607607

608608
expect(cleanedCode).toBe(standardJavaScript);
609609
});
610610

611611
it('should support the plain simplified CJS wrapper', function() {
612612
var AMDcode = "define('foo',['require','exports','module','bar'],function(require, exports){exports.bar = require('bar');});",
613613
cleanedCode = amdclean.clean(AMDcode, defaultOptions),
614-
standardJavaScript = "var foo;foo=function (exports){exports.bar=bar;return exports;}({});";
614+
standardJavaScript = "var foo={};foo=function (exports){exports.bar=bar;return exports;}(foo);";
615615

616616
expect(cleanedCode).toBe(standardJavaScript);
617617
});
618618

619619
it('should support the plain simplified CJS wrapper and not bomb when a variable is not initialized', function() {
620620
var AMDcode = "define('has',['require','exports','module'],function( require, exports, module ){exports.all = function( subject, properties ){if(subject === undefined || typeof subject != 'object'){return false;}var i = 0,len = properties.length,prop; //<--- error thrown because this isn't initialized\nfor(; i < len; i++){prop = properties[i];if(!(prop in subject)){return false;}}return true;};});",
621621
cleanedCode = amdclean.clean(AMDcode, defaultOptions),
622-
standardJavaScript = "var has;has=function (exports){exports.all=function(subject,properties){if(subject===undefined||typeof subject!='object'){return false;}var i=0,len=properties.length,prop;//<--- error thrown because this isn't initialized\nfor(;i<len;i++){prop=properties[i];if(!(prop in subject)){return false;}}return true;};return exports;}({});";
622+
standardJavaScript = "var has={};has=function (exports){exports.all=function(subject,properties){if(subject===undefined||typeof subject!='object'){return false;}var i=0,len=properties.length,prop;//<--- error thrown because this isn't initialized\nfor(;i<len;i++){prop=properties[i];if(!(prop in subject)){return false;}}return true;};return exports;}(has);";
623623

624624
expect(cleanedCode).toBe(standardJavaScript);
625625
});
@@ -656,7 +656,7 @@ describe('amdclean specs', function() {
656656

657657
it('should support the Require.js optimizer cjsTranslate option that converts CommonJS modules to AMD modules', function(done) {
658658
var cleanedCode,
659-
standardJavaScript = "var commonjs3,commonjs2,commonjs4,commonjs1;commonjs3=function (exports){exports.exampleFunc=function(){var test=true;return test;};return exports;}({});commonjs2=function (exports){exports={'exampleBool':true,'exampleFunc':commonjs3.exampleFunc};return exports;}({});commonjs4=function (exports){exports.test='this is a test';return exports;}({});commonjs1=function (exports,__commonjs2__,_commonjs4_){var commonjs2=__commonjs2__;var _commonjs2_='blah';var commonjs4=_commonjs4_;commonjs2.exampleFunc();return exports;}({},commonjs2,commonjs4);";
659+
standardJavaScript = "var commonjs3={},commonjs2={},commonjs4={},commonjs1={};commonjs3=function (exports){exports.exampleFunc=function(){var test=true;return test;};return exports;}(commonjs3);commonjs2=function (exports){exports={'exampleBool':true,'exampleFunc':commonjs3.exampleFunc};return exports;}(commonjs2);commonjs4=function (exports){exports.test='this is a test';return exports;}(commonjs4);commonjs1=function (exports,__commonjs2__,_commonjs4_){var commonjs2=__commonjs2__;var _commonjs2_='blah';var commonjs4=_commonjs4_;commonjs2.exampleFunc();return exports;}(commonjs1,commonjs2,commonjs4);";
660660

661661
requirejs.optimize({
662662
'baseUrl': './test/',
@@ -945,4 +945,4 @@ describe('amdclean specs', function() {
945945
});
946946
});
947947

948-
});
948+
});

0 commit comments

Comments
 (0)