Skip to content
Merged
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
31 changes: 31 additions & 0 deletions Common/Product/TestAdapter/VsProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.NodejsTools;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Flavor;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand Down Expand Up @@ -79,6 +81,14 @@ private static string GetAggregateProjectTypeGuids(this IVsProject project)
/// </summary>
public static bool IsTestProject(this IVsProject project, Guid projectGuid)
{
// Overload IsTestProject method to check if we should use this test adapter
// at all. This is much less error prone than adding this check to all locations
// where this method is called.
if (!IsTestAdapaterEnabled())
{
return false;
}

ValidateArg.NotNull(project, "project");

var projectTypeGuids = project.GetAggregateProjectTypeGuids();
Expand All @@ -87,6 +97,27 @@ public static bool IsTestProject(this IVsProject project, Guid projectGuid)
return (projectTypeGuids.IndexOf(projectGuid.ToString(), StringComparison.OrdinalIgnoreCase) >= 0);
}

private static bool checkedRegistryForTestAdapterEnabled = false;
private static bool registryValueForTestAdapterEnabled = true;

public static bool IsTestAdapaterEnabled()
{
if (!checkedRegistryForTestAdapterEnabled)
{
using (var nodeKey = VSRegistry.RegistryRoot(__VsLocalRegistryType.RegType_UserSettings, true).CreateSubKey(NodejsConstants.BaseRegistryKey))
using (var optionsKey = nodeKey.CreateSubKey("Options"))
using (var categoryKey = optionsKey.CreateSubKey("testing"))
{
// If the value is set to something we disable this testadapter
registryValueForTestAdapterEnabled = string.IsNullOrEmpty(categoryKey.GetValue("testadapter") as string);
}

checkedRegistryForTestAdapterEnabled = true;
}

return registryValueForTestAdapterEnabled;
}

/// <summary>
/// Gets the project home directory.
/// </summary>
Expand Down