Vendored modules versioned like the app's own: the 7 /vendor modules our JS imports get importmap entries and maplibre-gl.css, pmtiles and maplibre-contour a ?v=, so a deploy busts them too; a test keeps every imported /vendor module in the importmap
This commit is contained in:
1 parent
a21e2b0bc6
commit
07b623b7ca
2 files changed
+34
-10
No files matched your search
@@ -34,6 +34,19 @@ class AppTest < Minitest::Test
|
||||
end
|
||||
end
|
||||
|
||||
# Same for every /vendor module our own JS imports: one that changes with
|
||||
# the app (mdi.mjs gaining an icon) left cached under the old URL while
|
||||
# its freshly versioned importer asks for a new export is a dead page.
|
||||
def test_every_imported_vendor_module_has_a_versioned_importmap_entry
|
||||
response = request.get("/")
|
||||
sources = Dir.glob(File.join(__dir__, "..", "public", "js", "*.js")).map { |path| File.read(path) }.join("\n")
|
||||
vendor = sources.scan(%r{from\s+"(/vendor/[^"?]+)"}).flatten.uniq
|
||||
refute_empty vendor
|
||||
vendor.each do |path|
|
||||
assert_match(%r{"#{Regexp.escape(path)}":\s*"#{Regexp.escape(path)}\?v=\d+"}, response.body, "#{path} is missing from the importmap")
|
||||
end
|
||||
end
|
||||
|
||||
# Unversioned /vendor modules must be revalidated, or a deploy adding an
|
||||
# export to one (imported by a freshly versioned /js module) breaks a
|
||||
# browser still holding the old copy — see static_cache_control in app.rb.
|
||||
|
||||
Reference in new issue
Block a user