|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Linq; |
| 4 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 5 | +using WebCompiler; |
| 6 | + |
| 7 | +namespace WebCompilerTest.Minify |
| 8 | +{ |
| 9 | + [TestClass] |
| 10 | + public class JavaScriptMinifierTests |
| 11 | + { |
| 12 | + private const string processingConfigFile = "../../Minify/artifacts/javascript/"; |
| 13 | + |
| 14 | + /// <summary> |
| 15 | + /// Tests that '.min' is automatically appended to a minified file name. |
| 16 | + /// </summary> |
| 17 | + /// <remarks> |
| 18 | + /// For example, the file 'site.js' becomes 'site.min.js' when minified. |
| 19 | + /// </remarks> |
| 20 | + [TestMethod, TestCategory("JavaScriptMinifier")] |
| 21 | + public void ShouldAppendMinToOutputFile() |
| 22 | + { |
| 23 | + var configPath = Path.Combine(processingConfigFile, "outputfilenomin.json"); |
| 24 | + var configs = ConfigHandler.GetConfigs(configPath); |
| 25 | + var outputFile = "site.min.js"; |
| 26 | + |
| 27 | + // Capture the name of the resulting (minified) file. |
| 28 | + string resultFile = string.Empty; |
| 29 | + FileMinifier.BeforeWritingMinFile += (object sender, MinifyFileEventArgs e) => { resultFile = new FileInfo(e.ResultFile).Name; }; |
| 30 | + |
| 31 | + ConfigFileProcessor processor = new ConfigFileProcessor(); |
| 32 | + var results = processor.Process(configPath, configs, force:true); |
| 33 | + |
| 34 | + Assert.AreEqual(outputFile, resultFile); |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Tests that '.min' is only appended to a minified file name once. |
| 39 | + /// </summary> |
| 40 | + /// <remarks> |
| 41 | + /// For example, the file 'site.min.js' remains unchanged when minified |
| 42 | + /// as it already contains the '.min' suffix. |
| 43 | + /// </remarks> |
| 44 | + [TestMethod, TestCategory("JavaScriptMinifier")] |
| 45 | + public void ShouldAppendMinOnlyOnce() |
| 46 | + { |
| 47 | + var configPath = Path.Combine(processingConfigFile, "outputfilemin.json"); |
| 48 | + var configs = ConfigHandler.GetConfigs(configPath); |
| 49 | + var outputFile = configs.First().OutputFile; |
| 50 | + |
| 51 | + // Capture the name of the resulting (minified) file. |
| 52 | + string resultFile = string.Empty; |
| 53 | + FileMinifier.BeforeWritingMinFile += (object sender, MinifyFileEventArgs e) => { resultFile = new FileInfo(e.ResultFile).Name; }; |
| 54 | + |
| 55 | + ConfigFileProcessor processor = new ConfigFileProcessor(); |
| 56 | + var results = processor.Process(configPath, configs, force: true); |
| 57 | + |
| 58 | + Assert.AreEqual(outputFile, resultFile); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments