Beispiel #1
0
        private void DiscoverTests(Dictionary<string, List<TestFileEntry>> testItems, MSBuild.Project proj, ITestCaseDiscoverySink discoverySink, IMessageLogger logger) {
            List<TestFrameworks.NodejsTestInfo> result = new List<TestFrameworks.NodejsTestInfo>();
            var projectHome = Path.GetFullPath(Path.Combine(proj.DirectoryPath, "."));
            var projSource = ((MSBuild.Project)proj).FullPath;

            var nodeExePath =
                Nodejs.GetAbsoluteNodeExePath(
                    projectHome,
                    proj.GetPropertyValue(NodejsConstants.NodeExePath));

            if (!File.Exists(nodeExePath)) {
                logger.SendMessage(TestMessageLevel.Error, String.Format("Node.exe was not found.  Please install Node.js before running tests."));
                return;
            }

            int testCount = 0;
            foreach (string testFx in testItems.Keys) {
                TestFrameworks.TestFramework testFramework = GetTestFrameworkObject(testFx);
                if (testFramework == null) {
                    logger.SendMessage(TestMessageLevel.Warning, String.Format("Ignoring unsupported test framework {0}", testFx));
                    continue;
                }

                List<TestFileEntry> fileList = testItems[testFx];
                string files = string.Join(";", fileList.Select(p=>p.File));
                logger.SendMessage(TestMessageLevel.Informational, String.Format("Processing: {0}", files));

                List<TestFrameworks.NodejsTestInfo> discoveredTestCases = testFramework.FindTests(fileList.Select(p => p.File), nodeExePath, logger, projectHome);
                testCount += discoveredTestCases.Count;
                foreach (TestFrameworks.NodejsTestInfo discoveredTest in discoveredTestCases) {
                    string qualifiedName = discoveredTest.FullyQualifiedName;
                    logger.SendMessage(TestMessageLevel.Informational, String.Format("  " /*indent*/ + "Creating TestCase:{0}", qualifiedName));
                    //figure out the test source info such as line number
                    string filePath = discoveredTest.ModulePath;
                    TestFileEntry entry = fileList.Find(p => p.File.Equals(filePath, StringComparison.OrdinalIgnoreCase));
                    FunctionInformation fi = null;
                    if (entry.IsTypeScriptTest) {
                        fi = SourceMapper.MaybeMap(new FunctionInformation(String.Empty,
                                                                           discoveredTest.TestName,
                                                                           discoveredTest.SourceLine,
                                                                           entry.File));
                    }
                    discoverySink.SendTestCase(
                        new TestCase(qualifiedName, TestExecutor.ExecutorUri, projSource) {
                            CodeFilePath = (fi != null) ? fi.Filename : filePath,
                            LineNumber = (fi != null && fi.LineNumber.HasValue) ? fi.LineNumber.Value : discoveredTest.SourceLine,
                            DisplayName = discoveredTest.TestName
                        });

                }
                logger.SendMessage(TestMessageLevel.Informational, string.Format("Processing finished for framework of {0}", testFx));
            }
            if (testCount == 0) {
                logger.SendMessage(TestMessageLevel.Warning, String.Format("Discovered 0 testcases."));
            }
        }
 internal static string GetTypeScriptBackedJavaScriptFile(MSBuild.Project project, string pathToFile) {
     var typeScriptOutDir = project.GetPropertyValue(NodeProjectProperty.TypeScriptOutDir);
     return GetTypeScriptBackedJavaScriptFile(project.DirectoryPath, typeScriptOutDir, pathToFile);
 }