<commit_before>require "webpacker_test_helper"

class ConfigurationTest < Minitest::Test
  def test_source_path
    source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
    assert_equal source_path, Webpacker.config.source_path.to_s
  end

  def test_source_entry_path
    source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
    assert_equal Webpacker.config.source_entry_path.to_s, source_entry_path
  end

  def test_public_output_path
    public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
    assert_equal Webpacker.config.public_output_path.to_s, public_output_path
  end

  def test_public_manifest_path
    public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
    assert_equal Webpacker.config.public_manifest_path.to_s, public_manifest_path
  end

  def test_cache_path
    cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/cache/webpacker").to_s
    assert_equal Webpacker.config.cache_path.to_s, cache_path
  end

  def test_compile?
    assert Webpacker.config.compile?
  end
end<commit_msg>Test `config.compile?` in all envs<commit_after>require "webpacker_test_helper"

class ConfigurationTest < Minitest::Test
  def test_source_path
    source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
    assert_equal source_path, Webpacker.config.source_path.to_s
  end

  def test_source_entry_path
    source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "packs").to_s
    assert_equal Webpacker.config.source_entry_path.to_s, source_entry_path
  end

  def test_public_output_path
    public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
    assert_equal Webpacker.config.public_output_path.to_s, public_output_path
  end

  def test_public_manifest_path
    public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
    assert_equal Webpacker.config.public_manifest_path.to_s, public_manifest_path
  end

  def test_cache_path
    cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/cache/webpacker").to_s
    assert_equal Webpacker.config.cache_path.to_s, cache_path
  end

  def test_compile?
    with_node_env("development") do
      assert reloaded_config.compile?
    end

    with_node_env("test") do
      assert reloaded_config.compile?
    end

    with_node_env("production") do
      refute reloaded_config.compile?
    end
  end

  private
    def with_node_env(env)
      original = ENV["NODE_ENV"]
      ENV["NODE_ENV"] = env
      yield
    ensure
      ENV["NODE_ENV"] = original
    end

    def reloaded_config
      Webpacker.instance.instance_variable_set(:@config, nil)
      Webpacker.config
    end
end
{'fraction_non_alphanumeric': 0.08767851212221853, 'fraction_numerical': 0.0, 'mean_word_length': 4.726235741444867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '91305', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1010, 'n_words': 160}