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

Test: TestRunRequest.preserveFocus API #213601

Closed
2 tasks done
connor4312 opened this issue May 28, 2024 · 2 comments
Closed
2 tasks done

Test: TestRunRequest.preserveFocus API #213601

connor4312 opened this issue May 28, 2024 · 2 comments

Comments

@connor4312
Copy link
Member

connor4312 commented May 28, 2024

Refs: #209491

Complexity: 3

Create Issue


We've added a preserveFocus API on the TestRunRequest, which can be used to create test runs.

  1. You can start with the selfhost test provider (open that folder as your workspace, then F5 and open the VS Code repo.)
  2. Contribute a command that, when invoked, calls ctrl.createTestRun to run tests. (Or manually invoke the profile.runHandler)
  3. On the request that you create to pass into ctrl.createTestRun, validate the behavior of the new preserveFocus boolean behaves as expected. Read through the docstring and make sure it makes sense.
@aiday-mar
Copy link
Contributor

Hey @connor4312 I am testing this issue currently and I modified the repo so that on line 91, we have:

const newReq: vscode.TestRunRequest = { ...req, preserveFocus: false };
const task = ctrl.createTestRun(newReq);

In this way the request uses preserveFocus: false when running the tests for the testing profiles that already exist. Am I correct in understanding that by executing the action Run with Electron, the focus should now move to the test results view? I am finding it hard to determine if the focus is on the test results view as there does not appear to be a distinct change of focus when you click on the test results view in the terminal.

Screen.Recording.2024-05-28.at.15.16.27.mov

I am doing this because I previously tried running ctrl.createTestRun from a command with my custom vscode.TestRunRequest as follows:

const req: vscode.TestRunRequest = { include: undefined, exclude: undefined, profile: undefined, preserveFocus: false};
const task = ctrl.createTestRun(req);

But running my custom command would hang for 5 minutes with no apparent progress. So I was trying to reuse the existing code.

@connor4312
Copy link
Member Author

connor4312 commented May 28, 2024

This property controls whether focus is transferred when the test run is triggered outside of the normal VS Code UI, e.g. by a custom command. I don't think copying newReq alone will show the correct behavior, because there is also a request out from VS Code itself and focus handling is already done.

The second case is actually fine, you just want to end the run yourself -- it's not automatically dispatched for you. Having an empty test run is sufficient for testing this behavior, so you can do:

vscode.commands.registerCommand('hello-world', () => {
	const req = new vscode.TestRunRequest(
		undefined,
		undefined,
		runProfile,
		false,
		/* preserveFocus= */ true
	);

	ctrl.createTestRun(req).end();
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants