|
| 1 | +require "test_helper" |
| 2 | +require "propshaft/manifest" |
| 3 | + |
| 4 | +class Propshaft::ManifestTest < ActiveSupport::TestCase |
| 5 | + test "serializes to the extensible manifest format with integrity hash value" do |
| 6 | + manifest = create_manifest("sha384") |
| 7 | + parsed_manifest = JSON.parse(manifest.to_json) |
| 8 | + |
| 9 | + manifest_entry = parsed_manifest["one.txt"] |
| 10 | + assert_equal "one-f2e1ec14.txt", manifest_entry["digested_path"] |
| 11 | + assert_equal "sha384-LdS8l2QTAF8bD8WPb8QSQv0skTWHhmcnS2XU5LBkVQneGzqIqnDRskQtJvi7ADMe", manifest_entry["integrity"] |
| 12 | + |
| 13 | + manifest_entry = parsed_manifest["another.css"] |
| 14 | + assert_equal "another-c464b1ee.css", manifest_entry["digested_path"] |
| 15 | + assert_equal "sha384-RZLbo+FZ8rnE9ct6dNqDcgIYo7DBk/GaB4nCMnNsj6HWp0ePV8q8qky9Qemdpuwl", manifest_entry["integrity"] |
| 16 | + end |
| 17 | + |
| 18 | + test "serializes to the extensible manifest format without integrity hash algorithm" do |
| 19 | + manifest = create_manifest |
| 20 | + parsed_manifest = JSON.parse(manifest.to_json) |
| 21 | + |
| 22 | + manifest_entry = parsed_manifest["one.txt"] |
| 23 | + assert_equal "one-f2e1ec14.txt", manifest_entry["digested_path"] |
| 24 | + assert_nil manifest_entry["integrity"] |
| 25 | + |
| 26 | + manifest_entry = parsed_manifest["another.css"] |
| 27 | + assert_equal "another-c464b1ee.css", manifest_entry["digested_path"] |
| 28 | + assert_nil manifest_entry["integrity"] |
| 29 | + end |
| 30 | + |
| 31 | + private |
| 32 | + def create_manifest(integrity_hash_algorithm = nil) |
| 33 | + Propshaft::Manifest.new(integrity_hash_algorithm:).tap do |manifest| |
| 34 | + manifest.push_asset(find_asset("one.txt")) |
| 35 | + manifest.push_asset(find_asset("another.css")) |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + def find_asset(logical_path) |
| 40 | + root_path = Pathname.new("#{__dir__}/../fixtures/assets/first_path") |
| 41 | + path = root_path.join(logical_path) |
| 42 | + |
| 43 | + assembly = Propshaft::Assembly.new(ActiveSupport::OrderedOptions.new.tap { |config| |
| 44 | + config.paths = [ root_path ] |
| 45 | + config.compilers = [[ "text/css", Propshaft::Compiler::CssAssetUrls ]] |
| 46 | + }) |
| 47 | + |
| 48 | + Propshaft::Asset.new(path, logical_path: logical_path, load_path: assembly.load_path) |
| 49 | + end |
| 50 | +end |
0 commit comments