Exemplo n.º 1
0
        public void GetLintFilesForSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };
            string[]          results       = LintFileLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap);

            Assert.AreEqual(9, results.Length);

            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts");
            string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts");
            string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");
            string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            string expected5 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
            string expected6 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
            string expected7 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
            string expected8 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
            string expected9 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file

            Assert.IsTrue(results.Contains(expected1));
            Assert.IsTrue(results.Contains(expected2));
            Assert.IsTrue(results.Contains(expected3));
            Assert.IsTrue(results.Contains(expected4));
            Assert.IsTrue(results.Contains(expected5));
            Assert.IsTrue(results.Contains(expected6));
            Assert.IsTrue(results.Contains(expected7));
            Assert.IsTrue(results.Contains(expected8));
            Assert.IsTrue(results.Contains(expected9));
        }
        public void FindInSelectedItemsSingleFile()
        {
            // Arrange
            string              mainProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project             mainProject         = FindProject(mainProjectFullName, solution);
            string              mainFile4FullName   = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
            ProjectItem         file4 = FindProjectItemInProject(mainFile4FullName, mainProject);
            MockUIHierarchyItem mockFile4HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file4
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockFile4HierarchyItem };

            // Act
            string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap);

            // Assert
            string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json");

            Assert.AreEqual(1, results.Length);
            Assert.IsTrue(results.Contains(expected));
            Assert.AreEqual(1, fileToProjectMap.Keys.Count);
            Assert.AreEqual("tsconfigTest", fileToProjectMap[mainFile4FullName]);
        }
        public void GetTsconfigBuildFilesForSingleItem()
        {
            string      projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            string      projectFullName     = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project     project             = TsconfigLocationsTest.FindProject(projectFullName, solution);
            ProjectItem projectItem         = TsconfigLocationsTest.FindProjectItemInProject(projectItemFullName, project);

            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = projectItem
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            List <string> results = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: false,
                                                                           selectedItems: selectedItems, useTsConfig: true).ToList();

            // Again we are going to build the project the item is in so should lint for all tsconfigs in the project
            Assert.AreEqual(3, results.Count);

            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json");
            string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json");
            string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json");

            Assert.IsTrue(results.Contains(expected1));
            Assert.IsTrue(results.Contains(expected2));
            Assert.IsTrue(results.Contains(expected3));
        }
        public void MapToProjectsTwoProjectItemsInDifferentProjectsTest()
        {
            // Simulate fileA.ts and fileB.ts being selected in Solution Explorer in multiple.sln.
            string              fileAFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/a/fileA.ts");
            string              fileBFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/b/fileB.ts");
            Solution            solution      = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Object as Solution;
            ProjectItem         projectItemA  = solution.FindProjectItem(fileAFullPath);
            ProjectItem         projectItemB  = solution.FindProjectItem(fileBFullPath);
            MockUIHierarchyItem mockProjectItemHierarchyItemA = new MockUIHierarchyItem {
                Object = projectItemA
            };
            MockUIHierarchyItem mockProjectItemHierarchyItemB = new MockUIHierarchyItem {
                Object = projectItemB
            };

            UIHierarchyItem[] results = BuildSelectedItems.MapToProjects(
                new UIHierarchyItem[] { mockProjectItemHierarchyItemA, mockProjectItemHierarchyItemB }).ToArray();

            Assert.AreEqual(2, results.Length);
            Project projectObject = results[0].Object as Project;

            Assert.IsNotNull(projectObject);
            Assert.IsTrue(projectObject.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\a\\a.csproj"));
            Project projectObject2 = results[1].Object as Project;

            Assert.IsNotNull(projectObject2);
            Assert.IsTrue(projectObject2.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\b\\b.csproj"));
        }
Exemplo n.º 5
0
        public async Task LintSolutionUseTsconfigs()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            MockErrorListDataSource mockErrorListDataSource = new MockErrorListDataSource();

            ErrorListDataSource.InjectMockErrorListDataSource(mockErrorListDataSource);

            settings.UseTsConfig = true;

            try
            {
                bool hasVSErrors = await LintFilesCommandBase.LintSelectedItems(false, selectedItems);

                Assert.IsFalse(hasVSErrors);
                Assert.IsTrue(mockErrorListDataSource.HasErrors());
                Assert.AreEqual(7, mockErrorListDataSource.Snapshots.Count);

                // Note file5 is referenced by a tsconfig that isn't in the project, so doesn't get included
                string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
                string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file2.ts");
                string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
                string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
                //string expected5 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
                string expected6 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
                string expected7 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/file7.ts");
                string expected8 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");

                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected1));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected2));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected3));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected4));
                //Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected5));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected6));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected7));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected8));

                // Similar to TslintWithTsconfigTest.LintAll, again this level of detail may be too much
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected1].Count());
                Assert.AreEqual(4, mockErrorListDataSource.Snapshots[expected2].Count());
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected3].Count());
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected4].Count());
                //Assert.AreEqual(4, mockErrorListDataSource.Snapshots[expected5].Count());
                Assert.AreEqual(11, mockErrorListDataSource.Snapshots[expected6].Count());
                Assert.AreEqual(4, mockErrorListDataSource.Snapshots[expected7].Count());
                Assert.AreEqual(5, mockErrorListDataSource.Snapshots[expected8].Count());
            }
            finally
            {
                ErrorListDataSource.InjectMockErrorListDataSource(null);
                settings.UseTsConfig = false;
            }
        }
