33using System ;
44using System . Collections . Generic ;
55using System . Diagnostics ;
6+ using Microsoft . NodejsTools ;
67using Microsoft . VisualStudio ;
8+ using Microsoft . VisualStudio . Shell ;
79using Microsoft . VisualStudio . Shell . Flavor ;
810using Microsoft . VisualStudio . Shell . Interop ;
911using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
@@ -79,6 +81,14 @@ private static string GetAggregateProjectTypeGuids(this IVsProject project)
7981 /// </summary>
8082 public static bool IsTestProject ( this IVsProject project , Guid projectGuid )
8183 {
84+ // Overload IsTestProject method to check if we should use this test adapter
85+ // at all. This is much less error prone than adding this check to all locations
86+ // where this method is called.
87+ if ( ! IsTestAdapaterEnabled ( ) )
88+ {
89+ return false ;
90+ }
91+
8292 ValidateArg . NotNull ( project , "project" ) ;
8393
8494 var projectTypeGuids = project . GetAggregateProjectTypeGuids ( ) ;
@@ -87,6 +97,27 @@ public static bool IsTestProject(this IVsProject project, Guid projectGuid)
8797 return ( projectTypeGuids . IndexOf ( projectGuid . ToString ( ) , StringComparison . OrdinalIgnoreCase ) >= 0 ) ;
8898 }
8999
100+ private static bool checkedRegistryForTestAdapterEnabled = false ;
101+ private static bool registryValueForTestAdapterEnabled = true ;
102+
103+ public static bool IsTestAdapaterEnabled ( )
104+ {
105+ if ( ! checkedRegistryForTestAdapterEnabled )
106+ {
107+ using ( var nodeKey = VSRegistry . RegistryRoot ( __VsLocalRegistryType . RegType_UserSettings , true ) . CreateSubKey ( NodejsConstants . BaseRegistryKey ) )
108+ using ( var optionsKey = nodeKey . CreateSubKey ( "Options" ) )
109+ using ( var categoryKey = optionsKey . CreateSubKey ( "testing" ) )
110+ {
111+ // If the value is set to something we disable this testadapter
112+ registryValueForTestAdapterEnabled = string . IsNullOrEmpty ( categoryKey . GetValue ( "testadapter" ) as string ) ;
113+ }
114+
115+ checkedRegistryForTestAdapterEnabled = true ;
116+ }
117+
118+ return registryValueForTestAdapterEnabled ;
119+ }
120+
90121 /// <summary>
91122 /// Gets the project home directory.
92123 /// </summary>
0 commit comments