If I run tests with bin/rails test
it triggers yarn to run twice, once for esbuild and once for css. If I run all the same tests with bin/rails test test/**/**.rb
or bin/rails test test/
the tests run instantly.
Why is this happening when I'm not running System Tests)?
Versions: Rails 7.1.1, Ruby 3.2.2, Minitest 5.20.0
App created with rails new my_app --javascript esbuild --css bootstrap
My test helper doesn't seem to be calling rails test:prepare
or anything else that triggers yarn:
# test/test_helper.rb
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
module ActiveSupport
class TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
end
I've tried to go through each require
d file in test_helper.rb
and can't find anywhere else that yarn/assets/precompilation is being told to happen:
../config/environment
❌
config/application
❌
config/boot
❌rails/all
❓ (didn't even know where to begin)rails/test_help
❓ (read through source but only looked in to one of the things it requires)
active_support/testing/autorun
❌ (source)I also tried bundle open minitest
on the off chance something is configured there but I poked around a bit and couldn't see anything relevant.
Where is the yarn/asset-compilation "magic" configured for tests?
"My test helper doesn't seem to be calling
rails test:prepare
"
When you call rails test
without any arguments it calls test:prepare
for you Source
run_prepare_task if self.args.none?(EXACT_TEST_ARGUMENT_PATTERN)
and Source
Rails::Command::RakeCommand.perform("test:prepare", [], {})
As Noted in the Upgrade Guide
When running tests via
bin/rails test
, therake test:prepare
task will run before tests run. If you've enhanced thetest:prepare
task, your enhancements will run before your tests.tailwindcss-rails
,jsbundling-rails
, andcssbundling-rails
enhance this task, as do other third party gems.
You can see that this indeed builds yarn
Cssbundling and Jsbundling