示例#1
0
        public void GivenScriptHasNoTopLevelVarOrReturnExpressionThenDefineHasNoReturn()
        {
            var asset = new StubAsset("~/test.js");
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object);

            var output = asset.OpenStream().ReadToEnd();
            output.ShouldEqual("define(\"test\",[],function(){\r\n});");
        }
示例#2
0
        public void AssetIsWrappedInDefineCall()
        {
            var asset = new StubAsset("~/test.js", "var test = {};");
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object);

            var output = asset.OpenStream().ReadToEnd();
            output.ShouldEqual("define(\"test\",[],function(){var test = {};\r\nreturn test;});");
        }
示例#3
0
        public void AssetIsTransformedToIncludeModulePathInDefineCallWithNoDependencies()
        {
            var asset = new StubAsset("~/test.js", "define(function(){})");
            var bundle = new ScriptBundle("~");

            var module = new AnonymousModule(asset, bundle);

            var output = asset.OpenStream().ReadToEnd();
            output.ShouldEqual("define(\"test\",function(){})");
        }
示例#4
0
        public void AssetIsNotMinified()
        {
            var asset = new StubAsset("~/test.js", "define([],function(){var x = 1;})");
            var bundle = new ScriptBundle("~");

            var module = new AnonymousModule(asset, bundle);

            var output = asset.OpenStream().ReadToEnd();
            output.ShouldEqual("define(\"test\",[],function(){var x = 1;})");
        }
示例#5
0
        public void GivenScriptHasNoTopLevelVarOrReturnExpressionThenDefineHasNoReturn()
        {
            var asset  = new StubAsset("~/test.js");
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object);

            var output = asset.OpenStream().ReadToEnd();

            output.ShouldEqual("define(\"test\",[],function(){\r\n});");
        }
示例#6
0
        public void AssetIsWrappedInDefineCall()
        {
            var asset  = new StubAsset("~/test.js", "var test = {};");
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object);

            var output = asset.OpenStream().ReadToEnd();

            output.ShouldEqual("define(\"test\",[],function(){var test = {};\r\nreturn test;});");
        }
示例#7
0
        public void AssetIsNotMinified()
        {
            var asset  = new StubAsset("~/test.js", "define([],function(){var x = 1;})");
            var bundle = new ScriptBundle("~");

            var module = new AnonymousModule(asset, bundle);

            var output = asset.OpenStream().ReadToEnd();

            output.ShouldEqual("define(\"test\",[],function(){var x = 1;})");
        }
示例#8
0
        public void AssetIsTransformedToIncludeModulePathInDefineCallWithNoDependencies()
        {
            var asset  = new StubAsset("~/test.js", "define(function(){})");
            var bundle = new ScriptBundle("~");

            var module = new AnonymousModule(asset, bundle);

            var output = asset.OpenStream().ReadToEnd();

            output.ShouldEqual("define(\"test\",function(){})");
        }
示例#9
0
        public void DefineCallReturnsModuleReturnExpression()
        {
            var asset = new StubAsset("~/test.js", "var test = {};");
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object)
            {
                ModuleReturnExpression = "{}"
            };

            var output = asset.OpenStream().ReadToEnd();
            output.ShouldEqual("define(\"test\",[],function(){var test = {};\r\nreturn {};});");
        }
示例#10
0
        public void DefineCallReturnsModuleReturnExpression()
        {
            var asset  = new StubAsset("~/test.js", "var test = {};");
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object)
            {
                ModuleReturnExpression = "{}"
            };

            var output = asset.OpenStream().ReadToEnd();

            output.ShouldEqual("define(\"test\",[],function(){var test = {};\r\nreturn {};});");
        }
示例#11
0
        public void AssetReferencesAreTranslatedIntoModuleDependencies()
        {
            SetupFakeModule("foo");
            SetupFakeModule("bar");

            var asset = new StubAsset("~/test.js");
            asset.ReferenceList.Add(new AssetReference("~/test.js", "~/foo.js", 1, AssetReferenceType.SameBundle));
            asset.ReferenceList.Add(new AssetReference("~/test.js", "~/bar.js", 1, AssetReferenceType.SameBundle));
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object);

            var output = asset.OpenStream().ReadToEnd();
            output.ShouldEqual("define(\"test\",[\"foo\",\"bar\"],function(foo,bar){\r\n});");
        }
示例#12
0
        public void AssetReferencesAreTranslatedIntoModuleDependencies()
        {
            SetupFakeModule("foo");
            SetupFakeModule("bar");

            var asset = new StubAsset("~/test.js");

            asset.ReferenceList.Add(new AssetReference("~/test.js", "~/foo.js", 1, AssetReferenceType.SameBundle));
            asset.ReferenceList.Add(new AssetReference("~/test.js", "~/bar.js", 1, AssetReferenceType.SameBundle));
            var bundle = new ScriptBundle("~");

            var module = new PlainScript(asset, bundle, modules.Object);

            var output = asset.OpenStream().ReadToEnd();

            output.ShouldEqual("define(\"test\",[\"foo\",\"bar\"],function(foo,bar){\r\n});");
        }