Sha256: 4f2cbe614e1ebcb0ee4e769c6014611918f7e0eb8c3f027df2442cc3b84cf977

Contents?: true

Size: 1.88 KB

Versions: 28

Compression:

Stored size: 1.88 KB

Contents

require "test_helper"

class CompilerTest < Minitest::Test
  def remove_compilation_digest_path
    Webpacker.compiler.send(:compilation_digest_path).tap do |path|
      path.delete if path.exist?
    end
  end

  def setup
    remove_compilation_digest_path
  end

  def teardown
    remove_compilation_digest_path
  end

  def test_custom_environment_variables
    assert_nil Webpacker.compiler.send(:webpack_env)["FOO"]
    Webpacker.compiler.env["FOO"] = "BAR"
    assert Webpacker.compiler.send(:webpack_env)["FOO"] == "BAR"
  ensure
    Webpacker.compiler.env = {}
  end

  def test_freshness
    assert Webpacker.compiler.stale?
    assert !Webpacker.compiler.fresh?
  end

  def test_compile
    assert !Webpacker.compiler.compile
  end

  def test_freshness_on_compile_success
    status = OpenStruct.new(success?: true)

    assert Webpacker.compiler.stale?
    Open3.stub :capture3, [:sterr, :stdout, status] do
      Webpacker.compiler.compile
      assert Webpacker.compiler.fresh?
    end
  end

  def test_freshness_on_compile_fail
    status = OpenStruct.new(success?: false)

    assert Webpacker.compiler.stale?
    Open3.stub :capture3, [:sterr, :stdout, status] do
      Webpacker.compiler.compile
      assert Webpacker.compiler.fresh?
    end
  end

  def test_compilation_digest_path
    assert_equal Webpacker.compiler.send(:compilation_digest_path).basename.to_s, "last-compilation-digest-#{Webpacker.env}"
  end

  def test_external_env_variables
    assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"]
    assert_nil Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"]

    ENV["WEBPACKER_ASSET_HOST"] = "foo.bar"
    ENV["WEBPACKER_RELATIVE_URL_ROOT"] = "/baz"
    assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_ASSET_HOST"], "foo.bar"
    assert_equal Webpacker.compiler.send(:webpack_env)["WEBPACKER_RELATIVE_URL_ROOT"], "/baz"
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
shakapacker-6.2.1 test/compiler_test.rb
shakapacker-6.2.0 test/compiler_test.rb
shakapacker-6.1.1 test/compiler_test.rb
shakapacker-6.1.0 test/compiler_test.rb
shakapacker-6.1.0.beta.0 test/compiler_test.rb
shakapacker-6.0.2 test/compiler_test.rb
shakapacker-6.0.1 test/compiler_test.rb
shakapacker-6.0.0 test/compiler_test.rb
shakapacker-6.0.0.rc.14 test/compiler_test.rb
shakapacker-6.0.0.rc.13 test/compiler_test.rb
shakapacker-6.0.0.rc.12 test/compiler_test.rb
shakapacker-6.0.0.rc.6 test/compiler_test.rb
webpacker-6.0.0.rc.6 test/compiler_test.rb
webpacker-6.0.0.rc.5 test/compiler_test.rb
webpacker-6.0.0.rc.4 test/compiler_test.rb
webpacker-6.0.0.rc.3 test/compiler_test.rb
webpacker-6.0.0.rc.2 test/compiler_test.rb
webpacker-6.0.0.rc.1 test/compiler_test.rb
webpacker-6.0.0.beta.7 test/compiler_test.rb
webpacker-6.0.0.beta.6 test/compiler_test.rb