Exemplo n.º 6
0
        protected UIHierarchyItem[] Arrange(string solutionPath)
        {
            Initialize(solutionPath);
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            selectedItems             = new UIHierarchyItem[] { mockSolutionHierarchyItem };
            mockErrorsTableDataSource = new MockErrorsTableDataSource();
            TableDataSource.InjectMockErrorsTableDataSource(mockErrorsTableDataSource);
            return(selectedItems);
        }
        public void FindInSelectedItemsMultipleFiles()
        {
            // Includes two files with the same tsconfig.json and one with none
            string  mainProjectFullName  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project mainProject          = FindProject(mainProjectFullName, solution);
            string  emptyProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj");
            Project emptyProject         = FindProject(emptyProjectFullName, solution);

            string              mainFile4FullName      = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
            ProjectItem         file4                  = FindProjectItemInProject(mainFile4FullName, mainProject);
            MockUIHierarchyItem mockFile4HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file4
            };

            string              emptyFile2FullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts");
            ProjectItem         file2 = FindProjectItemInProject(emptyFile2FullName, emptyProject);
            MockUIHierarchyItem mockFile2HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file2
            };

            string              mainFile1FullName      = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            ProjectItem         file1                  = FindProjectItemInProject(mainFile1FullName, mainProject);
            MockUIHierarchyItem mockFile1HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file1
            };


            UIHierarchyItem[] selectedItems = new UIHierarchyItem[]
            {
                mockFile1HierarchyItem, mockFile2HierarchyItem, mockFile4HierarchyItem
            };

            string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap);

            string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json");

            Assert.AreEqual(1, results.Length);
            Assert.IsTrue(results.Contains(expected));
            // We create the fileToProjectMap for single selected files only, which is what we have here
            Assert.AreEqual(2, fileToProjectMap.Keys.Count);
            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");

            Assert.AreEqual("tsconfigTest", fileToProjectMap[expected1]);
            Assert.AreEqual("tsconfigTest", fileToProjectMap[expected2]);
        }
        public void MapToProjectsItemNotInProjectTest()
        {
            // package.json in b isn't in a project or solution
            string fileFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/b/package.json");

            Assert.IsTrue(File.Exists(fileFullPath));
            Solution            solution    = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Object as Solution;
            ProjectItem         projectItem = solution.FindProjectItem(fileFullPath);
            MockUIHierarchyItem mockProjectItemHierarchyItem = new MockUIHierarchyItem {
                Object = projectItem
            };

            UIHierarchyItem[] results = BuildSelectedItems.MapToProjects(new UIHierarchyItem[] { mockProjectItemHierarchyItem }).ToArray();

            Assert.AreEqual(0, results.Length);
        }
Exemplo n.º 9
0
        public void FindInSelectedItemsNoTsconfig()
        {
            string              emptyProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj");
            Project             emptyProject         = FindProject(emptyProjectFullName, solution);
            string              emptyFile2FullName   = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts");
            ProjectItem         file2 = FindProjectItemInProject(emptyFile2FullName, emptyProject);
            MockUIHierarchyItem mockFile2HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file2
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockFile2HierarchyItem };

            Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray();

            Assert.AreEqual(0, results.Length);
        }
