@@ -60,42 +60,70 @@ describe('searchUp nut test', () => {
6060
6161 describe ( 'relative paths' , ( ) => {
6262 it ( 'finds file in parent directory' , ( ) => {
63- const startPath = path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' ) ;
64- const result = searchUp ( startPath , 'target.txt' ) ;
65- const expected = path . join ( session . project . dir , 'level1' , 'level2' , 'target.txt' ) ;
63+ const relativeStartPath = path . relative (
64+ session . project . dir ,
65+ path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' )
66+ ) ;
67+ expect ( path . isAbsolute ( relativeStartPath ) ) . to . be . false ;
68+ const result = searchUp ( relativeStartPath , 'target.txt' ) ;
69+ const expected = path . relative (
70+ session . project . dir ,
71+ path . join ( session . project . dir , 'level1' , 'level2' , 'target.txt' )
72+ ) ;
6673
6774 expect ( result ) . to . equal ( expected ) ;
6875 } ) ;
6976
7077 it ( 'finds file multiple levels up' , ( ) => {
71- const startPath = path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' ) ;
72- const result = searchUp ( startPath , '.gitignore' ) ;
73- const expected = path . join ( session . project . dir , '.gitignore' ) ;
78+ const relativeStartPath = path . relative (
79+ session . project . dir ,
80+ path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' )
81+ ) ;
82+ expect ( path . isAbsolute ( relativeStartPath ) ) . to . be . false ;
83+ const result = searchUp ( relativeStartPath , '.gitignore' ) ;
84+ const expected = path . relative ( session . project . dir , path . join ( session . project . dir , '.gitignore' ) ) ;
7485
7586 expect ( result ) . to . equal ( expected ) ;
7687 } ) ;
7788
7889 it ( 'finds file in current directory' , ( ) => {
79- const startPath = path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' ) ;
80- fs . writeFileSync ( path . join ( startPath , 'localFile.txt' ) , 'local content' ) ;
81- const result = searchUp ( startPath , 'localFile.txt' ) ;
82- const expected = path . join ( startPath , 'localFile.txt' ) ;
90+ const relativeStartPath = path . relative (
91+ session . project . dir ,
92+ path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' )
93+ ) ;
94+ expect ( path . isAbsolute ( relativeStartPath ) ) . to . be . false ;
95+ const absoluteStartPath = path . resolve ( session . project . dir , relativeStartPath ) ;
96+ fs . writeFileSync ( path . join ( absoluteStartPath , 'localFile.txt' ) , 'local content' ) ;
97+ const result = searchUp ( relativeStartPath , 'localFile.txt' ) ;
98+ const expected = path . relative ( session . project . dir , path . join ( absoluteStartPath , 'localFile.txt' ) ) ;
8399
84100 expect ( result ) . to . equal ( expected ) ;
85101 } ) ;
86102
87103 it ( 'returns undefined when file not found' , ( ) => {
88- const startPath = path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' ) ;
89- const result = searchUp ( startPath , 'nonexistent.txt' ) ;
104+ const relativeStartPath = path . relative (
105+ session . project . dir ,
106+ path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' )
107+ ) ;
108+ expect ( path . isAbsolute ( relativeStartPath ) ) . to . be . false ;
109+ const result = searchUp ( relativeStartPath , 'nonexistent.txt' ) ;
90110
91111 expect ( result ) . to . be . undefined ;
92112 } ) ;
93113
94114 it ( 'works when starting from file path' , ( ) => {
95- const filePath = path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' , 'someFile.txt' ) ;
96- fs . writeFileSync ( filePath , 'content' ) ;
97- const result = searchUp ( filePath , 'target.txt' ) ;
98- const expected = path . join ( session . project . dir , 'level1' , 'level2' , 'target.txt' ) ;
115+ const relativeFilePath = path . relative (
116+ session . project . dir ,
117+ path . join ( session . project . dir , 'level1' , 'level2' , 'startDir' , 'someFile.txt' )
118+ ) ;
119+ expect ( path . isAbsolute ( relativeFilePath ) ) . to . be . false ;
120+ const absoluteFilePath = path . resolve ( session . project . dir , relativeFilePath ) ;
121+ fs . writeFileSync ( absoluteFilePath , 'content' ) ;
122+ const result = searchUp ( relativeFilePath , 'target.txt' ) ;
123+ const expected = path . relative (
124+ session . project . dir ,
125+ path . join ( session . project . dir , 'level1' , 'level2' , 'target.txt' )
126+ ) ;
99127
100128 expect ( result ) . to . equal ( expected ) ;
101129 } ) ;
0 commit comments