From 2df72d06978eb9790a8023f6e1f06df1ec18201a Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 13 Sep 2018 13:33:29 +0200 Subject: [PATCH] Fix building assets in test environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Webpacker (Ruby wrapper to webpack) uses RAILS_ENV-based environments while the javascript configuration for webpack re-reads this configuration file using the NODE_ENV environment variable. This means that when RAILS_ENV=test, running “assets:precompile” compiled the production packs in “public/packs” while webpacker expects them in “public/packs-test”. This causes Ruby to recompile them on-the-fly, possibly leading to race conditions in parallel_tests. This changes: - Disables on-the-fly compilation in test environment - Changes the javascript part to read the correct environment --- config/webpack/configuration.js | 2 +- config/webpacker.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/webpack/configuration.js b/config/webpack/configuration.js index 4d0d28582af..f81d23dd497 100644 --- a/config/webpack/configuration.js +++ b/config/webpack/configuration.js @@ -8,7 +8,7 @@ const glob = require('glob'); const configPath = resolve('config', 'webpacker.yml'); const loadersDir = join(__dirname, 'loaders'); -const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV]; +const settings = safeLoad(readFileSync(configPath), 'utf8')[env.RAILS_ENV || env.NODE_ENV]; const flavourFiles = glob.sync('app/javascript/flavours/*/theme.yml'); const skinFiles = glob.sync('app/javascript/skins/*/*'); const flavours = {}; diff --git a/config/webpacker.yml b/config/webpacker.yml index 50d95813a54..c0f91c4e436 100644 --- a/config/webpacker.yml +++ b/config/webpacker.yml @@ -28,6 +28,10 @@ test: # Compile test packs to a separate directory public_output_path: packs-test + # CircleCI precompiles packs prior to running the tests. + # Also avoids race conditions in parallel_tests. + compile: false + production: <<: *default