Skip to content

Commit 3a70034

Browse files
author
Paul van Brenk
committed
Fix resolution of TestFrameworks folder
1 parent cd1fd76 commit 3a70034

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

Nodejs/Product/Nodejs/TestFrameworks/TestFrameworkDirectories.cs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,64 @@
33
using System;
44
using System.Collections.Generic;
55
using System.IO;
6+
using System.Linq;
67

78
namespace Microsoft.NodejsTools.TestFrameworks
89
{
910
internal class TestFrameworkDirectories
1011
{
1112
public const string ExportRunnerFramework = "ExportRunner";
1213
private const string TestFrameworksDirectory = "TestFrameworks";
14+
private const string TestAdapterDirectory = "TestAdapter";
1315

14-
private readonly Dictionary<string, string> _frameworkDirectories;
16+
private readonly Dictionary<string, string> frameworkDirectories;
1517

1618
public TestFrameworkDirectories()
1719
{
18-
this._frameworkDirectories = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
19-
foreach (var directory in Directory.GetDirectories(GetBaseTestframeworkFolder()))
20+
this.frameworkDirectories = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
21+
22+
var testFrameworkRoot = GetTestframeworkFolderRoot();
23+
if(!Directory.Exists(testFrameworkRoot))
24+
{
25+
throw new InvalidOperationException("Unable to find test framework folder");
26+
}
27+
28+
foreach (var directory in Directory.GetDirectories(testFrameworkRoot))
2029
{
2130
var name = Path.GetFileName(directory);
22-
this._frameworkDirectories.Add(name, directory);
31+
this.frameworkDirectories.Add(name, directory);
2332
}
24-
string defaultFx;
25-
this._frameworkDirectories.TryGetValue(ExportRunnerFramework, out defaultFx);
26-
if (defaultFx == null)
33+
34+
if (!this.frameworkDirectories.TryGetValue(ExportRunnerFramework, out var defaultFx) || string.IsNullOrEmpty(defaultFx))
2735
{
2836
throw new InvalidOperationException("Missing generic test framework");
2937
}
3038
}
3139

32-
public List<string> GetFrameworkNames()
33-
{
34-
return new List<string>(this._frameworkDirectories.Keys);
35-
}
40+
public List<string> GetFrameworkNames() => this.frameworkDirectories.Keys.ToList();
3641

37-
public List<string> GetFrameworkDirectories()
38-
{
39-
return new List<string>(this._frameworkDirectories.Values);
40-
}
42+
public List<string> GetFrameworkDirectories() => this.frameworkDirectories.Values.ToList();
4143

42-
private static string GetBaseTestframeworkFolder()
44+
private static string GetTestframeworkFolderRoot()
4345
{
44-
var installFolder = GetExecutingAssemblyPath();
45-
var baseDirectory = Path.Combine(installFolder, TestFrameworksDirectory);
46+
// This class is used in 2 different assemblies, installed in 2 locations:
47+
//
48+
// "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\Extensions\Microsoft\NodeJsTools\NodeJsTools\Microsoft.NodejsTools.dll"
49+
// and
50+
// "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\Extensions\Microsoft\NodeJsTools\TestAdapter\Microsoft.NodejsTools.TestAdapter.dll"
51+
//
52+
// However in both cases, we should just go up a folder to the nodejstools root, and then into the TestAdapter folder.
53+
54+
var currentAssembly = typeof(TestFrameworkDirectories).Assembly;
55+
var currentAssemblyFolder = Path.GetDirectoryName(currentAssembly.Location);
56+
var nodejsRootFolder = Path.GetDirectoryName(currentAssemblyFolder);
57+
58+
var baseDirectory = Path.Combine(nodejsRootFolder, TestAdapterDirectory, TestFrameworksDirectory);
4659
#if DEBUG
4760
// To allow easier debugging of the test adapter, try to use the local directory as a fallback.
4861
baseDirectory = Directory.Exists(baseDirectory) ? baseDirectory : Path.Combine(Directory.GetCurrentDirectory(), TestFrameworksDirectory);
4962
#endif
5063
return baseDirectory;
5164
}
52-
53-
private static string GetExecutingAssemblyPath()
54-
{
55-
var codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
56-
var uri = new UriBuilder(codeBase);
57-
var path = Uri.UnescapeDataString(uri.Path);
58-
return Path.GetDirectoryName(path);
59-
}
6065
}
6166
}

Nodejs/Product/TestAdapter/TestAdapter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</Reference>
8383
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
8484
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
85-
<Private>True</Private>
85+
<Private>False</Private>
8686
</Reference>
8787
<Reference Include="PresentationCore" />
8888
<Reference Include="PresentationFramework" />

Nodejs/Product/TestAdapterShim/AssemblyResolver.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static string GetVSInstallDir()
2020
var vsTestFrameworkAssembly = typeof(ITestExecutor).Assembly;
2121
var testAdapterPath = vsTestFrameworkAssembly.Location;
2222

23-
// C:\Program Files (x86)\Microsoft Visual Studio\2017\VSUJSLT\Common7\IDE\CommonExtensions\Microsoft\NodeJs Tools Unit Test Adapter\Microsoft.nodejstools.TestAdapter.dll
23+
// C:\Program Files (x86)\Microsoft Visual Studio\2017\VSUJSLT\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll
2424
var indexOfCommon7Ide = testAdapterPath.IndexOf("common7", StringComparison.OrdinalIgnoreCase);
2525
string vsInstallDir = testAdapterPath.Substring(0, indexOfCommon7Ide);
2626

@@ -31,12 +31,12 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
3131
{
3232
// Use the setup API to find the VS install Dir, then build paths to the Private and Public Assemblies folders
3333
var installPath = GetVSInstallDir();
34-
var ideFolder = Path.Combine(installPath, "Common7\\IDE");
34+
var ideFolder = Path.Combine(installPath, "Common7", "IDE");
3535
var paths = new[] {
3636
Path.Combine(ideFolder, "PrivateAssemblies"),
3737
Path.Combine(ideFolder, "PublicAssemblies"),
38-
Path.Combine(installPath, "MSBuild\\15.0\\Bin"),
39-
Path.Combine(ideFolder, "CommonExtensions\\Microsoft\\WebClient\\Project System") };
38+
Path.Combine(installPath, "MSBuild","15.0","Bin"),
39+
Path.Combine(ideFolder, "CommonExtensions","Microsoft","WebClient","Project System") };
4040

4141
// This is what comes in for args.Name, but we really just want the dll file name:
4242
// "Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
@@ -45,7 +45,7 @@ private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
4545
foreach (var path in paths)
4646
{
4747
// Check under privateAssemblies
48-
if (AssemblyResolver.ResolveAssemblyPath(path, resolveTargetAssemblyName, out var resolvedAssembly))
48+
if (ResolveAssemblyPath(path, resolveTargetAssemblyName, out var resolvedAssembly))
4949
{
5050
return resolvedAssembly;
5151
}

0 commit comments

Comments
 (0)