public void Js_Global_Then_Style() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using(new ScriptPreprocessorScope<StubScriptPreprocessor>(scriptPreprocessor)) using(new GlobalPreprocessorScope<StubGlobalPreprocessor>(globalPreprocessor)) { JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .Add("~/js/test.script.global") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=hash\"></script>", tag); Assert.AreEqual("scripty;\n", contents); Assert.AreEqual("globey", scriptPreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); } }
public void Js_Skips_Extensions_With_No_Preprocessors() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); using(new ScriptPreprocessorScope<StubScriptPreprocessor>(scriptPreprocessor)) using(new GlobalPreprocessorScope<StubGlobalPreprocessor>(globalPreprocessor)) { JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .Add("~/js/test.script.fake.global.bogus") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=A87E7F7EA72FD18FC3E75FACD850E2EB\"></script>", tag); Assert.AreEqual("scripty", contents); Assert.AreEqual("globey", scriptPreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); } }
public void CanBundleDirectoryContentsInDebug_Writes_And_Ignores_Preprocessed_Debug_Files() { var path = Guid.NewGuid().ToString(); var file1 = TestUtilities.PrepareRelativePath(path + "\\file1.script.js"); var file2 = TestUtilities.PrepareRelativePath(path + "\\file1.script.js.squishit.debug.js"); var content = "some stuffs"; var preprocessor = new StubScriptPreprocessor(); using(new ScriptPreprocessorScope<StubScriptPreprocessor>(preprocessor)) using(new ResolverFactoryScope(typeof(FileSystemResolver).FullName, StubResolver.ForDirectory(new[] { file1, file2 }))) { var frf = new StubFileReaderFactory(); frf.SetContentsForFile(file1, content); var writerFactory = new StubFileWriterFactory(); var tag = new JavaScriptBundleFactory() .WithDebuggingEnabled(true) .WithFileReaderFactory(frf) .WithFileWriterFactory(writerFactory) .WithHasher(new StubHasher("hashy")) .Create() .Add(path) .Render("~/output.js"); var expectedTag = string.Format("<script type=\"text/javascript\" src=\"{0}/file1.script.js.squishit.debug.js\"></script>\n", path); Assert.AreEqual(expectedTag, TestUtilities.NormalizeLineEndings(tag)); Assert.AreEqual(content, preprocessor.CalledWith); Assert.AreEqual(1, writerFactory.Files.Count); Assert.AreEqual("scripty", writerFactory.Files[file1 + ".squishit.debug.js"]); } }
public void WithPreprocessor_Uses_Instance_Preprocessors() { var scriptPreprocessor = new StubScriptPreprocessor(); var globalPreprocessor = new StubGlobalPreprocessor(); JavaScriptBundle javaScriptBundle = javaScriptBundleFactory .WithHasher(hasher) .WithDebuggingEnabled(false) .WithContents("start") .Create(); string tag = javaScriptBundle .WithPreprocessor(scriptPreprocessor) .WithPreprocessor(globalPreprocessor) .Add("~/js/test.script.fake.global.bogus") .Render("~/js/output.js"); string contents = javaScriptBundleFactory.FileWriterFactory.Files[TestUtilities.PrepareRelativePath(@"js\output.js")]; Assert.AreEqual("<script type=\"text/javascript\" src=\"js/output.js?r=hash\"></script>", tag); Assert.AreEqual("scripty;\n", contents); Assert.AreEqual("globey", scriptPreprocessor.CalledWith); Assert.AreEqual("start", globalPreprocessor.CalledWith); Assert.IsEmpty(Bundle.Preprocessors); }