Skip to content

Commit 5ae5a74

Browse files
authored
testing: implement testPreserveFocus API (microsoft#210796)
* testing: implement testPreserveFocus API * fix tests
1 parent 8c172fc commit 5ae5a74

File tree

10 files changed

+40
-6
lines changed

10 files changed

+40
-6
lines changed

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
16611661
LinkedEditingRanges: extHostTypes.LinkedEditingRanges,
16621662
TestResultState: extHostTypes.TestResultState,
16631663
TestRunRequest: extHostTypes.TestRunRequest,
1664+
TestRunRequest2: extHostTypes.TestRunRequest,
16641665
TestMessage: extHostTypes.TestMessage,
16651666
TestTag: extHostTypes.TestTag,
16661667
TestRunProfileKind: extHostTypes.TestRunProfileKind,

src/vs/workbench/api/common/extHostTesting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
210210
}
211211

212212
await this.proxy.$runTests({
213-
isUiTriggered: false,
213+
preserveFocus: (req as vscode.TestRunRequest2).preserveFocus ?? true,
214214
targets: [{
215215
testIds: req.include?.map(t => TestId.fromExtHostTestItem(t, controller.collection.root.id).toString()) ?? [controller.collection.root.id],
216216
profileGroup: profileGroupToBitset[profile.kind],
@@ -746,6 +746,7 @@ export class TestRunCoordinator {
746746
exclude: request.exclude?.map(t => TestId.fromExtHostTestItem(t, collection.root.id).toString()) ?? [],
747747
id: dto.id,
748748
include: request.include?.map(t => TestId.fromExtHostTestItem(t, collection.root.id).toString()) ?? [collection.root.id],
749+
preserveFocus: (request as vscode.TestRunRequest2).preserveFocus ?? true,
749750
persist
750751
});
751752

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4018,12 +4018,13 @@ export enum TestRunProfileKind {
40184018
}
40194019

40204020
@es5ClassCompat
4021-
export class TestRunRequest implements vscode.TestRunRequest {
4021+
export class TestRunRequest implements vscode.TestRunRequest2 {
40224022
constructor(
40234023
public readonly include: vscode.TestItem[] | undefined = undefined,
40244024
public readonly exclude: vscode.TestItem[] | undefined = undefined,
40254025
public readonly profile: vscode.TestRunProfile | undefined = undefined,
40264026
public readonly continuous = false,
4027+
public readonly preserveFocus = true,
40274028
) { }
40284029
}
40294030

src/vs/workbench/api/test/browser/extHostTesting.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ suite('ExtHost Testing', () => {
752752
exclude: [new TestId(['ctrlId', 'id-b']).toString()],
753753
persist: false,
754754
continuous: false,
755+
preserveFocus: true,
755756
}]
756757
]);
757758

src/vs/workbench/contrib/testing/browser/testingProgressUiService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class TestingProgressTrigger extends Disposable {
3131
}
3232

3333
private attachAutoOpenForNewResults(result: LiveTestResult) {
34-
if (result.request.isUiTriggered === false) {
34+
if (result.request.preserveFocus === true) {
3535
return;
3636
}
3737

src/vs/workbench/contrib/testing/common/testResultService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class TestResultService extends Disposable implements ITestResultService
149149
}
150150

151151
const resolved: ResolvedTestRunRequest = {
152-
isUiTriggered: false,
152+
preserveFocus: req.preserveFocus,
153153
targets: [],
154154
exclude: req.exclude,
155155
continuous: req.continuous,

src/vs/workbench/contrib/testing/common/testServiceImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export class TestService extends Disposable implements ITestService {
366366
}
367367

368368
private async saveAllBeforeTest(req: ResolvedTestRunRequest, configurationService: IConfigurationService = this.configurationService, editorService: IEditorService = this.editorService): Promise<void> {
369-
if (req.isUiTriggered === false) {
369+
if (req.preserveFocus === true) {
370370
return;
371371
}
372372
const saveBeforeTest = getTestingConfiguration(this.configurationService, TestingConfigKeys.SaveBeforeTest);

src/vs/workbench/contrib/testing/common/testTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface ResolvedTestRunRequest {
8888
/** Whether this is a continuous test run */
8989
continuous?: boolean;
9090
/** Whether this was trigged by a user action in UI. Default=true */
91-
isUiTriggered?: boolean;
91+
preserveFocus?: boolean;
9292
}
9393

9494
/**
@@ -101,6 +101,7 @@ export interface ExtensionRunTestsRequest {
101101
controllerId: string;
102102
profile?: { group: TestRunProfileBitset; id: number };
103103
persist: boolean;
104+
preserveFocus: boolean;
104105
/** Whether this is a result of a continuous test run request */
105106
continuous: boolean;
106107
}

src/vs/workbench/services/extensions/common/extensionsApiProposals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export const allApiProposals = Object.freeze({
115115
terminalSelection: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalSelection.d.ts',
116116
terminalShellIntegration: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalShellIntegration.d.ts',
117117
testObserver: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testObserver.d.ts',
118+
testPreserveFocus: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testPreserveFocus.d.ts',
118119
textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts',
119120
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
120121
tokenInformation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tokenInformation.d.ts',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'vscode' {
7+
8+
// See https://github.com/microsoft/vscode/issues/209491
9+
10+
export class TestRunRequest2 extends TestRunRequest {
11+
/**
12+
* Controls how test Test Results view is focused. If true, the editor
13+
* will keep the maintain the user's focus. If false, the editor will
14+
* prefer to move focus into the Test Results view, although
15+
* this may be configured by users.
16+
*/
17+
readonly preserveFocus: boolean;
18+
19+
/**
20+
* @param include Array of specific tests to run, or undefined to run all tests
21+
* @param exclude An array of tests to exclude from the run.
22+
* @param profile The run profile used for this request.
23+
* @param continuous Whether to run tests continuously as source changes.
24+
* @param preserveFocus Whether to preserve the user's focus when the run is started
25+
*/
26+
constructor(include?: readonly TestItem[], exclude?: readonly TestItem[], profile?: TestRunProfile, continuous?: boolean);
27+
}
28+
}

0 commit comments

Comments
 (0)