From e4a0f6d36590e8c5141cd6025006a34f663ea809 Mon Sep 17 00:00:00 2001 From: Noah Gilson Date: Tue, 20 Feb 2024 10:41:35 -0800 Subject: [PATCH] Set test environment variable to prevent double activation When we add activation on startup finished we encountered a new bug with the test process that has existed for many years it will activate twice and the extension will be in a bad state. we need to allow manual activation to inject the correct mock classes into the extension and prevent it from activating on startupfinished under test. --- .../src/extension.ts | 12 +++++++++++ .../DotnetCoreAcquisitionExtension.test.ts | 2 ++ .../src/test/functional/runTest.ts | 20 +++++++++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/vscode-dotnet-runtime-extension/src/extension.ts b/vscode-dotnet-runtime-extension/src/extension.ts index dee152d8..5509e02d 100644 --- a/vscode-dotnet-runtime-extension/src/extension.ts +++ b/vscode-dotnet-runtime-extension/src/extension.ts @@ -87,9 +87,16 @@ const configPrefix = 'dotnetAcquisitionExtension'; const displayChannelName = '.NET Runtime'; const defaultTimeoutValue = 600; const moreInfoUrl = 'https://github.com/dotnet/vscode-dotnet-runtime/blob/main/Documentation/troubleshooting-runtime.md'; +let disableActivationUnderTest = true; export function activate(context: vscode.ExtensionContext, extensionContext?: IExtensionContext) { + + if(process.env['DOTNET_INSTALL_TOOL_UNDER_TEST'] === 'true' && disableActivationUnderTest) + { + return; + } + // Loading Extension Configuration const extensionConfiguration = extensionContext !== undefined && extensionContext.extensionConfiguration ? extensionContext.extensionConfiguration : @@ -416,3 +423,8 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE reportIssueRegistration, ...eventStreamObservers); } + +export function allowManualTestActivation() +{ + disableActivationUnderTest = false; +} \ No newline at end of file diff --git a/vscode-dotnet-runtime-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts b/vscode-dotnet-runtime-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts index f0fc1395..31dede5a 100644 --- a/vscode-dotnet-runtime-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts +++ b/vscode-dotnet-runtime-extension/src/test/functional/DotnetCoreAcquisitionExtension.test.ts @@ -73,6 +73,8 @@ suite('DotnetCoreAcquisitionExtension End to End', function() { extensionPath, logPath, } as any; + + extension.allowManualTestActivation(); extension.activate(extensionContext, { telemetryReporter: new MockTelemetryReporter(), extensionConfiguration: new MockExtensionConfiguration([{extensionId: 'alternative.extension', path: 'foo'}], true), diff --git a/vscode-dotnet-runtime-extension/src/test/functional/runTest.ts b/vscode-dotnet-runtime-extension/src/test/functional/runTest.ts index 49f17e2c..39f7b710 100644 --- a/vscode-dotnet-runtime-extension/src/test/functional/runTest.ts +++ b/vscode-dotnet-runtime-extension/src/test/functional/runTest.ts @@ -33,14 +33,18 @@ async function main() { } // Download VS Code, unzip it and run the integration test - await runTests({ - ...(platformValue !== '' && {platform: platformValue}), - extensionDevelopmentPath, - extensionTestsPath, - launchArgs: [ - // This disables all extensions except the one being testing - '--disable-extensions', - ]}); + await runTests( + { + ...(platformValue !== '' && {platform: platformValue}), + extensionDevelopmentPath, + extensionTestsPath, + launchArgs: [ + // This disables all extensions except the one being testing + '--disable-extensions', + ], + extensionTestsEnv : { DOTNET_INSTALL_TOOL_UNDER_TEST : 'true' } + } + ); } catch (err) { console.error('Failed to run tests'); process.exit(1);