public void AliasIsFilenameWithoutExtension() { var asset = new StubAsset("~/test.js", "var test = {};"); var bundle = new ScriptBundle("~"); var module = new PlainScript(asset, bundle, modules.Object); module.Alias.ShouldEqual("test"); }
public void AliasIsFromFilenameConvertsInvalidCharactersToUnderscores() { var asset = new StubAsset("~/test-test.js", "var test_test = {};"); var bundle = new ScriptBundle("~"); var module = new PlainScript(asset, bundle, modules.Object); module.Alias.ShouldEqual("test_test"); }
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});"); }
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;});"); }
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 {};});"); }
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});"); }