Sha256: d0f8d6b28f78481ccfadf7f6f26a3892250994b9ea26d625836e2ca66a47177c

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require "webpacker_test"

class ManifestTest < Minitest::Test
  def test_file_path
    file_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test", "manifest.json").to_s
    assert_equal WebpackerHelpers::Manifest.file_path.to_s, file_path
  end

  def test_file_not_existing
    begin
      file_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test", "manifest.json")
      temp_path = "#{file_path}.backup"
      FileUtils.mv(file_path, temp_path)
      # Point of this test is to ensure no crash
      WebpackerHelpers::Manifest.load_instance
      assert_equal({}, WebpackerHelpers::Manifest.instance.data)
    ensure
      FileUtils.mv(temp_path, file_path)
    end
  end

  def test_lookup_exception
    manifest_path = File.join(File.dirname(__FILE__), "test_app/public/webpack/test", "manifest.json").to_s
    asset_file = "calendar.js"
    msg = <<-MSG
        WebpackerHelpers can't find #{asset_file} in your manifest #{manifest_path}. Possible causes:
          1. You are hot reloading.
          2. Webpack has not re-run to reflect updates.
          3. You have misconfigured WebpackerHelpers's config/webpacker_helpers.yml file.
          4. Your Webpack configuration is not creating a manifest.
    MSG

    error = assert_raises WebpackerHelpers::FileLoader::NotFoundError do
      WebpackerHelpers::Manifest.lookup!(asset_file)
    end

    assert_equal error.message, msg
  end

  def test_lookup_success
    asset_file = "bootstrap.js"
    assert_equal WebpackerHelpers::Manifest.lookup!(asset_file), "bootstrap-300631c4f0e0f9c865bc.js"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webpacker_helpers-3.0.0.beta.1 test/manifest_test.rb