Exemplo n.º 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});");
        }
Exemplo 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;});");
        }
Exemplo n.º 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(){})");
        }
Exemplo n.º 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;})");
        }
Exemplo n.º 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});");
        }
Exemplo 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;});");
        }
Exemplo n.º 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;})");
        }
Exemplo n.º 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(){})");
        }
Exemplo n.º 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 {};});");
        }
Exemplo n.º 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 {};});");
        }
Exemplo n.º 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});");
        }
Exemplo 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});");
        }