Merge pull request #11847 from mkllnk/spec-opt

Avoid precompiling assets unnecessarily
This commit is contained in:
David Cook
2023-11-24 09:16:50 +11:00
committed by GitHub
3 changed files with 18 additions and 29 deletions

View File

@@ -4,12 +4,6 @@ require 'base_spec_helper'
require 'database_cleaner'
RSpec.configure do |config|
# Precompile Webpacker assets (once) when starting the suite. The default setup can result
# in the assets getting compiled many times throughout the build, slowing it down.
config.before :suite do
Webpacker.compile
end
# Fix encoding issue in Rails 5.0; allows passing empty arrays or hashes as params.
config.before(:each, type: :controller) { @request.env["CONTENT_TYPE"] = 'application/json' }
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
RSpec.configure do |config|
config.before(:suite) do
# We can use webpack-dev-server for tests, too!
# Useful if you working on a frontend code fixes and want to verify them via system tests.
next if Webpacker.dev_server.running?
specs_needing_assets = %i[controller feature mailer request system view]
examples = RSpec.world.filtered_examples.values.flatten
types = examples.map(&:metadata).pluck(:type).uniq
if types.intersect?(specs_needing_assets)
$stdout.puts "\n Precompiling assets.\n"
Webpacker.compile
end
end
end

View File

@@ -1,23 +0,0 @@
# frozen_string_literal: true
RSpec.configure do |config|
# Skip assets precompilcation if we exclude system specs.
# For example, you can run all non-system tests via the following command:
#
# rspec --tag ~type:system
#
# In this case, we don't need to precompile assets.
next if
config.filter.opposite.rules[:type] == "system" ||
config.exclude_pattern.match?(%r{spec/system})
config.before(:suite) do
# We can use webpack-dev-server for tests, too!
# Useful if you working on a frontend code fixes and want to verify them via system tests.
next if Webpacker.dev_server.running?
$stdout.puts "\n Precompiling assets.\n"
Webpacker.compile
end
end