Browse Source

Fix building assets in test environment (#8691)

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
ThibG 1 year ago
parent
commit
7fa4144d48
2 changed files with 5 additions and 1 deletions
  1. 1
    1
      config/webpack/configuration.js
  2. 4
    0
      config/webpacker.yml

+ 1
- 1
config/webpack/configuration.js View File

@@ -7,7 +7,7 @@ const { readFileSync } = require('fs');
7 7
 
8 8
 const configPath = resolve('config', 'webpacker.yml');
9 9
 const loadersDir = join(__dirname, 'loaders');
10
-const settings = safeLoad(readFileSync(configPath), 'utf8')[env.NODE_ENV];
10
+const settings = safeLoad(readFileSync(configPath), 'utf8')[env.RAILS_ENV || env.NODE_ENV];
11 11
 
12 12
 const themePath = resolve('config', 'themes.yml');
13 13
 const themes = safeLoad(readFileSync(themePath), 'utf8');

+ 4
- 0
config/webpacker.yml View File

@@ -40,6 +40,10 @@ test:
40 40
   # Compile test packs to a separate directory
41 41
   public_output_path: packs-test
42 42
 
43
+  # CircleCI precompiles packs prior to running the tests.
44
+  # Also avoids race conditions in parallel_tests.
45
+  compile: false
46
+
43 47
 production:
44 48
   <<: *default
45 49