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

Start discovering all available tests lazily #3120

Merged

Conversation

vinistock
Copy link
Member

@vinistock vinistock commented Jan 31, 2025

Motivation

This is the first step in addressing several test explorer related issues that we currently have open.

This PR implements lazy test discovery up until the file level.

Implementation

The VS Code API for the explorer supports lazily discovering tests by implementing the resolveHandler. I essentially only implement two resolutions:

  1. If there's only one workspace folder, we eager discover all test files in the workspace
  2. If there are many workspace folders, then the first level in the hierarchy are the workspaces themselves. If you open any of them, then it triggers resolution and we discover all available tests in that workspace

The tests are discovered using the VS Code findFiles API, which is very efficient and will avoid having us implement an indexing-like mechanism in the server. Since the test explorer is VS Code only anyway, this should be fine.

I also considered two levels of hierarchy for tests (in addition to the workspace when there are many). The firsts level is the test/spec/features directory. Since there may be many of them in an application split by components, we need to have that level of grouping.

The second level is the immediate subdirectory of the test/spec/features directory, which in a Rails app normally accounts for models, controllers and so on. This hierarchy is useful because it will allow users to take actions like running all tests in a workspace, test directory or all tests of a kind (e.g.: models).

Notes

This PR doesn't yet implement the resolution of the test files themselves. The approach we will take for that is asking the server for which tests are available in a file, which gives us the opportunity to include add-on listeners in the discovery.

Since the implementation is still partial, I put a new under development feature flag.

Automated Tests

Added tests.

Manual tests

Enable this under development flag

{
  "rubyLsp.featureFlags": {
    "newTestExperience": true
  }
}

Then start the extension on this branch and navigate tests

demo.mov

@vinistock vinistock requested review from andyw8 and st0012 January 31, 2025 17:42
@vinistock vinistock self-assigned this Jan 31, 2025
@vinistock vinistock added enhancement New feature or request vscode This pull request should be included in the VS Code extension's release notes labels Jan 31, 2025 — with Graphite App
Copy link
Member Author

vinistock commented Jan 31, 2025


How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vinistock vinistock marked this pull request as ready for review January 31, 2025 17:51
@vinistock vinistock requested a review from a team as a code owner January 31, 2025 17:51
@vinistock vinistock force-pushed the 01-31-start_discovering_all_available_tests_lazily branch from bb3d40b to ed5685c Compare January 31, 2025 17:52
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Is it possible to expand test/controllers/foo_controller_test.rb in the test explorer when I opened foo_controller_test.rb in the editor? Similar to how VS Code would expand the file explorer based on the currently opened file.
Not a blocker for the PR but it'd be a very useful feature IMO.

vscode/src/testController.ts Outdated Show resolved Hide resolved
vscode/package.json Show resolved Hide resolved
@vinistock vinistock force-pushed the 01-31-start_discovering_all_available_tests_lazily branch from ed5685c to b0f99fc Compare January 31, 2025 19:51
vscode/src/common.ts Outdated Show resolved Hide resolved
@vinistock vinistock force-pushed the 01-31-start_discovering_all_available_tests_lazily branch from b0f99fc to a63d395 Compare January 31, 2025 20:32
@vinistock
Copy link
Member Author

Is it possible to expand test/controllers/foo_controller_test.rb in the test explorer when I opened foo_controller_test.rb in the editor?

Yes! Added that. Note that you need to have clicked on the explorer first, to lazily populate the tests. We don't force the explorer to reveal, but if you're already there, we focus on the current test.

@vinistock vinistock force-pushed the 01-31-allow_for_under_development_feature_flags branch from c2ba939 to baabe7d Compare January 31, 2025 20:34
@vinistock vinistock force-pushed the 01-31-start_discovering_all_available_tests_lazily branch from a63d395 to 077b2cc Compare January 31, 2025 20:34
@vinistock vinistock changed the base branch from 01-31-allow_for_under_development_feature_flags to graphite-base/3120 February 3, 2025 13:53
@vinistock vinistock force-pushed the 01-31-start_discovering_all_available_tests_lazily branch from 077b2cc to a523375 Compare February 3, 2025 14:18
@vinistock vinistock changed the base branch from graphite-base/3120 to main February 3, 2025 14:19
@vinistock vinistock force-pushed the 01-31-start_discovering_all_available_tests_lazily branch 2 times, most recently from ec861f4 to c76d5d4 Compare February 7, 2025 20:41
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

Tested it in Core, IRB, RDoc, and ruby-lsp-rspec. All worked as expected 👍

One non-blocking suggestion, I think the experience would be better if it can automatically expand results to the first level having multiple results.

For example, in IRB I needed to expand test and then irb even though both of them are the only item on their level.

Screenshot 2025-02-07 at 21 32 50

@vinistock vinistock added the graphite-merge Ship this PR using Graphite's merge queue label Feb 7, 2025
Copy link
Member Author

vinistock commented Feb 7, 2025

Merge activity

  • Feb 7, 4:55 PM EST: The merge label 'graphite-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 7, 5:24 PM EST: A user merged this pull request with the Graphite merge queue.

### Motivation

This is the first step in addressing several test explorer related issues that we currently have open.

This PR implements lazy test discovery up until the file level.

### Implementation

The VS Code API for the explorer supports lazily discovering tests by implementing the `resolveHandler`. I essentially only implement two resolutions:

1. If there's only one workspace folder, we eager discover all test files in the workspace
2. If there are many workspace folders, then the first level in the hierarchy are the workspaces themselves. If you open any of them, then it triggers resolution and we discover all available tests in that workspace

The tests are discovered using the VS Code `findFiles` API, which is very efficient and will avoid having us implement an indexing-like mechanism in the server. Since the test explorer is VS Code only anyway, this should be fine.

I also considered two levels of hierarchy for tests (in addition to the workspace when there are many). The firsts level is the `test/spec/features` directory. Since there may be many of them in an application split by components, we need to have that level of grouping.

The second level is the immediate subdirectory of the `test/spec/features` directory, which in a Rails app normally accounts for `models`, `controllers` and so on. This hierarchy is useful because it will allow users to take actions like running all tests in a workspace, test directory or all tests of a kind (e.g.: models).

### Notes

This PR doesn't yet implement the resolution of the test files themselves. The approach we will take for that is asking the server for which tests are available in a file, which gives us the opportunity to include add-on listeners in the discovery.

Since the implementation is still partial, I put a new under development feature flag.

### Automated Tests

Added tests.

### Manual tests

Enable this under development flag
```json
{
  "rubyLsp.featureFlags": {
    "newTestExperience": true
  }
}
```
Then start the extension on this branch and navigate tests

https://github.com/user-attachments/assets/1aaf145a-7b8f-48bf-b30b-61f0eef3e039
@graphite-app graphite-app bot force-pushed the 01-31-start_discovering_all_available_tests_lazily branch from c76d5d4 to 37eb419 Compare February 7, 2025 21:58
@graphite-app graphite-app bot merged commit 37eb419 into main Feb 7, 2025
42 checks passed
@graphite-app graphite-app bot deleted the 01-31-start_discovering_all_available_tests_lazily branch February 7, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request graphite-merge Ship this PR using Graphite's merge queue vscode This pull request should be included in the VS Code extension's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants