@@ -8,6 +8,9 @@ def setup
88 pin "editor" , to : "rich_text.js" , preload : false
99 pin "not_there" , to : "nowhere.js" , preload : false
1010 pin "md5" , to : "https://cdn.skypack.dev/md5" , preload : true
11+ pin "leaflet" , to : "https://cdn.skypack.dev/leaflet" , preload : 'application'
12+ pin "chartkick" , to : "https://cdn.skypack.dev/chartkick" , preload : [ 'application' , 'alternate' ]
13+ pin "tinyMCE" , to : "https://cdn.skypack.dev/tinymce" , preload : 'alternate'
1114
1215 pin_all_from "app/javascript/controllers" , under : "controllers" , preload : true
1316 pin_all_from "app/javascript/spina/controllers" , under : "controllers/spina" , preload : true
@@ -78,10 +81,32 @@ def setup
7881 end
7982 end
8083
81- test "preloaded modules are included in preload tags" do
84+ test "preloaded modules are included in preload tags when no entry_point specified " do
8285 preloading_module_paths = @importmap . preloaded_module_paths ( resolver : ApplicationController . helpers ) . to_s
8386 assert_match /md5/ , preloading_module_paths
8487 assert_match /goodbye_controller/ , preloading_module_paths
88+ assert_match /leaflet/ , preloading_module_paths
89+ assert_no_match /application/ , preloading_module_paths
90+ assert_no_match /tinymce/ , preloading_module_paths
91+ end
92+
93+ test "preloaded modules are included in preload tags based on single entry_point provided" do
94+ preloading_module_paths = @importmap . preloaded_module_paths ( resolver : ApplicationController . helpers , entry_point : "alternate" ) . to_s
95+ assert_no_match /leaflet/ , preloading_module_paths
96+ assert_match /tinymce/ , preloading_module_paths
97+ assert_match /chartkick/ , preloading_module_paths
98+ assert_match /md5/ , preloading_module_paths
99+ assert_match /goodbye_controller/ , preloading_module_paths
100+ assert_no_match /application/ , preloading_module_paths
101+ end
102+
103+ test "preloaded modules are included in preload tags based on multiple entry_points provided" do
104+ preloading_module_paths = @importmap . preloaded_module_paths ( resolver : ApplicationController . helpers , entry_point : [ "application" , "alternate" ] ) . to_s
105+ assert_match /leaflet/ , preloading_module_paths
106+ assert_match /tinymce/ , preloading_module_paths
107+ assert_match /chartkick/ , preloading_module_paths
108+ assert_match /md5/ , preloading_module_paths
109+ assert_match /goodbye_controller/ , preloading_module_paths
85110 assert_no_match /application/ , preloading_module_paths
86111 end
87112
0 commit comments