Replies: 2 comments
-
In my experience, Vite compilation time does increase as a project grows with more JS and CSS. On a new project, compilation time is sub-second, but I have seen bigger projects take several seconds. I don't think there is a silver bullet, because to run a Capybara test, the frontend assets must be compiled, and that compilation takes time. What I've done as an optimization is to turn off Vite's Here is the relevant part of my {
"test": {
"autoBuild": false,
"publicOutputDir": "vite-test",
"port": 3037
}
} And here is my code: # test/vite_helper.rb
return if ViteRuby.config.auto_build
# Compile assets once at the start of testing
require "benchmark"
seconds = Benchmark.realtime { ViteRuby.commands.build }
puts format("Built Vite assets (%.1fms)", seconds * 1_000) And then I require it at the top of my system test case base class: # test/application_system_test_case.rb
require "test_helper"
require "vite_helper" # <-- compile assets once
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
# ... Even if this doesn't solve the problem, you will at least get benchmark output printed to the console when you run your tests, which will give you an idea of how much time it takes to compile your assets. If everything is working properly, you should only pay the compilation penalty when your JS/CSS files change. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @mattbrictson Setting Meanwhile I have had good experience with |
Beta Was this translation helpful? Give feedback.
-
On a big project, running a single capybara/selenium test is lasting aproximately 8.9 seconds, driven by
headless_chrome
. This is annoying.I cannot say that Vite makes a problem - no - vite seems to be fast - also on capybara!
I set up a test project, and there a test runs within 1.8-2.6 seconds! That would make fun!
See Discussion on discuss.rubyonrails.org.
It seems that the more packages (JS/Styles), the slower the tests.
What are your experiences?
Which configs are important to speed-up a capybara/selenium test on rails/vite?
Many thanks,
Chris
Beta Was this translation helpful? Give feedback.
All reactions