@@ -50,7 +50,105 @@ class CommandsTest < ActiveSupport::TestCase
50
50
assert_equal original , File . read ( "#{ @tmpdir } /dummy/vendor/javascript/md5.js" )
51
51
end
52
52
53
+ test "update command preserves preload false option" do
54
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", preload: false' )
55
+
56
+ out , _err = run_importmap_command ( "update" )
57
+
58
+ assert_includes out , "Pinning"
59
+
60
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
61
+ assert_includes updated_content , "preload: false"
62
+ assert_includes updated_content , "# @2.3.0"
63
+ end
64
+
65
+ test "update command preserves preload true option" do
66
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", preload: true' )
67
+
68
+ out , _err = run_importmap_command ( "update" )
69
+
70
+ assert_includes out , "Pinning"
71
+
72
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
73
+ assert_includes updated_content , "preload: true"
74
+ end
75
+
76
+ test "update command preserves custom preload string option" do
77
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", preload: "custom"' )
78
+
79
+ out , _err = run_importmap_command ( "update" )
80
+
81
+ assert_includes out , "Pinning"
82
+
83
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
84
+ assert_includes updated_content , 'preload: "custom"'
85
+ end
86
+
87
+ test "update command removes existing integrity" do
88
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", integrity: "sha384-oldintegrity"' )
89
+
90
+ out , _err = run_importmap_command ( "update" )
91
+
92
+ assert_includes out , "Pinning"
93
+
94
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
95
+ assert_not_includes updated_content , "integrity:"
96
+ end
97
+
98
+ test "update command only keeps preload option" do
99
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", preload: false, integrity: "sha384-oldintegrity"' )
100
+
101
+ out , _err = run_importmap_command ( "update" )
102
+
103
+ assert_includes out , "Pinning"
104
+
105
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
106
+ assert_includes updated_content , "preload: false"
107
+ assert_not_includes updated_content , "to:"
108
+ assert_not_includes updated_content , "integrity:"
109
+ end
110
+
111
+ test "update command handles packages with different quote styles" do
112
+ importmap_config ( "pin 'md5', to: 'https://cdn.skypack.dev/[email protected] ', preload: false" )
113
+
114
+ out , _err = run_importmap_command ( "update" )
115
+
116
+ assert_includes out , "Pinning"
117
+
118
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
119
+ assert_includes updated_content , "preload: false"
120
+ end
121
+
122
+ test "update command preserves options with version comments" do
123
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", preload: false # @2.2.0' )
124
+
125
+ out , _err = run_importmap_command ( "update" )
126
+
127
+ assert_includes out , "Pinning"
128
+
129
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
130
+ assert_includes updated_content , "preload: false"
131
+ assert_includes updated_content , "# @2.3.0"
132
+ assert_not_includes updated_content , "# @2.2.0"
133
+ end
134
+
135
+ test "update command handles whitespace variations in pin options" do
136
+ importmap_config ( 'pin "md5", to: "https://cdn.skypack.dev/[email protected] ", preload: false ' )
137
+
138
+ out , _err = run_importmap_command ( "update" )
139
+
140
+ assert_includes out , "Pinning"
141
+
142
+ updated_content = File . read ( "#{ @tmpdir } /dummy/config/importmap.rb" )
143
+ assert_equal 4 , updated_content . lines . size
144
+ assert_includes updated_content , "preload: false"
145
+ end
146
+
53
147
private
148
+ def importmap_config ( content )
149
+ File . write ( "#{ @tmpdir } /dummy/config/importmap.rb" , content )
150
+ end
151
+
54
152
def run_importmap_command ( command , *args )
55
153
capture_subprocess_io { system ( "bin/importmap" , command , *args , exception : true ) }
56
154
end
0 commit comments