// We do this to preload all files but actually require
// only those matching the pattern.

<%
  spec_location = Rails.root.join(Rails.application.config.opal_rspec.spec_location)

  # Preload all files from `config.opal_rspec.spec_location`
  entries = []
  Dir["#{spec_location}/**"].map do |p|
    relative_path = Pathname(p).relative_path_from(spec_location)
    entries << relative_path
    depend_on relative_path
  end

  # …and all files in `config.opal_rspec.preload`
  entries += Rails.application.config.opal_rspec.preload
  entries.each { |entry| require_asset entry }
%>

Opal.gvars.spec_files = <%= entries.to_json %>;


// We do this to preload all files but actually require
// only those matching the pattern.

<%
  spec_location = Rails.root.join(Rails.application.config.opal_rspec.spec_location)
  reload_file = spec_location.join('reload.txt')
  reload_file.write('Touch this file to reload the list of specs after adding new files') unless reload_file.exist?

  # Preload all files from `config.opal_rspec.spec_location`
  entries = []
  Dir["#{spec_location}/**.rb"].map do |p|
    relative_path = Pathname(p).relative_path_from(spec_location)
    entries << relative_path.to_s
    depend_on relative_path.to_s
  end

  # …and all files in `config.opal_rspec.preload`
  entries += Rails.application.config.opal_rspec.preload
  entries.each { |entry| require_asset entry }
%>

Opal.gvars.spec_files = <%= entries.to_json %>;


Add a spec_files list reloader
Add a spec_files list reloader