mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-12 09:38:26 +01:00
testing: implement testPreserveFocus API (#210796)
* testing: implement testPreserveFocus API * fix tests
This commit is contained in:
@@ -1661,6 +1661,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
LinkedEditingRanges: extHostTypes.LinkedEditingRanges,
|
||||
TestResultState: extHostTypes.TestResultState,
|
||||
TestRunRequest: extHostTypes.TestRunRequest,
|
||||
TestRunRequest2: extHostTypes.TestRunRequest,
|
||||
TestMessage: extHostTypes.TestMessage,
|
||||
TestTag: extHostTypes.TestTag,
|
||||
TestRunProfileKind: extHostTypes.TestRunProfileKind,
|
||||
|
||||
@@ -210,7 +210,7 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
|
||||
}
|
||||
|
||||
await this.proxy.$runTests({
|
||||
isUiTriggered: false,
|
||||
preserveFocus: (req as vscode.TestRunRequest2).preserveFocus ?? true,
|
||||
targets: [{
|
||||
testIds: req.include?.map(t => TestId.fromExtHostTestItem(t, controller.collection.root.id).toString()) ?? [controller.collection.root.id],
|
||||
profileGroup: profileGroupToBitset[profile.kind],
|
||||
@@ -746,6 +746,7 @@ export class TestRunCoordinator {
|
||||
exclude: request.exclude?.map(t => TestId.fromExtHostTestItem(t, collection.root.id).toString()) ?? [],
|
||||
id: dto.id,
|
||||
include: request.include?.map(t => TestId.fromExtHostTestItem(t, collection.root.id).toString()) ?? [collection.root.id],
|
||||
preserveFocus: (request as vscode.TestRunRequest2).preserveFocus ?? true,
|
||||
persist
|
||||
});
|
||||
|
||||
|
||||
@@ -4018,12 +4018,13 @@ export enum TestRunProfileKind {
|
||||
}
|
||||
|
||||
@es5ClassCompat
|
||||
export class TestRunRequest implements vscode.TestRunRequest {
|
||||
export class TestRunRequest implements vscode.TestRunRequest2 {
|
||||
constructor(
|
||||
public readonly include: vscode.TestItem[] | undefined = undefined,
|
||||
public readonly exclude: vscode.TestItem[] | undefined = undefined,
|
||||
public readonly profile: vscode.TestRunProfile | undefined = undefined,
|
||||
public readonly continuous = false,
|
||||
public readonly preserveFocus = true,
|
||||
) { }
|
||||
}
|
||||
|
||||
|
||||
@@ -752,6 +752,7 @@ suite('ExtHost Testing', () => {
|
||||
exclude: [new TestId(['ctrlId', 'id-b']).toString()],
|
||||
persist: false,
|
||||
continuous: false,
|
||||
preserveFocus: true,
|
||||
}]
|
||||
]);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export class TestingProgressTrigger extends Disposable {
|
||||
}
|
||||
|
||||
private attachAutoOpenForNewResults(result: LiveTestResult) {
|
||||
if (result.request.isUiTriggered === false) {
|
||||
if (result.request.preserveFocus === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ export class TestResultService extends Disposable implements ITestResultService
|
||||
}
|
||||
|
||||
const resolved: ResolvedTestRunRequest = {
|
||||
isUiTriggered: false,
|
||||
preserveFocus: req.preserveFocus,
|
||||
targets: [],
|
||||
exclude: req.exclude,
|
||||
continuous: req.continuous,
|
||||
|
||||
@@ -366,7 +366,7 @@ export class TestService extends Disposable implements ITestService {
|
||||
}
|
||||
|
||||
private async saveAllBeforeTest(req: ResolvedTestRunRequest, configurationService: IConfigurationService = this.configurationService, editorService: IEditorService = this.editorService): Promise<void> {
|
||||
if (req.isUiTriggered === false) {
|
||||
if (req.preserveFocus === true) {
|
||||
return;
|
||||
}
|
||||
const saveBeforeTest = getTestingConfiguration(this.configurationService, TestingConfigKeys.SaveBeforeTest);
|
||||
|
||||
@@ -88,7 +88,7 @@ export interface ResolvedTestRunRequest {
|
||||
/** Whether this is a continuous test run */
|
||||
continuous?: boolean;
|
||||
/** Whether this was trigged by a user action in UI. Default=true */
|
||||
isUiTriggered?: boolean;
|
||||
preserveFocus?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +101,7 @@ export interface ExtensionRunTestsRequest {
|
||||
controllerId: string;
|
||||
profile?: { group: TestRunProfileBitset; id: number };
|
||||
persist: boolean;
|
||||
preserveFocus: boolean;
|
||||
/** Whether this is a result of a continuous test run request */
|
||||
continuous: boolean;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ export const allApiProposals = Object.freeze({
|
||||
terminalSelection: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalSelection.d.ts',
|
||||
terminalShellIntegration: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts',
|
||||
testObserver: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testObserver.d.ts',
|
||||
testPreserveFocus: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testPreserveFocus.d.ts',
|
||||
textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts',
|
||||
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
|
||||
tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts',
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
declare module 'vscode' {
|
||||
|
||||
// See https://github.com/microsoft/vscode/issues/209491
|
||||
|
||||
export class TestRunRequest2 extends TestRunRequest {
|
||||
/**
|
||||
* Controls how test Test Results view is focused. If true, the editor
|
||||
* will keep the maintain the user's focus. If false, the editor will
|
||||
* prefer to move focus into the Test Results view, although
|
||||
* this may be configured by users.
|
||||
*/
|
||||
readonly preserveFocus: boolean;
|
||||
|
||||
/**
|
||||
* @param include Array of specific tests to run, or undefined to run all tests
|
||||
* @param exclude An array of tests to exclude from the run.
|
||||
* @param profile The run profile used for this request.
|
||||
* @param continuous Whether to run tests continuously as source changes.
|
||||
* @param preserveFocus Whether to preserve the user's focus when the run is started
|
||||
*/
|
||||
constructor(include?: readonly TestItem[], exclude?: readonly TestItem[], profile?: TestRunProfile, continuous?: boolean);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user