mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #11847 from mkllnk/spec-opt
Avoid precompiling assets unnecessarily
This commit is contained in:
@@ -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
|
||||
|
||||
18
spec/support/precompile_assets.rb
Normal file
18
spec/support/precompile_assets.rb
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user