diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 97fe6201e4fb..067275ad732c 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -411,7 +411,6 @@ export namespace DebugConfigStrings { export namespace Testing { export const configureTests = l10n.t('Configure Test Framework'); - export const testNotConfigured = l10n.t('No test framework configured.'); export const cancelUnittestDiscovery = l10n.t('Canceled unittest test discovery'); export const errorUnittestDiscovery = l10n.t('Unittest test discovery error'); export const cancelPytestDiscovery = l10n.t('Canceled pytest test discovery'); diff --git a/src/client/testing/common/types.ts b/src/client/testing/common/types.ts index 17d528d234f9..562005386633 100644 --- a/src/client/testing/common/types.ts +++ b/src/client/testing/common/types.ts @@ -50,7 +50,6 @@ export interface ITestsHelper { export const ITestConfigurationService = Symbol('ITestConfigurationService'); export interface ITestConfigurationService { hasConfiguredTests(wkspace: Uri): boolean; - displayTestFrameworkError(wkspace: Uri): Promise; selectTestRunner(placeHolderMessage: string): Promise; enableTest(wkspace: Uri, product: UnitTestProduct): Promise; promptToEnableAndConfigureTestFramework(wkspace: Uri): Promise; diff --git a/src/client/testing/configuration/index.ts b/src/client/testing/configuration/index.ts index 4825e9aa4f6a..b78475293594 100644 --- a/src/client/testing/configuration/index.ts +++ b/src/client/testing/configuration/index.ts @@ -40,28 +40,6 @@ export class UnitTestConfigurationService implements ITestConfigurationService { return settings.testing.pytestEnabled || settings.testing.unittestEnabled || false; } - public async displayTestFrameworkError(wkspace: Uri): Promise { - const settings = this.configurationService.getSettings(wkspace); - let enabledCount = settings.testing.pytestEnabled ? 1 : 0; - enabledCount += settings.testing.unittestEnabled ? 1 : 0; - if (enabledCount > 1) { - return this._promptToEnableAndConfigureTestFramework( - wkspace, - 'Enable only one of the test frameworks (unittest or pytest).', - true, - ); - } - const option = 'Enable and configure a Test Framework'; - const item = await this.appShell.showInformationMessage( - 'No test framework configured (unittest, or pytest)', - option, - ); - if (item !== option) { - throw NONE_SELECTED; - } - return this._promptToEnableAndConfigureTestFramework(wkspace); - } - public async selectTestRunner(placeHolderMessage: string): Promise { const items = [ { diff --git a/src/client/testing/main.ts b/src/client/testing/main.ts index 1941ce5e57c2..e794d5711f2a 100644 --- a/src/client/testing/main.ts +++ b/src/client/testing/main.ts @@ -29,7 +29,7 @@ import { DelayedTrigger, IDelayedTrigger } from '../common/utils/delayTrigger'; import { ExtensionContextKey } from '../common/application/contextKeys'; import { checkForFailedTests, updateTestResultMap } from './testController/common/testItemUtilities'; import { Testing } from '../common/utils/localize'; -import { traceVerbose } from '../logging'; +import { traceVerbose, traceWarn } from '../logging'; import { writeTestIdToClipboard } from './utils'; @injectable() @@ -103,22 +103,9 @@ export class UnitTestManagementService implements IExtensionActivationService { if (unconfigured.length === workspaces.length) { const commandManager = this.serviceContainer.get(ICommandManager); await commandManager.executeCommand('workbench.view.testing.focus'); - - // TODO: this is a workaround for https://github.com/microsoft/vscode/issues/130696 - // Once that is fixed delete this notification and test should be configured from the test view. - const app = this.serviceContainer.get(IApplicationShell); - const response = await app.showInformationMessage( - Testing.testNotConfigured, - Testing.configureTests, + traceWarn( + 'Testing: Run attempted but no test configurations found for any workspace, use command palette to configure tests for python if desired.', ); - if (response === Testing.configureTests) { - await commandManager.executeCommand( - constants.Commands.Tests_Configure, - undefined, - constants.CommandSource.ui, - unconfigured[0].uri, - ); - } } }); } diff --git a/src/test/testing/configuration.unit.test.ts b/src/test/testing/configuration.unit.test.ts index 98d19dca9cbc..e259587ecccd 100644 --- a/src/test/testing/configuration.unit.test.ts +++ b/src/test/testing/configuration.unit.test.ts @@ -25,7 +25,7 @@ import { ITestsHelper, } from '../../client/testing/common/types'; import { ITestingSettings } from '../../client/testing/configuration/types'; -import { NONE_SELECTED, UnitTestConfigurationService } from '../../client/testing/configuration'; +import { UnitTestConfigurationService } from '../../client/testing/configuration'; suite('Unit Tests - ConfigurationService', () => { UNIT_TEST_PRODUCTS.forEach((product) => { @@ -259,198 +259,6 @@ suite('Unit Tests - ConfigurationService', () => { enabled = true; expect(testConfigService.target.hasConfiguredTests(workspaceUri)).to.equal(true); }); - test('Prompt to enable a test if a test framework is not enabled', async () => { - unitTestSettings.setup((u) => u.pytestEnabled).returns(() => false); - unitTestSettings.setup((u) => u.unittestEnabled).returns(() => false); - - appShell - .setup((s) => s.showInformationMessage(typeMoq.It.isAny(), typeMoq.It.isAny())) - .returns(() => Promise.resolve(undefined)) - .verifiable(typeMoq.Times.once()); - - let exceptionThrown = false; - try { - await testConfigService.target.displayTestFrameworkError(workspaceUri); - } catch (exc) { - if (exc !== NONE_SELECTED) { - throw exc; - } - exceptionThrown = true; - } - - expect(exceptionThrown).to.be.equal(true, 'Exception not thrown'); - appShell.verifyAll(); - }); - test('Prompt to select a test if a test framework is not enabled', async () => { - unitTestSettings.setup((u) => u.pytestEnabled).returns(() => false); - unitTestSettings.setup((u) => u.unittestEnabled).returns(() => false); - - appShell - .setup((s) => s.showInformationMessage(typeMoq.It.isAny(), typeMoq.It.isAny())) - .returns((_msg, option) => Promise.resolve(option)) - .verifiable(typeMoq.Times.once()); - - let exceptionThrown = false; - let selectTestRunnerInvoked = false; - try { - testConfigService.callBase = false; - testConfigService - .setup((t) => t.selectTestRunner(typeMoq.It.isAny())) - .returns(() => { - selectTestRunnerInvoked = true; - return Promise.resolve(undefined); - }); - await testConfigService.target.displayTestFrameworkError(workspaceUri); - } catch (exc) { - if (exc !== NONE_SELECTED) { - throw exc; - } - exceptionThrown = true; - } - - expect(selectTestRunnerInvoked).to.be.equal(true, 'Method not invoked'); - expect(exceptionThrown).to.be.equal(true, 'Exception not thrown'); - appShell.verifyAll(); - }); - test('Configure selected test framework and disable others', async () => { - unitTestSettings.setup((u) => u.pytestEnabled).returns(() => false); - unitTestSettings.setup((u) => u.unittestEnabled).returns(() => false); - - const workspaceConfig = typeMoq.Mock.ofType( - undefined, - typeMoq.MockBehavior.Strict, - ); - workspaceConfig - .setup((w) => w.get(typeMoq.It.isAny())) - .returns(() => true) - .verifiable(typeMoq.Times.once()); - workspaceService - .setup((w) => w.getConfiguration(typeMoq.It.isValue('python'), workspaceUri)) - .returns(() => workspaceConfig.object) - .verifiable(typeMoq.Times.once()); - - appShell - .setup((s) => s.showInformationMessage(typeMoq.It.isAny(), typeMoq.It.isAny())) - .returns((_msg, option) => Promise.resolve(option)) - .verifiable(typeMoq.Times.once()); - - let selectTestRunnerInvoked = false; - testConfigService.callBase = false; - testConfigService - .setup((t) => t.selectTestRunner(typeMoq.It.isAny())) - .returns(() => { - selectTestRunnerInvoked = true; - return Promise.resolve(product); - }); - - const configMgr = typeMoq.Mock.ofType( - undefined, - typeMoq.MockBehavior.Strict, - ); - factory - .setup((f) => - f.create(typeMoq.It.isValue(workspaceUri), typeMoq.It.isValue(product), typeMoq.It.isAny()), - ) - .returns(() => configMgr.object) - .verifiable(typeMoq.Times.once()); - - configMgr - .setup((c) => c.configure(typeMoq.It.isValue(workspaceUri))) - .returns(() => Promise.resolve()) - .verifiable(typeMoq.Times.once()); - configMgr - .setup((c) => c.enable()) - .returns(() => Promise.resolve()) - .verifiable(typeMoq.Times.once()); - - await testConfigService.target.displayTestFrameworkError(workspaceUri); - - expect(selectTestRunnerInvoked).to.be.equal(true, 'Select Test Runner not invoked'); - appShell.verifyAll(); - factory.verifyAll(); - configMgr.verifyAll(); - workspaceConfig.verifyAll(); - }); - test('If more than one test framework is enabled, then prompt to select a test framework', async () => { - unitTestSettings.setup((u) => u.pytestEnabled).returns(() => true); - unitTestSettings.setup((u) => u.unittestEnabled).returns(() => true); - - appShell - .setup((s) => s.showInformationMessage(typeMoq.It.isAny(), typeMoq.It.isAny())) - .returns(() => Promise.resolve(undefined)) - .verifiable(typeMoq.Times.never()); - appShell - .setup((s) => s.showQuickPick(typeMoq.It.isAny(), typeMoq.It.isAny())) - .returns(() => Promise.resolve(undefined)) - .verifiable(typeMoq.Times.once()); - - let exceptionThrown = false; - try { - await testConfigService.target.displayTestFrameworkError(workspaceUri); - } catch (exc) { - if (exc !== NONE_SELECTED) { - throw exc; - } - exceptionThrown = true; - } - - expect(exceptionThrown).to.be.equal(true, 'Exception not thrown'); - appShell.verifyAll(); - }); - test('If more than one test framework is enabled, then prompt to select a test framework and enable test, but do not configure', async () => { - unitTestSettings.setup((u) => u.pytestEnabled).returns(() => true); - unitTestSettings.setup((u) => u.unittestEnabled).returns(() => true); - - appShell - .setup((s) => s.showInformationMessage(typeMoq.It.isAny(), typeMoq.It.isAny())) - .returns((_msg, option) => Promise.resolve(option)) - .verifiable(typeMoq.Times.never()); - - let selectTestRunnerInvoked = false; - testConfigService.callBase = false; - testConfigService - .setup((t) => t.selectTestRunner(typeMoq.It.isAny())) - .returns(() => { - selectTestRunnerInvoked = true; - return Promise.resolve(product); - }); - - let enableTestInvoked = false; - testConfigService - .setup((t) => t.enableTest(typeMoq.It.isValue(workspaceUri), typeMoq.It.isValue(product))) - .returns(() => { - enableTestInvoked = true; - return Promise.resolve(); - }); - - const configMgr = typeMoq.Mock.ofType( - undefined, - typeMoq.MockBehavior.Strict, - ); - factory - .setup((f) => - f.create(typeMoq.It.isValue(workspaceUri), typeMoq.It.isValue(product), typeMoq.It.isAny()), - ) - .returns(() => configMgr.object) - .verifiable(typeMoq.Times.once()); - - configMgr - .setup((c) => c.configure(typeMoq.It.isValue(workspaceUri))) - .returns(() => Promise.resolve()) - .verifiable(typeMoq.Times.never()); - configMgr - .setup((c) => c.enable()) - .returns(() => Promise.resolve()) - .verifiable(typeMoq.Times.once()); - - await testConfigService.target.displayTestFrameworkError(workspaceUri); - - expect(selectTestRunnerInvoked).to.be.equal(true, 'Select Test Runner not invoked'); - expect(enableTestInvoked).to.be.equal(false, 'Enable Test is invoked'); - factory.verifyAll(); - appShell.verifyAll(); - configMgr.verifyAll(); - }); test('Prompt to enable and configure selected test framework', async () => { unitTestSettings.setup((u) => u.pytestEnabled).returns(() => false);