Module: EvilSystems::PrecompileAssets

Defined in:
lib/evil_systems/precompile_assets.rb

Class Method Summary collapse

Class Method Details

.initial_setup(task: "assets:precompile", silent: true) ⇒ Object

Precompile assets before running tests to avoid timeouts. Do not precompile if webpack-dev-server is running (NOTE: MUST be launched with RAILS_ENV=test)

Parameters:

  • task (String, nil) (defaults to: "assets:precompile")

    (“assets:precompile”) - the precompile task to run

  • silent (Boolean) (defaults to: true)

    (true) - silence build output and only show asset compilation and time spent compiling.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/evil_systems/precompile_assets.rb', line 9

def self.initial_setup(task: "assets:precompile", silent: true)
  $stdout.puts "\n🐢  Precompiling assets.\n"
  original_stdout = $stdout.clone
  start = Time.current
  begin
    # Silence output
    $stdout.reopen(File.new("/dev/null", "w")) if silent == true
    # next 3 lines to compile assets before running our test suite
    require "rake"
    Rails.application.load_tasks
    Rake::Task[task].invoke if task
  ensure
    $stdout.reopen(original_stdout) if silent == true
    $stdout.puts "Finished in #{(Time.current - start).round(2)} seconds"
  end
end