Exemplo n.º 10
0
        public void GetLintFilesForProject()
        {
            string              projectFullName           = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj");
            Project             project                   = TsconfigLocationsTest.FindProject(projectFullName, solution);
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = project
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            string[] results = LintFileLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap);

            Assert.AreEqual(1, results.Length);
            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");

            Assert.IsTrue(results.Contains(expected1));
        }
        public void GetLintFilesForSolutionIncludeNested()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            settings.IgnoreNestedFiles = false;

            try
            {
                List <string> results = LintFileLocations.FindPathsFromSelectedItems(selectedItems).ToList();

                Assert.AreEqual(10, results.Count);

                string expected1  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts");
                string expected2  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts");
                string expected3  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");
                string expected4  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
                string expected5  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
                string expected6  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
                string expected7  = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
                string expected8  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
                string expected9  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/file7.ts");
                string expected10 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file

                Assert.IsTrue(results.Contains(expected1));
                Assert.IsTrue(results.Contains(expected2));
                Assert.IsTrue(results.Contains(expected3));
                Assert.IsTrue(results.Contains(expected4));
                Assert.IsTrue(results.Contains(expected5));
                Assert.IsTrue(results.Contains(expected6));
                Assert.IsTrue(results.Contains(expected7));
                Assert.IsTrue(results.Contains(expected8));
                Assert.IsTrue(results.Contains(expected9));
                Assert.IsTrue(results.Contains(expected10));
            }
            finally
            {
                settings.IgnoreNestedFiles = true;
            }
        }
        public void GetBuildFilesForProject()
        {
            string              projectFullName           = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj");
            Project             project                   = TsconfigLocationsTest.FindProject(projectFullName, solution);
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = project
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            List <string> results = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: false,
                                                                           selectedItems: selectedItems, useTsConfig: false).ToList();

            Assert.AreEqual(1, results.Count);
            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");

            Assert.IsTrue(results.Contains(expected1));
        }
Exemplo n.º 13
0
        public void FindInSelectedItemsMultipleFiles()
        {
            // Includes two files with the same tsconfig.json and one with none
            string  mainProjectFullName  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project mainProject          = FindProject(mainProjectFullName, solution);
            string  emptyProjectFullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/tsconfigEmptyTest.csproj");
            Project emptyProject         = FindProject(emptyProjectFullName, solution);

            string              mainFile4FullName      = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
            ProjectItem         file4                  = FindProjectItemInProject(mainFile4FullName, mainProject);
            MockUIHierarchyItem mockFile4HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file4
            };

            string              emptyFile2FullName = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file2.ts");
            ProjectItem         file2 = FindProjectItemInProject(emptyFile2FullName, emptyProject);
            MockUIHierarchyItem mockFile2HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file2
            };

            string              mainFile1FullName      = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            ProjectItem         file1                  = FindProjectItemInProject(mainFile1FullName, mainProject);
            MockUIHierarchyItem mockFile1HierarchyItem = new MockUIHierarchyItem()
            {
                Object = file1
            };


            UIHierarchyItem[] selectedItems = new UIHierarchyItem[]
            {
                mockFile1HierarchyItem, mockFile2HierarchyItem, mockFile4HierarchyItem
            };

            Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray();

            string expected = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json");

            Assert.AreEqual(1, results.Length);
            Assert.IsTrue(Contains(results, expected));
        }
Exemplo n.º 14
0
        public void FindInSelectedItemsSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray();

            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json");
            string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json");
            string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json");

            Assert.AreEqual(3, results.Length);
            Assert.IsTrue(Contains(results, expected1));
            Assert.IsTrue(Contains(results, expected2));
            Assert.IsTrue(Contains(results, expected3));
        }
        public void MapToProjectsSingleProjectItemTest()
        {
            // Simulate fileA.ts being selected in Solution Explorer in multiple.sln.
            // Ensure a.csproj (which contains fileA.ts) is the item we calculate as building
            string              fileAFullPath = Path.GetFullPath(@"../../artifacts/localinstall/multiple/a/fileA.ts");
            Solution            solution      = WebLinterPackage.Dte.ToolWindows.SolutionExplorer.UIHierarchyItems.Item(1).Object as Solution;
            ProjectItem         projectItem   = solution.FindProjectItem(fileAFullPath);
            MockUIHierarchyItem mockProjectItemHierarchyItem = new MockUIHierarchyItem {
                Object = projectItem
            };

            UIHierarchyItem[] results = BuildSelectedItems.MapToProjects(new UIHierarchyItem[] { mockProjectItemHierarchyItem }).ToArray();

            Assert.AreEqual(1, results.Length);
            Project projectObject = results[0].Object as Project;

            Assert.IsNotNull(projectObject);
            Assert.IsTrue(projectObject.FullName
                          .EndsWith("\\src\\WebLinterTest\\artifacts\\localinstall\\multiple\\a\\a.csproj"));
        }
