@@ -4,25 +4,30 @@ import path from "../../utils/path.js";
44
55const isBrowser = typeof window !== "undefined" ;
66
7+ function normalizePathForAssertion ( entry : string ) {
8+ return decodeURIComponent ( entry )
9+ . replace ( / \\ / g, "/" )
10+ . replace ( / ^ f i l e : \/ \/ \/ ( [ A - Z ] ) : / , ( _match , drive : string ) => `file:///${ drive . toLowerCase ( ) } :` )
11+ . replace ( / ^ ( [ A - Z ] ) : / , ( _match , drive : string ) => `${ drive . toLowerCase ( ) } :` ) ;
12+ }
13+
714describe . skipIf ( isBrowser ) ( "Special-character file paths" , ( ) => {
815 // Adapted replacement for the repo's previously ignored filename regression, using
916 // a cross-platform-safe subset of special characters.
1017 const schemaPath = path . rel (
1118 "test/specs/special-characters-files/dir with [brackets] & spaces/root schema.yaml" ,
1219 ) ;
13- const nestedPath = path . abs (
14- "test/specs/special-characters-files/dir with [brackets] & spaces/defs [value] %.json" ,
15- ) ;
1620
1721 it ( "should resolve external refs from filenames with spaces and special characters" , async ( ) => {
1822 const parser = new $RefParser ( ) ;
1923 const $refs = await parser . resolve ( schemaPath ) ;
20- const resolvedPath = $refs . paths ( ) . find ( ( entry ) => entry . includes ( "defs [value] %.json" ) ) ;
2124 const values = $refs . values ( ) ;
25+ const resolvedEntry = Object . entries ( values ) . find ( ( [ entry ] ) =>
26+ normalizePathForAssertion ( entry ) . includes ( "defs [value] %.json" ) ,
27+ ) ;
2228
23- expect ( $refs . paths ( ) ) . toContain ( nestedPath ) ;
24- expect ( resolvedPath ) . toBeTruthy ( ) ;
25- expect ( values [ resolvedPath as string ] ) . toEqual ( {
29+ expect ( resolvedEntry ) . toBeTruthy ( ) ;
30+ expect ( resolvedEntry ?. [ 1 ] ) . toEqual ( {
2631 definitions : {
2732 value : {
2833 type : "object" ,
@@ -32,7 +37,7 @@ describe.skipIf(isBrowser)("Special-character file paths", () => {
3237 } ,
3338 } ,
3439 } ) ;
35- expect ( values [ resolvedPath as string ] . definitions . value ) . toEqual ( {
40+ expect ( ( resolvedEntry ?. [ 1 ] as any ) . definitions . value ) . toEqual ( {
3641 type : "object" ,
3742 properties : {
3843 name : { type : "string" } ,
0 commit comments