@@ -139,6 +139,19 @@ mod tests {
139139 ) ;
140140 }
141141
142+ #[ test]
143+ fn tsjs_script_src_is_stable_for_identical_module_ids ( ) {
144+ let module_ids = [ "core" , "lockr" , "permutive" ] ;
145+ let src = tsjs_script_src ( & module_ids) ;
146+
147+ assert_sha256_hex_hash ( hash_query_value ( & src) ) ;
148+ assert_eq ! (
149+ src,
150+ tsjs_script_src( & module_ids) ,
151+ "should produce a stable URL for identical module IDs"
152+ ) ;
153+ }
154+
142155 #[ test]
143156 fn tsjs_script_tag_wraps_source_in_single_trustedserver_tag ( ) {
144157 let module_ids = [ "creative" ] ;
@@ -219,4 +232,38 @@ mod tests {
219232 "should preserve caller-provided deferred module order"
220233 ) ;
221234 }
235+
236+ #[ test]
237+ fn tsjs_unified_script_src_and_tag_include_cache_busting_hash ( ) {
238+ let src = tsjs_unified_script_src ( ) ;
239+
240+ assert ! (
241+ src. starts_with( "/static/tsjs=tsjs-unified.min.js?v=" ) ,
242+ "should include unified script URL prefix"
243+ ) ;
244+ assert_sha256_hex_hash ( hash_query_value ( & src) ) ;
245+ assert_eq ! (
246+ tsjs_unified_script_tag( ) ,
247+ format!( r#"<script src="{src}" id="trustedserver-js"></script>"# ) ,
248+ "should wrap the unified source in a trusted server script tag"
249+ ) ;
250+ }
251+
252+ #[ test]
253+ fn tsjs_script_src_differs_for_different_module_sets ( ) {
254+ assert_ne ! (
255+ tsjs_script_src( & [ "lockr" ] ) ,
256+ tsjs_script_src( & [ "lockr" , "permutive" ] ) ,
257+ "should bust the cache when the module set content changes"
258+ ) ;
259+ }
260+
261+ #[ test]
262+ fn tsjs_deferred_script_src_has_empty_hash_for_unknown_module ( ) {
263+ assert_eq ! (
264+ tsjs_deferred_script_src( "does-not-exist" ) ,
265+ "/static/tsjs=tsjs-does-not-exist.min.js?v=" ,
266+ "should fall back to an empty cache-busting hash for an unknown module"
267+ ) ;
268+ }
222269}
0 commit comments