Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vscode] Support TestRunRequest.preserveFocus #13839

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

rschnekenbu
Copy link
Contributor

@rschnekenbu rschnekenbu commented Jun 24, 2024

What it does

Add a progress service for tests to support activation of views
Support vscode API to listen for test run request preserveFocus:

  • when preserve focus is true, nothing had to be done
  • if preserveFocus is false, then the Test Results view shall be activated.

fixes #13759

contributed on behalf of STMicroelectronics

How to test

  1. Start the theia browser example on master and install the following extension (derived from vscode sample extension test-provider-sample):
  1. When starting extensions from Test UI, nothing should happen (as preserveFocus is always true in this case)
  2. With the PR and the extensions, 2 additional commands are available with the markdown tests: Test Sample: Trigger Tests (preserveFocus: true/false). With the one with true, nothing shall happen also. The Test Result view shall activate when using the command with the false preserve Focus.

Follow-ups

The current implementation may be extended later based on preferences and test results status. In VS Code, when tests are started or failing, the Test Result view or the Test Explorer view can be activated based on user preferences (see https://github.com/microsoft/vscode/blob/f9238dd94a8b54dc3adb274927c7871e7c215300/src/vs/workbench/contrib/testing/browser/testingProgressUiService.ts#L49)

Review checklist

Reminder for reviewers

@rschnekenbu rschnekenbu marked this pull request as ready for review June 24, 2024 12:55
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure about naming here. Maybe $notifyTestRunRequested may be more aligned with the other methods?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for testRunRequested consistency is king.

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First reading of the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for testRunRequested consistency is king.

packages/plugin/src/theia.d.ts Show resolved Hide resolved
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { inject, injectable } from '@theia/core/shared/inversify';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we need this class. Why isn't this handled in TestService?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or alternatively, don't go through the test TestService but notify this service directly from test-main.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had an issue with the architecture there: the test views depend on the TestService, so I could not have the TestService to depend on them.
But yes, I can notify it from test-main.ts. I will propose a new version with TestExecutionProgressService directly used in TestingMain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit has shifted a bit the way it is architectured, as you suggested. TestingMain is directly invoking the progress service and not channeling events through main test service anymore.

packages/plugin-ext/src/plugin/tests.ts Show resolved Hide resolved
@@ -624,4 +625,8 @@ export class TestingMainImpl implements TestingMain {
$notifyTestRunEnded(controllerId: string, runId: string): void {
this.withController(controllerId).withRun(runId).ended();
}

$notifyOnTestRunRequest(preserveFocus: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use $notifyTestRunCreated instead of adding a new notification? A test run starts either at creation or when it's "running" flage changes, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done on new commit.

@injectable()
export class DefaultTestExecutionProgressService implements TestExecutionProgressService {

@inject(WidgetManager)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unused.

protected readonly widgetManager: WidgetManager;

@inject(ApplicationShell)
protected readonly shell: ApplicationShell;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

@inject(TestViewContribution)
protected readonly testView: TestViewContribution;

@inject(TestService)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unused.

@tsmaeder
Copy link
Contributor

@rschnekenbu I have a couple of remarks from testing:

  1. The preferences are in the "Extensions/Testing" section, but IMO should be in "Features/Testing".
  2. When I close the test explorer view, it is not opened when I run the tests with "preserveFocus: false".
  3. Not sure what the distinction is between "openOnStart" and "openExplorerOnStart" 🤷

@rschnekenbu
Copy link
Contributor Author

rschnekenbu commented Jun 26, 2024

I moved the preferences to right place. That is now under Features section.
I removed the openWithTestExplorer, as the option (copied from vs code) is not really obvious given the comment on the d.ts file and in the description of the preference. Now, the 2 options are 'do nothing' or 'open Test Results View'. I kept however the enum choice if we want to expand later the choices to other views.
I also removed unused code left from previous implementation.

@rschnekenbu
Copy link
Contributor Author

A small detail about the test of this feature: Running the tests from the UI should preserve the focus in any case, and not open any views. Only triggering from the extension, with the 'preserveFocus:false' version should open the view if the preference is set for this.

@rschnekenbu rschnekenbu mentioned this pull request Jun 26, 2024
2 tasks
@rschnekenbu rschnekenbu added the vscode issues related to VSCode compatibility label Jun 26, 2024
@tsmaeder
Copy link
Contributor

@rschnekenbu for me revealing the test explorer does not work in this scenario:

  1. Set the preference to openOnTestStart.
  2. Make sure the file explorer view is visible
  3. Invoke `Trigger Test (preserveFocus: false)
  4. Observe: the test explorer view is not revealed.

🤷

@rschnekenbu
Copy link
Contributor Author

@rschnekenbu for me revealing the test explorer does not work in this scenario:

  1. Set the preference to openOnTestStart.
  2. Make sure the file explorer view is visible
  3. Invoke `Trigger Test (preserveFocus: false)
  4. Observe: the test explorer view is not revealed.

🤷

The Test Results View shall open, not the Test Explorer. Is that not the case?

@tsmaeder
Copy link
Contributor

The Test Results View shall open, not the Test Explorer. Is that not the case?

No, the file explorer still is visible.

@tsmaeder
Copy link
Contributor

Cleared this up: The "Test Result View" is the one that shows up in the lower right corner where the terminals, etc. are.

Add a progress service for tests to support activation of views
Forward Test Run to be started event to progress service to activate view if needed

fixes eclipse-theia#13759

contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
@rschnekenbu rschnekenbu merged commit 0e50cfc into eclipse-theia:master Jun 27, 2024
13 of 14 checks passed
@rschnekenbu rschnekenbu deleted the issues/13759 branch June 27, 2024 08:52
@jfaltermeier jfaltermeier added this to the 1.51.0 milestone Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[vscode] Implement TestRunRequest preserveFocus API
3 participants