Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Nodejs/Product/TestAdapterImpl/TestDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ private void DiscoverTests(Dictionary<string, List<TestFileEntry>> 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;
}

var fileList = testItems[testFx];
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)
{
Expand Down
36 changes: 14 additions & 22 deletions Nodejs/Product/TestAdapterImpl/TestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -228,7 +226,8 @@ private void RunTestCases(IEnumerable<TestCase> 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);
Expand Down Expand Up @@ -372,8 +371,8 @@ select connection.LocalEndPoint.Port

private IEnumerable<string> 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);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -522,3 +513,4 @@ public TestCaseObject(string framework, string testName, string testFile, string
public string workingFolder { get; set; }
public string projectFolder { get; set; }
}

22 changes: 18 additions & 4 deletions Nodejs/Product/TestAdapterImpl/TestFrameworks/NodejsTestInfo.cs
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we already had GetRelativeFilePath? Sweet!

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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public TestFramework(string vsixScriptFolder)
public List<NodejsTestInfo> FindTests(IEnumerable<string> 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 },
Expand Down Expand Up @@ -89,7 +89,7 @@ public List<NodejsTestInfo> FindTests(IEnumerable<string> 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);
}
}
Expand Down