-
Notifications
You must be signed in to change notification settings - Fork 183
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
Ensure we index non test files under test directories #3188
base: main
Are you sure you want to change the base?
Ensure we index non test files under test directories #3188
Conversation
How to use the Graphite Merge QueueAdd 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. |
541b20f
to
0e44b1d
Compare
0e44b1d
to
af8bce2
Compare
|
||
# Don't exclude the special files, unless they are under fixtures or inside a gem installed inside of the | ||
# workspace | ||
if excluded_from_ignore_test_files.include?(File.basename(path)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a complex conditional, I think we can improve it by extracting out some helper methods or explaining variables.
File.join("spec", "**", "*"), | ||
File.join("test", "**", "*"), | ||
File.join("tmp", "**", "*"), | ||
"**/{test,spec,features}/**/{*_test.rb,test_*.rb,*_spec.rb,*.feature}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.feature
files don't contain Ruby code, is there any need to list them here?
end | ||
|
||
@included_patterns = T.let([File.join("**", "*.rb")], T::Array[String]) | ||
excluded_directories = ["tmp", "node_modules", "sorbet"] | ||
top_level_directories = Dir.glob("#{Dir.pwd}/*").filter_map do |path| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could extract top_level_directories
to a method to avoid making initializer
longer.
Motivation
I noticed something with #3180. We can only accurately linearize ancestors for test files if we index files under the test directories that aren't tests, but support implementations.
For example, in our own codebase, we have
lib/ruby_indexer/test/test_case.rb
, which is not a test, but implements the parent class for all tests in the indexer. If we never index that parent class, it's impossible to linearize the ancestors of any of the tests and we can't discover them properly.Implementation
I propose we start indexing non test files inside the test directory. In addition to allowing our improved test functionality to work, users often refer to these support declarations when writing the tests themselves.
I also simplified the code, which was hard to follow, while still trying to maintain the original performance gains applied by recent changes.
One small thing is that I couldn't think of a decent way to not exclude
test_case
andtest_helper
from indexing, since both of them are common names that may declare test parent classes and match our file exclusion glob. I created a special case to handle them.I benchmarked this and it makes no substantial difference in indexing time in Core.
Automated Tests
Added a test verifying the behaviour changes.