@@ -453,3 +453,44 @@ describe("escapeHtml", () => {
453453 )
454454 } )
455455} )
456+
457+ describe ( "pathToFsPath" , ( ) => {
458+ it ( "should convert a path to a file system path" , ( ) => {
459+ expect ( util . pathToFsPath ( "/foo/bar/baz" ) ) . toBe ( "/foo/bar/baz" )
460+ } )
461+ it ( "should lowercase drive letter casing by default" , ( ) => {
462+ expect ( util . pathToFsPath ( "/C:/far/boo" ) ) . toBe ( "c:/far/boo" )
463+ } )
464+ it ( "should keep drive letter casing when set to true" , ( ) => {
465+ expect ( util . pathToFsPath ( "/C:/far/bo" , true ) ) . toBe ( "C:/far/bo" )
466+ } )
467+ it ( "should throw an error if a non-string is passed in for path" , ( ) => {
468+ expect ( ( ) =>
469+ util
470+ // @ts -expect-error We need to check other types
471+ . pathToFsPath ( { } ) ,
472+ ) . toThrow (
473+ `Could not compute fsPath from given uri. Expected path to be of type string, but was of type undefined.` ,
474+ )
475+ } )
476+ it ( "should not throw an error for a string array" , ( ) => {
477+ // @ts -expect-error We need to check other types
478+ expect ( ( ) => util . pathToFsPath ( [ "/hello/foo" , "/hello/bar" ] ) . not . toThrow ( ) )
479+ } )
480+ it ( "should use the first string in a string array" , ( ) => {
481+ expect ( util . pathToFsPath ( [ "/hello/foo" , "/hello/bar" ] ) ) . toBe ( "/hello/foo" )
482+ } )
483+ it ( "should replace / with \\ on Windows" , ( ) => {
484+ let ORIGINAL_PLATFORM = process . platform
485+
486+ Object . defineProperty ( process , "platform" , {
487+ value : "win32" ,
488+ } )
489+
490+ expect ( util . pathToFsPath ( "/C:/far/boo" ) ) . toBe ( "c:\\far\\boo" )
491+
492+ Object . defineProperty ( process , "platform" , {
493+ value : ORIGINAL_PLATFORM ,
494+ } )
495+ } )
496+ } )
0 commit comments