char/serve-esm
git clone https://git.t4t.associates/char/serve-esm
e06f6b7
main
1use serve_esm:: get_mime_type; 2 3# [ test ] 4fn known_extensions () { 5for ( path, expected) in [ 6( "foo.js" , "text/javascript; charset=utf-8" ), 7( "foo.mjs" , "text/javascript; charset=utf-8" ), 8( "foo.cjs" , "text/javascript; charset=utf-8" ), 9( "foo.jsx" , "text/jsx; charset=utf-8" ), 10( "foo.ts" , "text/typescript; charset=utf-8" ), 11( "foo.mts" , "text/typescript; charset=utf-8" ), 12( "foo.cts" , "text/typescript; charset=utf-8" ), 13( "foo.tsx" , "text/tsx; charset=utf-8" ), 14( "foo.json" , "application/json; charset=utf-8" ), 15( "foo.map" , "application/json; charset=utf-8" ), 16( "foo.css" , "text/css; charset=utf-8" ), 17( "foo.html" , "text/html; charset=utf-8" ), 18( "foo.txt" , "text/plain; charset=utf-8" ), 19( "foo.md" , "text/markdown; charset=utf-8" ), 20( "foo.svg" , "image/svg+xml; charset=utf-8" ), 21( "foo.wasm" , "application/wasm" ), 22] { 23assert_eq! ( get_mime_type ( path), Some ( expected), "{path}" ); 24} 25} 26 27# [ test ] 28fn only_the_final_extension_counts_and_case_does_not_matter () { 29assert_eq! ( 30get_mime_type ( "foo.d.ts" ), 31Some ( "text/typescript; charset=utf-8" ) 32); 33assert_eq! ( 34get_mime_type ( "foo.bundle.js" ), 35Some ( "text/javascript; charset=utf-8" ) 36); 37assert_eq! ( 38get_mime_type ( "FOO.JS" ), 39Some ( "text/javascript; charset=utf-8" ) 40); 41for pathin [ "foo.xyz" , "README" , "" , "foo." , "src.ts/no-extension" ] { 42assert_eq! ( get_mime_type ( path), None , "{path}" ); 43} 44}