Exemplo n.º 16
0
        public void FindInSelectedItemsTsconfig()
        {
            string              mainProjectFullName         = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project             mainProject                 = FindProject(mainProjectFullName, solution);
            string              mainProjectTsconfigFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json");
            ProjectItem         tsconfig = FindProjectItemInProject(mainProjectTsconfigFullName, mainProject);
            MockUIHierarchyItem mockTsconfigHierarchyItem = new MockUIHierarchyItem()
            {
                Object = tsconfig
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockTsconfigHierarchyItem };

            Tsconfig[] results = TsconfigLocations.FindFromSelectedItems(selectedItems).ToArray();

            string expected = mainProjectTsconfigFullName;

            Assert.AreEqual(1, results.Length);
            Assert.IsTrue(Contains(results, expected));
        }
        public void GetLintFilesForSingleItem()
        {
            string      projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            string      projectFullName     = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project     project             = TsconfigLocationsTest.FindProject(projectFullName, solution);
            ProjectItem projectItem         = TsconfigLocationsTest.FindProjectItemInProject(projectItemFullName, project);

            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = projectItem
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            List <string> results = LintFileLocations.FindPathsFromSelectedItems(selectedItems).ToList();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(projectItemFullName, results[0]);
            //string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
            //Assert.IsTrue(results.Contains(expected1));
        }
        public void FindInSelectedItemsTsconfig()
        {
            string              mainProjectFullName         = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project             mainProject                 = FindProject(mainProjectFullName, solution);
            string              mainProjectTsconfigFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json");
            ProjectItem         tsconfig = FindProjectItemInProject(mainProjectTsconfigFullName, mainProject);
            MockUIHierarchyItem mockTsconfigHierarchyItem = new MockUIHierarchyItem()
            {
                Object = tsconfig
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockTsconfigHierarchyItem };

            string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap);

            string expected = mainProjectTsconfigFullName;

            Assert.AreEqual(1, results.Length);
            Assert.IsTrue(results.Contains(expected));
            Assert.AreEqual(0, fileToProjectMap.Keys.Count);
        }
        public void FindInSelectedItemsSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            string[] results = TsconfigLocations.FindPathsFromSelectedItems(selectedItems, out Dictionary <string, string> fileToProjectMap);

            string expectedConfig1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfig.json");
            string expectedConfig2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/tsconfig.json");
            string expectedConfig3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/tsconfig.json");

            Assert.AreEqual(3, results.Length);
            Assert.IsTrue(results.Contains(expectedConfig1));
            Assert.IsTrue(results.Contains(expectedConfig2));
            Assert.IsTrue(results.Contains(expectedConfig3));
            Assert.AreEqual(0, fileToProjectMap.Keys.Count);
        }
        public void GetBuildFilesForSingleItem()
        {
            string      projectItemFullName = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            string      projectFullName     = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/tsconfigTest.csproj");
            Project     project             = TsconfigLocationsTest.FindProject(projectFullName, solution);
            ProjectItem projectItem         = TsconfigLocationsTest.FindProjectItemInProject(projectItemFullName, project);

            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = projectItem
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            List <string> results = BuildFileLocations.GetBuildFilesToLint(isBuildingSolution: false,
                                                                           selectedItems: selectedItems, useTsConfig: false).ToList();

            // We're going to build the project that the individual file is in (tsconfigTest) and so need to lint
            // all the files in said project before the build.  Note NOT using tsconfig.json (useTsConfig: false above).
            Assert.AreEqual(8, results.Count);

            string expected1 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts");
            string expected2 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts");
            string expected3 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");
            string expected4 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
            string expected5 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
            string expected6 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
            string expected7 = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
            string expected8 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file

            Assert.IsTrue(results.Contains(expected1));
            Assert.IsTrue(results.Contains(expected2));
            Assert.IsTrue(results.Contains(expected3));
            Assert.IsTrue(results.Contains(expected4));
            Assert.IsTrue(results.Contains(expected5));
            Assert.IsTrue(results.Contains(expected6));
            Assert.IsTrue(results.Contains(expected7));
            Assert.IsTrue(results.Contains(expected8));
        }
