ruby-lsp-rspec
ruby-lsp-rspec copied to clipboard
"Run" vs "Run in terminal" time gap
Hello Stan Thank you for showing me your extension at RubyKaigi.
There's a significant time gap between the "Run" and "Run in terminal".
It looks like the entire app restart for each individual test. Is there a way to optimize the "Run" task?
Normally the 2 should use the same command to run tests, which theoretically should have similar duration. Can you provide more information? Like the actual commands being invoked?
One possibility is that the one runs in terminal utilizes spring, while the one runs in test explorer doesn’t.
It runs each tests individually. I'm on Rails 6.1.7.8, rspec-rails (6.1.2), rspec-core (3.13.0), VScode 1.90.0, MacOS 14.5 on ARM (M1)
Run in terminal:
bundle exec rspec /Users/thomas/project/spec/lib/csv_imports_lib/things_spec.rb:3
Run:
Run options: include {:locations=>{"./spec/lib/csv_imports_lib/things_spec.rb"=>[324]}}
.
Finished in 0.19813 seconds (files took 10.59 seconds to load)
1 example, 0 failures
Coverage report generated for RSpec to /Users/thomas/project/coverage. 175 / 564 LOC (31.03%) covered.
Run options: include {:locations=>{"./spec/lib/csv_imports_lib/things_spec.rb"=>[307]}}
.
Finished in 0.02762 seconds (files took 3.81 seconds to load)
1 example, 0 failures
Coverage report generated for RSpec to /Users/thomas/project/coverage. 144 / 562 LOC (25.62%) covered.
Run options: include {:locations=>{"./spec/lib/csv_imports_lib/things_spec.rb"=>[292]}}
.
Finished in 0.11977 seconds (files took 3.81 seconds to load)
1 example, 0 failures
Coverage report generated for RSpec to /Users/thomas/project/coverage. 254 / 1408 LOC (18.04%) covered.
Run options: include {:locations=>{"./spec/lib/csv_imports_lib/things_spec.rb"=>[272]}}
.
Finished in 0.20968 seconds (files took 3.8 seconds to load)
1 example, 0 failures
Coverage report generated for RSpec to /Users/thomas/project/coverage. 267 / 1408 LOC (18.96%) covered.
Run options: include {:locations=>{"./spec/lib/csv_imports_lib/things_spec.rb"=>[250]}}
.
[...]
I'm seeing this too.
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [x86_64-linux]
Rails 7.1.3.3
Via terminal:
Run options: include {:locations=>{"./spec/controllers/application_controller_spec.rb"=>[5]}}
.....................
Finished in 0.56302 seconds (files took 5.79 seconds to load)
21 examples, 0 failures
Via test explorer:
Fix for this would be great, makes the "Run" command pretty useless for larger spec files.
@st0012 I confirmed that this problem that occurs with latest ruby-lsp (0.20.1) and ruby-lsp-rspec (0.1.16) using Ruby 3.3.5 and Rails 7.0.8.5. How and where does the rspec is called?
The main plugin has an open issue for this: https://github.com/Shopify/ruby-lsp/issues/2402
The test execution loop in the extension is here. It will execute anything marked with the 'example' tag. But it will also enqueue any children of that node to be potentially run. So even if we changed the codelens response from the rspec extension to tag the context/describe codelens commands with 'example', the current extension code would still run the children in their own processes.
and then there is the issue of how to pluck the success/error responses from the stdout of the test and properly populate the test explorer ui.
it looks like someone tried to do it for minitest but gave up, and the maintainers from shopify claim its on their roadmap to address eventually.
Here is permalink of the test execution loop.
https://github.com/Shopify/ruby-lsp/blob/4604785d2fb964b0e19dd72774c1568b840cf4db/vscode/src/testController.ts#L256
A new feature on both Ruby LSP and this addon is going to address this soon:
https://github.com/user-attachments/assets/2d704169-65cd-497d-8266-53d680c747c8
Thanks!!! Can we get a new release?
FYI: it has been released in v0.1.23
This works much better.
Though, it can take a long time to discover all the tests initially if you have a lot of tests.