From a23171ea512d55f278e014b1c68c1c871d11a2fb Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 14 Jun 2021 20:22:17 +0100 Subject: [PATCH] Compile Webpacker assets only once in test environment --- config/webpacker.yml | 16 +++++++--------- spec/spec_helper.rb | 6 ++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/config/webpacker.yml b/config/webpacker.yml index f966a6ac93..dccab3e4ab 100644 --- a/config/webpacker.yml +++ b/config/webpacker.yml @@ -71,15 +71,7 @@ development: watch_options: ignored: '**/node_modules/**' - -test: - <<: *default - compile: true - - # Compile test packs to a separate directory - public_output_path: packs-test - -production: +production: &production <<: *default # Production depends on precompilation of packs prior to booting for performance. @@ -90,3 +82,9 @@ production: # Cache manifest.json for performance cache_manifest: true + +test: + <<: *production + + # Compile test packs to a separate directory + public_output_path: packs-test diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b975f5aff7..c912bb80d1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -55,6 +55,12 @@ RSpec.configure do |config| Capybara.reset_sessions! end + # 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' }