Exemplo n.º 21
0
        public async Task LintBadTslintJsonSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            MockErrorListDataSource mockErrorListDataSource = new MockErrorListDataSource();

            ErrorListDataSource.InjectMockErrorListDataSource(mockErrorListDataSource);

            settings.UseTsConfig       = false;
            settings.IgnoreNestedFiles = false;

            try
            {
                bool hasVSErrors = await LintFilesCommandBase.LintSelectedItems(false, selectedItems);

                Assert.IsTrue(hasVSErrors);
                Assert.IsTrue(mockErrorListDataSource.HasErrors());
                Assert.AreEqual(1, mockErrorListDataSource.Snapshots.Count);

                CollectionAssert.AreEquivalent(new string[] { "TSLint" }, mockErrorListDataSource.Snapshots.Keys.ToArray());

                var actualMsg   = mockErrorListDataSource.Snapshots["TSLint"].Select(e => e.Message).First();
                var expectedMsg = "Could not find custom rule directory: ./does-not-exist";
                StringAssert.Contains(actualMsg, expectedMsg);
            }
            finally
            {
                ErrorListDataSource.InjectMockErrorListDataSource(null);
                settings.UseTsConfig       = false;
                settings.IgnoreNestedFiles = true;
            }
        }
        public async Task LintSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            // TODO Don't like that singleton much, or my workaround to test:
            // any reason it can't be instantiated at startup and cached on the package?
            MockErrorsTableDataSource mockErrorsTableDataSource = new MockErrorsTableDataSource();

            TableDataSource.InjectMockErrorsTableDataSource(mockErrorsTableDataSource);

            settings.UseTsConfig       = false;
            settings.IgnoreNestedFiles = false;

            try
            {
                bool hasVSErrors = await LintFilesCommandBase.LintLintLint(false, selectedItems);

                Assert.IsFalse(hasVSErrors);
                Assert.IsTrue(mockErrorsTableDataSource.HasErrors());
                Assert.AreEqual(10, mockErrorsTableDataSource.Snapshots.Count);

                // See LintFileLocationsTest.GetLintFilesForSolutionIncludeNested
                string expected1  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts");
                string expected2  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts");
                string expected3  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");
                string expected4  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
                string expected5  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
                string expected6  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
                string expected7  = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
                string expected8  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
                string expected9  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/file7.ts");
                string expected10 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file

                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected1));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected2));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected3));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected4));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected5));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected6));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected7));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected8));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected9));
                Assert.IsTrue(mockErrorsTableDataSource.Snapshots.Keys.Contains(expected10));

                // May be too painful when we upgrade tslint: I think since the tslint.json is fixed it should be OK though
                // 2017-08-30: tslint 5.7.0 changed no-namespace rule to 'ignore global augmentation', reduced 293->292 below
                // 2017-10-30: tslint 5.8.0 no-empty-interface now disregards interfaces with generic types #3260, reduced 292 -> 283 below
                Assert.AreEqual(8, mockErrorsTableDataSource.Snapshots[expected1].Count());
                Assert.AreEqual(283, mockErrorsTableDataSource.Snapshots[expected2].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected3].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected4].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected5].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected6].Count());
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected7].Count());
                Assert.AreEqual(9, mockErrorsTableDataSource.Snapshots[expected8].Count());
                Assert.AreEqual(3, mockErrorsTableDataSource.Snapshots[expected9].Count());
                Assert.AreEqual(2, mockErrorsTableDataSource.Snapshots[expected10].Count());

                // Pick an error and check we are generating all details - expected4 is file1.ts
                LintingError lintingError = mockErrorsTableDataSource.Snapshots[expected4].First(le => le.ErrorCode == "no-empty");
                Assert.AreEqual(expected4, lintingError.FileName);
                Assert.AreEqual("block is empty", lintingError.Message);
                Assert.AreEqual(2, lintingError.LineNumber);
                Assert.AreEqual(17, lintingError.ColumnNumber);
                Assert.AreEqual("https://palantir.github.io/tslint/rules/no-empty", lintingError.HelpLink);
                Assert.IsFalse(lintingError.IsError);
            }
            finally
            {
                TableDataSource.InjectMockErrorsTableDataSource(null);
                settings.UseTsConfig       = false;
                settings.IgnoreNestedFiles = true;
            }
        }
