public void Initialize(IPipelines pipelines) { _debug = StaticConfiguration.IsRunningDebug; var config = HotGlueConfiguration.Load(_debug); _configuration = LoadedConfiguration.Load(config); _locator = new GraphReferenceLocator(_configuration); pipelines.AfterRequest.AddItemToEndOfPipeline(RewriteContents); }
public void Can_Find_Absolute_References_With_Tilde() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("AbsoluteReference2", "app.js", Reference.TypeEnum.App); // Act var references = locator.Load(root, reference).ToList(); // Assert references.Count.ShouldBe(2); references.ShouldContain(r => r.Name.Equals("mod.js", StringComparison.InvariantCultureIgnoreCase)); }
public void Can_Parse_Relative_Paths_And_Their_Modules(bool specifyRoot) { // Arrange if (specifyRoot) { configuration.ScriptPath = "Scripts/"; } var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module6", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Module5", "mod2.js", Reference.TypeEnum.Dependency), BuildReference("Module5", "mod1.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public static string Compile(string rootPath, string filePath, string fileName) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException("rootPath"); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } var config = LoadedConfiguration.Load(HotGlueConfiguration.Default()); var locator = new GraphReferenceLocator(config); var directoryInfo = new DirectoryInfo(rootPath); var fileInfo = new FileInfo(Path.Combine(filePath, fileName)); var reference = new SystemReference(directoryInfo, fileInfo, fileName); var references = locator.Load(rootPath, reference); var package = Package.Build(config, rootPath); return package.Compile(references); }
public void Should_Not_Parse_Library_References() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("LibraryTest1", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("LibraryTest1", "library.js", Reference.TypeEnum.Library), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void You_Cannot_Reference_Yourself() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Exception3", "reference_forever.js", Reference.TypeEnum.App); // Act var references = locator.Load(root, reference).ToList(); // Assert Assert.Fail("Expected circular reference detected exception"); }
public void Reference_Type_Should_Be_Unmodified() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module2", "app.js", Reference.TypeEnum.App); var matchReference = new[] { BuildReference("Module2", "dep1.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReference, references); }
public void Should_Add_Absolute_Reference() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module4", "app.js", Reference.TypeEnum.App); // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldContainExactlyOne(references, "/Scripts/Module4/app.js"); ShouldContainExactlyOne(references, "/Scripts/Module4-Relative/dep1.js"); ShouldContainExactlyOne(references, "/Scripts/Module4-Relative/mod.js"); }
public void Order_Of_External_Dependencies_Should_Stay_The_Same_When_Taken_From_Shared() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module3", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Module3", "ext2.js", Reference.TypeEnum.Dependency), BuildReference("Module3", "ext1.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Parse_And_Return_Reference() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module8", "graph_test.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Module8", "dep1.js", Reference.TypeEnum.Dependency), BuildReference("Module8", "module1.js", Reference.TypeEnum.Dependency), BuildReference("Module8", "graph_test.js", Reference.TypeEnum.App) }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Multiple_Files_With_Same_Name_Different_Locations_Get_Added() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module10", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Module10/sub1", "dep1.js", Reference.TypeEnum.Dependency), BuildReference("Module10/sub2", "dep1.js", Reference.TypeEnum.Dependency), BuildReference("Module10/sub3", "dep1.js", Reference.TypeEnum.Module), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Detect_Missing_Reference() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("ExceptionMissingFile", "app.js", Reference.TypeEnum.App); var references = locator.Load(root, reference); foreach (var r in references) { // Assert Assert.Fail("Expected file not found exception"); } }
public void Ignore_Multiple_Same_Require_Types_For_Same_Reference_In_Same_File() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module9", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Module9", "module.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Depedencies_At_Multiple_Levels_Should_Not_Be_Circular(bool specifyRoot) { // Arrange if (specifyRoot) { configuration.ScriptPath = "Scripts/"; } var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module1", "app.js", Reference.TypeEnum.App); var matchReferences = new [] { BuildReference("Module1", "dep1.js", Reference.TypeEnum.Dependency), BuildReference("Module1", "mod.js", Reference.TypeEnum.Module), BuildReference("Module1", "app.js", Reference.TypeEnum.App) }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Ignore_Multiple_References_In_Different_Relative_Paths() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Path1", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Path1\\Sub", "library.js", Reference.TypeEnum.Library), BuildReference("Path1\\Sub", "module.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Duplicate_Relative_References_In_Same_File_Not_Found_Until_System_Duplicate_Check() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Path2", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Path2", "module.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Detect_Multiple_Require_Types_For_Same_Reference() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Exception2", "reference.js", Reference.TypeEnum.App); var references = locator.Load(root, reference); foreach (var r in references) { // Assert Assert.Fail("Expected different require type type exception"); } }
public void Can_Parse_Relative_Paths_Within_References() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Module4", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("Module4-Relative", "dep1.js", Reference.TypeEnum.Dependency), BuildReference("Module4-Relative", "mod.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Order_Of_Dependencies_Should_Match_File_Order() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("OrderOfDependencies", "main.js", Reference.TypeEnum.App); var matchReferences = new[] { BuildReference("OrderOfDependencies", "dep1.js", Reference.TypeEnum.Dependency), BuildReference("OrderOfDependencies", "dep2.js", Reference.TypeEnum.Dependency), BuildReference("OrderOfDependencies", "dep3.js", Reference.TypeEnum.Dependency), BuildReference("OrderOfDependencies", "dep4.js", Reference.TypeEnum.Dependency), BuildReference("OrderOfDependencies", "main.js", Reference.TypeEnum.App) }; // Act var references = locator.Load(root, reference).ToList(); // Assert for (int i = 0; i < matchReferences.Length; i++) { ShouldMatch(matchReferences[i], references[i]); } }
public void More_Than_One_Library_Only_Adds_Once() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("LibraryTest2", "app.js", Reference.TypeEnum.App); var matchReferences = new[] { //TODO: Original unit test didn't have this either but //TODO library.js requires something.js //BuildReference("LibraryTest2", "something.js", Reference.TypeEnum.Dependency), BuildReference("LibraryTest2", "library.js", Reference.TypeEnum.Library), BuildReference("LibraryTest2", "app2.js", Reference.TypeEnum.Dependency), reference }; // Act var references = locator.Load(root, reference).ToList(); // Assert ShouldMatch(matchReferences, references); }
public void Detect_Circular_Reference() { // Arrange var locator = new GraphReferenceLocator(configuration); var reference = BuildReference("Exception1", "circular_begin.js", Reference.TypeEnum.App); var references = locator.Load(root, reference).ToList(); foreach (var r in references) { // Assert Assert.Fail("Expected circular reference detected exception"); } }