Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion src/client/testing/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export interface ITestsHelper {
export const ITestConfigurationService = Symbol('ITestConfigurationService');
export interface ITestConfigurationService {
hasConfiguredTests(wkspace: Uri): boolean;
displayTestFrameworkError(wkspace: Uri): Promise<void>;
selectTestRunner(placeHolderMessage: string): Promise<UnitTestProduct | undefined>;
enableTest(wkspace: Uri, product: UnitTestProduct): Promise<void>;
promptToEnableAndConfigureTestFramework(wkspace: Uri): Promise<void>;
Expand Down
22 changes: 0 additions & 22 deletions src/client/testing/configuration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,6 @@ export class UnitTestConfigurationService implements ITestConfigurationService {
return settings.testing.pytestEnabled || settings.testing.unittestEnabled || false;
}

public async displayTestFrameworkError(wkspace: Uri): Promise<void> {
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<UnitTestProduct | undefined> {
const items = [
{
Expand Down
19 changes: 3 additions & 16 deletions src/client/testing/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -103,22 +103,9 @@ export class UnitTestManagementService implements IExtensionActivationService {
if (unconfigured.length === workspaces.length) {
const commandManager = this.serviceContainer.get<ICommandManager>(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>(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,
);
}
}
});
}
Expand Down
194 changes: 1 addition & 193 deletions src/test/testing/configuration.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<WorkspaceConfiguration>(
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<ITestConfigurationManager>(
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<ITestConfigurationManager>(
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);
Expand Down