Skip to content

Commit

Permalink
Add support for TestRunProfile onDidChangeProfile
Browse files Browse the repository at this point in the history
add support to changing default profile in service
add event for isDefault onDidChangeProfile
add command to change default profile

fixes #13354

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>

address review comments

reduce code
  • Loading branch information
rschnekenbu committed Feb 28, 2024
1 parent 8aecd44 commit f1d3e36
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## v1.47.0 not yet released

- [plugin] Add command to install plugins from the command line [#13406](https://github.com/eclipse-theia/theia/issues/13406) - contributed on behalf of STMicroelectronics
- [testing] support TestRunProfile onDidChangeDefault introduced in VS Code 1.86.0 [#13388](https://github.com/eclipse-theia/theia/pull/13388) - contributed on behalf of STMicroelectronics

<a name="breaking_changes_not_yet_released">[Breaking Changes:](#breaking_changes_not_yet_released)</a>
- [monaco] Upgrade Monaco dependency to 1.83.1 [#13217](https://github.com/eclipse-theia/theia/pull/13217)- contributed on behalf of STMicroelectronics\
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,9 @@ export interface TestingExt {
/** Configures a test run config. */
$onConfigureRunProfile(controllerId: string, profileId: string): void;

/** Sets the default on a given run profile */
$onDidChangeDefault(controllerId: string, profileId: string, isDefault: boolean): void;

$onRunControllerTests(reqs: TestRunRequestDTO[]): void;

/** Asks the controller to refresh its tests */
Expand Down
13 changes: 11 additions & 2 deletions packages/plugin-ext/src/main/browser/test-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,16 @@ function itemToPath(item: TestItem): string[] {
class TestRunProfileImpl implements TestRunProfile {

label: string;
isDefault: boolean;

private _isDefault: boolean;
set isDefault(isDefault: boolean) {
this._isDefault = isDefault;
this.proxy.$onDidChangeDefault(this.controllerId, this.id, isDefault);
}
get isDefault(): boolean {
return this._isDefault;
}

tag: string;
canConfigure: boolean;

Expand All @@ -205,7 +214,7 @@ class TestRunProfileImpl implements TestRunProfile {
}

if ('isDefault' in update) {
this.isDefault = update.isDefault!;
this._isDefault = update.isDefault!;
}

if ('tag' in update) {
Expand Down
33 changes: 31 additions & 2 deletions packages/plugin-ext/src/plugin/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ export class TestingExtImpl implements TestingExt {
this.controllersById.get(controllerId)?.getProfile(profileId)?.configureHandler?.();
}

/** @inheritdoc */
$onDidChangeDefault(controllerId: string, profileId: string, isDefault: boolean): void {
const profile = this.controllersById.get(controllerId)?.getProfile(profileId);
if (profile) {
profile.doSetDefault(isDefault);
}
}

/** @inheritdoc */
async $refreshTests(controllerId: string, token: CancellationToken): Promise<void> {
await this.withController(controllerId).refreshHandler?.(token);
Expand Down Expand Up @@ -483,8 +491,29 @@ export class TestRunProfile implements theia.TestRunProfile {
@observableProperty('notifyPropertyChange')
label: string;

@observableProperty('notifyPropertyChange')
isDefault: boolean;
_isDefault: boolean;

get isDefault(): boolean {
return this._isDefault;
}

set isDefault(isDefault: boolean) {
if (this.doSetDefault(isDefault)) {
this.proxy.$updateTestRunProfile(this.controllerId, this.profileId, { isDefault: isDefault });
}
}

doSetDefault(isDefault: boolean): boolean {
if (this._isDefault !== isDefault) {
this._isDefault = isDefault;
this.onDidChangeDefaultEmitter.fire(isDefault);
return true;
}
return false;
}

private onDidChangeDefaultEmitter = new Emitter<boolean>();
onDidChangeDefault = this.onDidChangeDefaultEmitter.event;

@observableProperty('notifyTagChange')
tag: theia.TestTag | undefined;
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15979,9 +15979,18 @@ export module '@theia/plugin' {
* the generic "run all" button, then the default profile for
* {@link TestRunProfileKind.Run} will be executed, although the
* user can configure this.
*
* Changes the user makes in their default profiles will be reflected
* in this property after a {@link onDidChangeDefault} event.
*/
isDefault: boolean;

/**
* Fired when a user has changed whether this is a default profile. The
* event contains the new value of {@link isDefault}
*/
onDidChangeDefault: Event<boolean>;

/**
* Whether this profile supports continuous running of requests. If so,
* then {@link TestRunRequest.continuous} may be set to `true`. Defaults
Expand Down
36 changes: 34 additions & 2 deletions packages/test/src/browser/test-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export enum TestRunProfileKind {
export interface TestRunProfile {
readonly kind: TestRunProfileKind;
readonly label: string,
readonly isDefault: boolean;
isDefault: boolean;
readonly canConfigure: boolean;
readonly tag: string;
run(name: string, included: readonly TestItem[], excluded: readonly TestItem[]): void;
Expand Down Expand Up @@ -177,6 +177,7 @@ export interface TestController {
export interface TestService {
clearResults(): void;
configureProfile(): void;
selectDefaultProfile(): void;
runTestsWithProfile(tests: TestItem[]): void;
runTests(profileKind: TestRunProfileKind, tests: TestItem[]): void;
runAllTests(profileKind: TestRunProfileKind): void;
Expand Down Expand Up @@ -304,7 +305,7 @@ export class DefaultTestService implements TestService {
}
return {
iconClasses,
label: profile.label,
label: `${profile.label}${profile.isDefault ? ' (default)' : ''}`,
profile: profile
};
});
Expand All @@ -313,6 +314,22 @@ export class DefaultTestService implements TestService {

}

protected async pickProfileKind(): Promise<TestRunProfileKind | undefined> {
// eslint-disable-next-line arrow-body-style
const picks = [{
iconClasses: codiconArray('run'),
label: 'Run',
kind: TestRunProfileKind.Run
}, {
iconClasses: codiconArray('debug-alt'),
label: 'Debug',
kind: TestRunProfileKind.Debug
}];

return (await this.quickpickService.show(picks, { title: 'Select the kind of profiles' }))?.kind;

}

runTests(profileKind: TestRunProfileKind, items: TestItem[]): void {
groupBy(items, item => item.controller).forEach((tests, controller) => {
if (controller) {
Expand All @@ -333,6 +350,21 @@ export class DefaultTestService implements TestService {
});
}

selectDefaultProfile(): void {
this.pickProfileKind().then(kind => {
const profiles = this.getControllers().flatMap(c => c.testRunProfiles).filter(profile => profile.kind === kind);
this.pickProfile(profiles, nls.localizeByDefault('Pick a test profile to use')).then(activeProfile => {
if (activeProfile) {
// only change the default for the controller containing selected profile for default and its profiles with same kind
const controller = this.getControllers().find(c => c.testRunProfiles.includes(activeProfile));
controller?.testRunProfiles.filter(profile => profile.kind === activeProfile.kind).forEach(profile => {
profile.isDefault = profile === activeProfile;
});
}
});
});
}

configureProfile(): void {
const profiles: TestRunProfile[] = [];

Expand Down
19 changes: 19 additions & 0 deletions packages/test/src/browser/view/test-view-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export namespace TestViewCommands {
category: 'Test'
});

export const SELECT_DEFAULT_PROFILES: Command = Command.toDefaultLocalizedCommand({
id: TestCommandId.SelectDefaultTestProfiles,
label: 'Select Default Test Profiles...',
category: 'Test'
});

export const CLEAR_ALL_RESULTS: Command = Command.toDefaultLocalizedCommand({
id: TestCommandId.ClearTestResultsAction,
label: 'Clear All Results',
Expand Down Expand Up @@ -186,6 +192,14 @@ export class TestViewContribution extends AbstractViewContribution<TestTreeWidge
}
});

commands.registerCommand(TestViewCommands.SELECT_DEFAULT_PROFILES, {
isEnabled: t => TestItem.is(t),
isVisible: t => TestItem.is(t),
execute: () => {
this.testService.selectDefaultProfile();
}
});

commands.registerCommand(TestViewCommands.DEBUG_TEST, {
isEnabled: t => TestItem.is(t),
isVisible: t => TestItem.is(t),
Expand Down Expand Up @@ -254,6 +268,11 @@ export class TestViewContribution extends AbstractViewContribution<TestTreeWidge
commandId: TestViewCommands.RUN_TEST_WITH_PROFILE.id,
order: 'aaaa'
});

menus.registerMenuAction(TEST_VIEW_CONTEXT_MENU, {
commandId: TestViewCommands.SELECT_DEFAULT_PROFILES.id,
order: 'aaaaa'
});
}

registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
Expand Down

0 comments on commit f1d3e36

Please sign in to comment.