public void DiscoverTests(IEnumerable <string> fileList, TestFramework testFx, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, string testDiscovererName) { // If it's a framework name we support, is safe to submit the string to telemetry. var testAdapterName = Enum.GetNames(typeof(SupportedFramework)).Contains(testFx.Name, StringComparer.OrdinalIgnoreCase) ? testFx.Name : "Other"; TelemetryHelper.LogTestDiscoveryStarted(testAdapterName, testDiscovererName); if (!File.Exists(this.nodeExePath)) { logger.SendMessage(TestMessageLevel.Error, "Node.exe was not found. Please install Node.js before running tests."); return; } var files = string.Join(";", fileList); logger.SendMessage(TestMessageLevel.Informational, $"Processing: {files}"); var discoveredTestCases = testFx.FindTests(fileList, this.nodeExePath, logger, projectRoot: this.workingDir); if (!discoveredTestCases.Any()) { logger.SendMessage(TestMessageLevel.Warning, "Discovered 0 test cases."); return; } foreach (var discoveredTest in discoveredTestCases) { var qualifiedName = discoveredTest.FullyQualifiedName; const string indent = " "; logger.SendMessage(TestMessageLevel.Informational, $"{indent}Creating Test Case:{qualifiedName}"); //figure out the test source info such as line number var filePath = CommonUtils.GetAbsoluteFilePath(this.workingDir, discoveredTest.TestFile); // We try to map every time, so we work with .ts files and post-processed js files. var fi = SourceMapper.MaybeMap(new FunctionInformation(string.Empty, discoveredTest.TestName, discoveredTest.SourceLine, filePath)); var testCase = new TestCase(qualifiedName, NodejsConstants.ExecutorUri, this.testSource) { CodeFilePath = fi?.Filename ?? filePath, LineNumber = fi?.LineNumber ?? discoveredTest.SourceLine, DisplayName = discoveredTest.TestName }; testCase.SetPropertyValue(JavaScriptTestCaseProperties.TestFramework, testFx.Name); testCase.SetPropertyValue(JavaScriptTestCaseProperties.WorkingDir, this.workingDir); testCase.SetPropertyValue(JavaScriptTestCaseProperties.ProjectRootDir, this.workingDir); testCase.SetPropertyValue(JavaScriptTestCaseProperties.NodeExePath, this.nodeExePath); testCase.SetPropertyValue(JavaScriptTestCaseProperties.TestFile, filePath); testCase.SetPropertyValue(JavaScriptTestCaseProperties.ConfigDirPath, discoveredTest.ConfigDirPath); discoverySink.SendTestCase(testCase); } logger.SendMessage(TestMessageLevel.Informational, $"Processing finished for framework '{testFx.Name}'."); }
internal void DiscoverTestFiles(string packageJsonPath, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) { logger.SendMessage(TestMessageLevel.Informational, $"Parsing '{packageJsonPath}'."); var packageJson = PackageJsonFactory.Create(packageJsonPath); if (string.IsNullOrEmpty(packageJson.TestRoot)) { logger.SendMessage(TestMessageLevel.Informational, "No vsTestOptions|testRoot specified."); return; } var workingDir = Path.GetDirectoryName(packageJsonPath); var testFolderPath = Path.Combine(workingDir, packageJson.TestRoot); if (!Directory.Exists(testFolderPath)) { logger.SendMessage(TestMessageLevel.Error, $"Testroot '{packageJson.TestRoot}' doesn't exist."); return; } TestFramework testFx = null; foreach (var dep in packageJson.AllDependencies) { testFx = FrameworkDiscoverer.Instance.Get(dep.Name); if (testFx != null) { break; } } testFx = testFx ?? FrameworkDiscoverer.Instance.Get("ExportRunner"); var nodeExePath = Nodejs.GetPathToNodeExecutableFromEnvironment(); if (!File.Exists(nodeExePath)) { logger.SendMessage(TestMessageLevel.Error, "Node.exe was not found. Please install Node.js before running tests."); return; } var fileList = Directory.GetFiles(testFolderPath, "*.js", SearchOption.AllDirectories); var files = string.Join(";", fileList); logger.SendMessage(TestMessageLevel.Informational, $"Processing: {files}"); var discoveredTestCases = testFx.FindTests(fileList, nodeExePath, logger, projectRoot: workingDir); if (!discoveredTestCases.Any()) { logger.SendMessage(TestMessageLevel.Warning, "Discovered 0 testcases."); return; } foreach (var discoveredTest in discoveredTestCases) { var qualifiedName = discoveredTest.FullyQualifiedName; const string indent = " "; logger.SendMessage(TestMessageLevel.Informational, $"{indent}Creating TestCase:{qualifiedName}"); //figure out the test source info such as line number var filePath = CommonUtils.GetAbsoluteFilePath(workingDir, discoveredTest.TestFile); var testcase = new TestCase(qualifiedName, NodejsConstants.PackageJsonExecutorUri, packageJsonPath) { CodeFilePath = filePath, LineNumber = discoveredTest.SourceLine, DisplayName = discoveredTest.TestName }; testcase.SetPropertyValue(JavaScriptTestCaseProperties.TestFramework, testFx.Name); testcase.SetPropertyValue(JavaScriptTestCaseProperties.WorkingDir, workingDir); testcase.SetPropertyValue(JavaScriptTestCaseProperties.ProjectRootDir, workingDir); testcase.SetPropertyValue(JavaScriptTestCaseProperties.NodeExePath, nodeExePath); testcase.SetPropertyValue(JavaScriptTestCaseProperties.TestFile, filePath); discoverySink.SendTestCase(testcase); } logger.SendMessage(TestMessageLevel.Informational, $"Processing finished for framework '{testFx.Name}'."); }