diff --git a/Nodejs/Product/TestAdapterImpl/TestDiscoverer.cs b/Nodejs/Product/TestAdapterImpl/TestDiscoverer.cs index b4834d91c..c54e44526 100644 --- a/Nodejs/Product/TestAdapterImpl/TestDiscoverer.cs +++ b/Nodejs/Product/TestAdapterImpl/TestDiscoverer.cs @@ -129,7 +129,7 @@ private void DiscoverTests(Dictionary> testItems, MS var testFramework = GetTestFrameworkObject(testFx); if (testFramework == null) { - logger.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, "Ignoring unsupported test framework {0}", testFx)); + logger.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, "Ignoring unsupported test framework \'{0}\'.", testFx)); continue; } @@ -137,7 +137,7 @@ private void DiscoverTests(Dictionary> testItems, MS var files = string.Join(";", fileList.Select(p => p.File)); logger.SendMessage(TestMessageLevel.Informational, string.Format(CultureInfo.CurrentCulture, "Processing: {0}", files)); - var discoveredTestCases = testFramework.FindTests(fileList.Select(p => p.File), nodeExePath, logger, projectHome); + var discoveredTestCases = testFramework.FindTests(fileList.Select(p => p.File), nodeExePath, logger, projectRoot:projectHome); testCount += discoveredTestCases.Count; foreach (var discoveredTest in discoveredTestCases) { diff --git a/Nodejs/Product/TestAdapterImpl/TestExecutor.cs b/Nodejs/Product/TestAdapterImpl/TestExecutor.cs index 516c5f86d..df455b176 100644 --- a/Nodejs/Product/TestAdapterImpl/TestExecutor.cs +++ b/Nodejs/Product/TestAdapterImpl/TestExecutor.cs @@ -198,8 +198,6 @@ private void LogTelemetry(int testCount, Version nodeVersion, bool isDebugging) userTask.Properties["VS.NodejsTools.NodeVersion"] = nodeVersion.ToString(); userTask.Properties["VS.NodejsTools.IsDebugging"] = isDebugging; - //todo: when we have support for the Node 8 debugger log which version of the debugger people are actually using - TelemetryService.DefaultSession?.PostEvent(userTask); } @@ -228,7 +226,8 @@ private void RunTestCases(IEnumerable tests, IRunContext runContext, I } // All tests being run are for the same test file, so just use the first test listed to get the working dir - var testInfo = new NodejsTestInfo(tests.First().FullyQualifiedName); + var firstTest = tests.First(); + var testInfo = new NodejsTestInfo(firstTest.FullyQualifiedName, firstTest.CodeFilePath); var workingDir = Path.GetDirectoryName(CommonUtils.GetAbsoluteFilePath(settings.WorkingDir, testInfo.ModulePath)); var nodeVersion = Nodejs.GetNodeVersion(settings.NodeExePath); @@ -372,8 +371,8 @@ select connection.LocalEndPoint.Port private IEnumerable GetInterpreterArgs(TestCase test, string workingDir, string projectRootDir) { - var testInfo = new TestFrameworks.NodejsTestInfo(test.FullyQualifiedName); - var discover = new TestFrameworks.FrameworkDiscover(); + var testInfo = new NodejsTestInfo(test.FullyQualifiedName, test.CodeFilePath); + var discover = new FrameworkDiscover(); return discover.Get(testInfo.TestFramework).ArgumentsToRunTests(testInfo.TestName, testInfo.ModulePath, workingDir, projectRootDir); } @@ -467,27 +466,19 @@ public NodejsProjectSettings() this.WorkingDir = string.Empty; } - public string NodeExePath { get; set; } - public string SearchPath { get; set; } - public string WorkingDir { get; set; } - public string ProjectRootDir { get; set; } + public string NodeExePath { get; set; } = string.Empty; + public string SearchPath { get; set; } = string.Empty; + public string WorkingDir { get; set; } = string.Empty; + public string ProjectRootDir { get; set; } = string.Empty; } internal class ResultObject { - public ResultObject() - { - this.title = string.Empty; - this.passed = false; - this.pending = false; - this.stdout = string.Empty; - this.stderr = string.Empty; - } - public string title { get; set; } - public bool passed { get; set; } - public bool? pending { get; set; } - public string stdout { get; set; } - public string stderr { get; set; } + public string title { get; set; } = string.Empty; + public bool passed { get; set; } = false; + public bool? pending { get; set; } = false; + public string stdout { get; set; } = string.Empty; + public string stderr { get; set; } = string.Empty; } internal class TestEvent @@ -522,3 +513,4 @@ public TestCaseObject(string framework, string testName, string testFile, string public string workingFolder { get; set; } public string projectFolder { get; set; } } + diff --git a/Nodejs/Product/TestAdapterImpl/TestFrameworks/NodejsTestInfo.cs b/Nodejs/Product/TestAdapterImpl/TestFrameworks/NodejsTestInfo.cs index 097bd6f3a..76219bf77 100644 --- a/Nodejs/Product/TestAdapterImpl/TestFrameworks/NodejsTestInfo.cs +++ b/Nodejs/Product/TestAdapterImpl/TestFrameworks/NodejsTestInfo.cs @@ -1,36 +1,50 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; +using System.Text.RegularExpressions; +using Microsoft.VisualStudioTools; namespace Microsoft.NodejsTools.TestAdapter.TestFrameworks { internal class NodejsTestInfo { - public NodejsTestInfo(string fullyQualifiedName) + public NodejsTestInfo(string fullyQualifiedName, string modulePath) { var parts = fullyQualifiedName.Split(new[] { "::" }, StringSplitOptions.None); if (parts.Length != 3) { throw new ArgumentException("Invalid fully qualified test name", nameof(fullyQualifiedName)); } - this.ModulePath = parts[0]; + + this.ModulePath = modulePath; + + this.ModuleName = parts[0]; this.TestName = parts[1]; this.TestFramework = parts[2]; } - public NodejsTestInfo(string modulePath, string testName, string testFramework, int line, int column) + public NodejsTestInfo(string modulePath, string testName, string testFramework, int line, int column, string projectRootDir) { + var relativePath = CommonUtils.GetRelativeFilePath(projectRootDir, modulePath); + var moduleName = Regex.Replace(relativePath, @"[ \\/]", "_"); // use regex to replace spaces and slashes with '_' + + var fileName = Path.GetFileNameWithoutExtension(modulePath); + this.ModulePath = modulePath; + this.ModuleName = moduleName; this.TestName = testName; this.TestFramework = testFramework; this.SourceLine = line; this.SourceColumn = column; } - public string FullyQualifiedName => $"{this.ModulePath}::{this.TestName}::{this.TestFramework}"; + public string FullyQualifiedName => $"{this.ModuleName}::{this.TestName}::{this.TestFramework}"; public string ModulePath { get; } + public string ModuleName { get; } + public string TestName { get; } public string TestFramework { get; } diff --git a/Nodejs/Product/TestAdapterImpl/TestFrameworks/TestFramework.cs b/Nodejs/Product/TestAdapterImpl/TestFrameworks/TestFramework.cs index 58d8f4302..6dcd7ee5c 100644 --- a/Nodejs/Product/TestAdapterImpl/TestFrameworks/TestFramework.cs +++ b/Nodejs/Product/TestAdapterImpl/TestFrameworks/TestFramework.cs @@ -31,13 +31,13 @@ public TestFramework(string vsixScriptFolder) public List FindTests(IEnumerable testFiles, string nodeExe, IMessageLogger logger, - string workingDirectory) + string projectRoot) { var testInfo = string.Empty; var discoverResultFile = Path.GetTempFileName(); try { - var stdout = EvaluateJavaScript(nodeExe, string.Join(";", testFiles), discoverResultFile, logger, workingDirectory); + var stdout = EvaluateJavaScript(nodeExe, string.Join(";", testFiles), discoverResultFile, logger, projectRoot); if (!string.IsNullOrWhiteSpace(stdout)) { var stdoutLines = stdout.Split(new[] { Environment.NewLine }, @@ -89,7 +89,7 @@ public List FindTests(IEnumerable testFiles, { var line = discoveredTest.Line + 1; var column = discoveredTest.Column + 1; - var test = new NodejsTestInfo(discoveredTest.File, discoveredTest.Test, this.Name, line, column); + var test = new NodejsTestInfo(discoveredTest.File, discoveredTest.Test, this.Name, line, column, projectRoot); testCases.Add(test); } }