@@ -14,7 +14,7 @@ describe("unittests:: canWatch::", () => {
1414 paths . forEach ( path => baselineCanWatchDirectoryOrFile ( combinePaths ( path , "package.json" ) , maxLengths ) ) ;
1515 baseline . push ( "" , "" ) ;
1616 function baselineCanWatchDirectoryOrFile ( path : ts . Path , maxLengths : readonly number [ ] ) {
17- pushRow ( baseline , [ path , `${ ts . canWatchDirectoryOrFile ( path ) } ` ] , maxLengths ) ;
17+ pushRow ( baseline , [ path , `${ ts . canWatchDirectoryOrFile ( ts . getPathComponents ( path ) ) } ` ] , maxLengths ) ;
1818 }
1919 } ,
2020 ) ;
@@ -25,13 +25,12 @@ describe("unittests:: canWatch::", () => {
2525 ( paths , longestPathLength , baseline ) => {
2626 const testType = "canWatchAtTypes" ;
2727 const maxLengths = [ longestPathLength + "/node_modules/@types" . length , testType . length ] as const ;
28- baselineCanWatchForRoot ( paths , baseline , root => {
29- pushHeader ( baseline , [ "Directory" , testType ] , maxLengths ) ;
30- paths . forEach ( path => {
31- path = combinePaths ( path , "node_modules/@types" ) ;
32- pushRow ( baseline , [ path , `${ ts . canWatchAtTypes ( path , root ) } ` ] , maxLengths ) ;
33- } ) ;
28+ pushHeader ( baseline , [ "Directory" , testType ] , maxLengths ) ;
29+ paths . forEach ( path => {
30+ path = combinePaths ( path , "node_modules/@types" ) ;
31+ pushRow ( baseline , [ path , `${ ts . canWatchAtTypes ( path ) } ` ] , maxLengths ) ;
3432 } ) ;
33+ baseline . push ( "" , "" ) ;
3534 } ,
3635 ) ;
3736
@@ -41,13 +40,12 @@ describe("unittests:: canWatch::", () => {
4140 ( paths , longestPathLength , baseline ) => {
4241 const testType = "canWatchAffectingLocation" ;
4342 const maxLengths = [ longestPathLength + "/package.json" . length , testType . length ] as const ;
44- baselineCanWatchForRoot ( paths , baseline , _root => {
45- pushHeader ( baseline , [ "File" , testType ] , maxLengths ) ;
46- paths . forEach ( path => {
47- path = combinePaths ( path , "package.json" ) ;
48- pushRow ( baseline , [ path , `${ ts . canWatchAffectingLocation ( path ) } ` ] , maxLengths ) ;
49- } ) ;
43+ pushHeader ( baseline , [ "File" , testType ] , maxLengths ) ;
44+ paths . forEach ( path => {
45+ path = combinePaths ( path , "package.json" ) ;
46+ pushRow ( baseline , [ path , `${ ts . canWatchAffectingLocation ( path ) } ` ] , maxLengths ) ;
5047 } ) ;
48+ baseline . push ( "" , "" ) ;
5149 } ,
5250 ) ;
5351
@@ -65,21 +63,21 @@ describe("unittests:: canWatch::", () => {
6563 const recursive = "Recursive" ;
6664 const maxLength = longestPathLength + ts . combinePaths ( forPath , "dir/subdir/somefile.d.ts" ) . length ;
6765 const maxLengths = [ maxLength , maxLength , recursive . length ] as const ;
68- baselineCanWatchForRoot ( paths , baseline , root => {
66+ baselineCanWatchForRoot ( paths , baseline , ( rootPathCompoments , root ) => {
6967 pushHeader ( baseline , [ "Location" , "getDirectoryToWatchFailedLookupLocation" , recursive ] , maxLengths ) ;
7068 paths . forEach ( path => {
71- baselineGetDirectoryToWatchFailedLookupLocation ( combinePaths ( path , forPath , "somefile.d.ts" ) , root , maxLengths ) ;
72- baselineGetDirectoryToWatchFailedLookupLocation ( combinePaths ( path , forPath , "dir/somefile.d.ts" ) , root , maxLengths ) ;
73- baselineGetDirectoryToWatchFailedLookupLocation ( combinePaths ( path , forPath , "dir/subdir/somefile.d.ts" ) , root , maxLengths ) ;
69+ baselineGetDirectoryToWatchFailedLookupLocation ( combinePaths ( path , forPath , "somefile.d.ts" ) , root , rootPathCompoments , maxLengths ) ;
70+ baselineGetDirectoryToWatchFailedLookupLocation ( combinePaths ( path , forPath , "dir/somefile.d.ts" ) , root , rootPathCompoments , maxLengths ) ;
71+ baselineGetDirectoryToWatchFailedLookupLocation ( combinePaths ( path , forPath , "dir/subdir/somefile.d.ts" ) , root , rootPathCompoments , maxLengths ) ;
7472 } ) ;
7573 } ) ;
76- function baselineGetDirectoryToWatchFailedLookupLocation ( path : ts . Path , root : ts . Path | undefined , maxLengths : readonly number [ ] ) {
74+ function baselineGetDirectoryToWatchFailedLookupLocation ( path : ts . Path , root : ts . Path , rootPathCompoments : Readonly < ts . PathPathComponents > , maxLengths : readonly number [ ] ) {
7775 const result = ts . getDirectoryToWatchFailedLookupLocation (
7876 path ,
7977 path ,
8078 root ,
8179 root ,
82- root !== undefined ? root . split ( ts . directorySeparator ) . length : 0 ,
80+ rootPathCompoments ,
8381 ts . returnUndefined ,
8482 ) ;
8583 pushRow ( baseline , [ path , result ? result . dir : "" , result ? `${ ! result . nonRecursive } ` : "" ] , maxLengths ) ;
@@ -94,16 +92,18 @@ describe("unittests:: canWatch::", () => {
9492 ( paths , longestPathLength , baseline ) => {
9593 const maxLength = longestPathLength + "/node_modules/@types" . length ;
9694 const maxLengths = [ maxLength , maxLength ] as const ;
97- baselineCanWatchForRoot ( paths , baseline , root => {
95+ baselineCanWatchForRoot ( paths , baseline , ( rootPathCompoments , root ) => {
9896 pushHeader ( baseline , [ "Directory" , "getDirectoryToWatchFailedLookupLocationFromTypeRoot" ] , maxLengths ) ;
9997 paths . forEach ( path => {
10098 path = combinePaths ( path , "node_modules/@types" ) ;
10199 // This is invoked only on paths that are watched
102- if ( ! ts . canWatchAtTypes ( path , root ) ) return ;
100+ if ( ! ts . canWatchAtTypes ( path ) ) return ;
103101 const result = ts . getDirectoryToWatchFailedLookupLocationFromTypeRoot (
104102 path ,
105103 path ,
106104 root ,
105+ rootPathCompoments ,
106+ ts . returnUndefined ,
107107 ts . returnTrue ,
108108 ) ;
109109 pushRow ( baseline , [ path , result !== undefined ? result : "" ] , maxLengths ) ;
@@ -112,16 +112,14 @@ describe("unittests:: canWatch::", () => {
112112 } ,
113113 ) ;
114114
115- function baselineCanWatchForRoot ( paths : readonly ts . Path [ ] , baseline : string [ ] , baselineForRoot : ( root : ts . Path | undefined ) => void ) {
116- paths . forEach ( baselineRoot ) ;
117- baselineRoot ( /*rootDirForResolution*/ undefined ) ;
118- baseline . push ( "" , "" ) ;
119-
120- function baselineRoot ( rootDirForResolution : ts . Path | undefined ) {
115+ function baselineCanWatchForRoot ( paths : readonly ts . Path [ ] , baseline : string [ ] , baselineForRoot : ( rootPathCompoments : Readonly < ts . PathPathComponents > , root : ts . Path ) => void ) {
116+ paths . forEach ( rootDirForResolution => {
121117 const root = ts . getRootDirectoryOfResolutionCache ( rootDirForResolution , ts . returnUndefined ) as ts . Path ;
122- baseline . push ( "" , `## RootDirForResolution: ${ rootDirForResolution } ` , "" , `Root: ${ root } ` ) ;
123- baselineForRoot ( root ) ;
124- }
118+ assert ( root === rootDirForResolution ) ;
119+ baseline . push ( "" , `## RootDirForResolution: ${ rootDirForResolution } ` ) ;
120+ baselineForRoot ( ts . getPathComponents ( root ) , root ) ;
121+ } ) ;
122+ baseline . push ( "" , "" ) ;
125123 }
126124
127125 function baselineCanWatch (
0 commit comments