Exemplo n.º 23
0
        public async Task LintSolution()
        {
            MockUIHierarchyItem mockSolutionHierarchyItem = new MockUIHierarchyItem()
            {
                Object = solution
            };

            UIHierarchyItem[] selectedItems = new UIHierarchyItem[] { mockSolutionHierarchyItem };

            MockErrorListDataSource mockErrorListDataSource = new MockErrorListDataSource();

            ErrorListDataSource.InjectMockErrorListDataSource(mockErrorListDataSource);

            settings.UseTsConfig       = false;
            settings.IgnoreNestedFiles = false;

            try
            {
                bool hasVSErrors = await LintFilesCommandBase.LintSelectedItems(false, selectedItems);

                Assert.IsFalse(hasVSErrors);
                Assert.IsTrue(mockErrorListDataSource.HasErrors());
                Assert.AreEqual(10, mockErrorListDataSource.Snapshots.Count);

                // See LintFileLocationsTest.GetLintFilesForSolutionIncludeNested
                string expected1  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react-dom.d.ts");
                string expected2  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/react.d.ts");
                string expected3  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/test.ts");
                string expected4  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/file1.ts");
                string expected5  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file4.ts");
                string expected6  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/b/file3.ts");
                string expected7  = Path.GetFullPath(@"../../artifacts/tsconfig/none/b/file5.ts");
                string expected8  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/a/c/file6.tsx");
                string expected9  = Path.GetFullPath(@"../../artifacts/tsconfig/multiple/file7.ts");
                string expected10 = Path.GetFullPath(@"../../artifacts/tsconfig/file9.ts"); // Linked file

                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected1));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected2));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected3));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected4));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected5));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected6));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected7));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected8));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected9));
                Assert.IsTrue(mockErrorListDataSource.Snapshots.Keys.Contains(expected10));

                // May be too painful when we upgrade tslint: I think since the tslint.json is fixed it should be OK though
                // 2017-08-30: tslint 5.7.0 changed no-namespace rule to 'ignore global augmentation', reduced 293->292 below
                // 2017-10-30: tslint 5.8.0 no-empty-interface now disregards interfaces with generic types #3260, reduced 292 -> 283 below
                // 2019-03-02: tslint 15.13.0 enabled the completed-docs rules if NOT using tsconfig.json, as here, previously only ran if
                //             a tsconfig.json was specified.  That is it stopped being 'typed' = 'uses tslint' = 'uses type checker'.
                //             The rule was in tslint.json for this test, so extra test errors appeared. tslint issue #3557.
                // 2019-05-31: tslint 15.17.0 treats IntrinsicAttributes, IntrinsicClassAttributes and IntrinsicElements interface names
                //             as failing the 'interface name must start with a capitalized I' test, version 5.13.1 didn't, +3 errors in
                //             expected2 (react.d.ts).  interface-name rule.
                // 2020-01-07: tslint 5.20.1 has stopped reporting line 2164 in react.d.ts in WebLinterTest/artifacts/
                //             tsconfig/multiple as being over 120 characters, in spite of the fact it clearly is, was reported in
                //             earlier versions, and other lines over 120 characters in that file are being correctly reported.  Reduces
                //             errors in expected2 from 1297 to 1296. Edit: this is because of the check-strings flag for max-line-length
                //             introduced in 5.19.0 and set to false by default.  If it is set to true the error reappears.  Whether it's
                //             really meant to allow multiple string options on a line or this is a bug I'm not sure.
                Assert.AreEqual(22, mockErrorListDataSource.Snapshots[expected1].Count());
                Assert.AreEqual(1296, mockErrorListDataSource.Snapshots[expected2].Count());
                Assert.AreEqual(5, mockErrorListDataSource.Snapshots[expected3].Count());
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected4].Count());
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected5].Count());
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected6].Count());
                Assert.AreEqual(4, mockErrorListDataSource.Snapshots[expected7].Count());
                Assert.AreEqual(11, mockErrorListDataSource.Snapshots[expected8].Count());
                Assert.AreEqual(4, mockErrorListDataSource.Snapshots[expected9].Count());
                Assert.AreEqual(3, mockErrorListDataSource.Snapshots[expected10].Count());

                // Pick an error and check we are generating all details - expected4 is file1.ts
                LintingError lintingError = mockErrorListDataSource.Snapshots[expected4].First(le => le.ErrorCode == "no-empty");
                Assert.AreEqual(expected4, lintingError.FileName);
                Assert.AreEqual("block is empty", lintingError.Message);
                Assert.AreEqual(2, lintingError.LineNumber);
                Assert.AreEqual(17, lintingError.ColumnNumber);
                Assert.AreEqual("https://palantir.github.io/tslint/rules/no-empty", lintingError.HelpLink);
                Assert.IsFalse(lintingError.IsError);
            }
            finally
            {
                ErrorListDataSource.InjectMockErrorListDataSource(null);
                settings.UseTsConfig       = false;
                settings.IgnoreNestedFiles = true;
            }
        }