@@ -55,71 +55,77 @@ describe("unittests:: canWatch::", () => {
55
55
scenario : string ,
56
56
forPath : "node_modules" | "node_modules/@types" | "" ,
57
57
) {
58
- [ "file" , "dir" , "subDir" ] . forEach ( type => {
59
- baselineCanWatch (
60
- `${ scenario } In${ type } ` ,
61
- ( ) => `Determines whether to watch given failed lookup location (file that didnt exist) when resolving module.\r\nIt also determines the directory to watch and whether to watch it recursively or not.` ,
62
- ( paths , longestPathLength , baseline ) => {
63
- const recursive = "Recursive" ;
64
- const maxLength = longestPathLength + ts . combinePaths ( forPath , "dir/subdir/somefile.d.ts" ) . length ;
65
- const maxLengths = [ maxLength , maxLength , recursive . length , maxLength ] as const ;
66
- baselineCanWatchForRoot ( paths , baseline , ( rootPathCompoments , root ) => {
67
- pushHeader ( baseline , [ "Location" , "getDirectoryToWatchFailedLookupLocation" , recursive , "Location if not symlink" ] , maxLengths ) ;
68
- paths . forEach ( path => {
69
- let subPath ;
70
- switch ( type ) {
71
- case "file" :
72
- subPath = "somefile.d.ts" ;
73
- break ;
74
- case "dir" :
75
- subPath = "dir/somefile.d.ts" ;
76
- break ;
77
- case "subDir" :
78
- subPath = "dir/subdir/somefile.d.ts" ;
79
- break ;
80
- }
81
- const testPath = combinePaths ( path , forPath , subPath ) ;
82
- const result = ts . getDirectoryToWatchFailedLookupLocation (
83
- testPath ,
84
- testPath ,
85
- root ,
86
- root ,
87
- rootPathCompoments ,
88
- ts . returnUndefined ,
89
- ) ;
90
- pushRow ( baseline , [ testPath , result ? result . packageDir ?? result . dir : "" , result ? `${ ! result . nonRecursive } ` : "" , result ?. packageDir ? result . dir : "" ] , maxLengths ) ;
58
+ [ undefined , true ] . forEach ( preferNonRecursiveWatch => {
59
+ [ "file" , "dir" , "subDir" ] . forEach ( type => {
60
+ baselineCanWatch (
61
+ `${ scenario } In${ type } ${ preferNonRecursiveWatch ? "NonRecursive" : "" } ` ,
62
+ ( ) => `Determines whether to watch given failed lookup location (file that didnt exist) when resolving module.\r\nIt also determines the directory to watch and whether to watch it recursively or not.` ,
63
+ ( paths , longestPathLength , baseline ) => {
64
+ const recursive = "Recursive" ;
65
+ const maxLength = longestPathLength + ts . combinePaths ( forPath , "dir/subdir/somefile.d.ts" ) . length ;
66
+ const maxLengths = [ maxLength , maxLength , recursive . length , maxLength ] as const ;
67
+ baselineCanWatchForRoot ( paths , baseline , ( rootPathCompoments , root ) => {
68
+ pushHeader ( baseline , [ "Location" , "getDirectoryToWatchFailedLookupLocation" , recursive , "Location if not symlink" ] , maxLengths ) ;
69
+ paths . forEach ( path => {
70
+ let subPath ;
71
+ switch ( type ) {
72
+ case "file" :
73
+ subPath = "somefile.d.ts" ;
74
+ break ;
75
+ case "dir" :
76
+ subPath = "dir/somefile.d.ts" ;
77
+ break ;
78
+ case "subDir" :
79
+ subPath = "dir/subdir/somefile.d.ts" ;
80
+ break ;
81
+ }
82
+ const testPath = combinePaths ( path , forPath , subPath ) ;
83
+ const result = ts . getDirectoryToWatchFailedLookupLocation (
84
+ testPath ,
85
+ testPath ,
86
+ root ,
87
+ root ,
88
+ rootPathCompoments ,
89
+ ts . returnUndefined ,
90
+ preferNonRecursiveWatch ,
91
+ ) ;
92
+ pushRow ( baseline , [ testPath , result ? result . packageDir ?? result . dir : "" , result ? `${ ! result . nonRecursive } ` : "" , result ?. packageDir ? result . dir : "" ] , maxLengths ) ;
93
+ } ) ;
91
94
} ) ;
92
- } ) ;
93
- } ,
94
- ) ;
95
+ } ,
96
+ ) ;
97
+ } ) ;
95
98
} ) ;
96
99
}
97
100
98
- baselineCanWatch (
99
- "getDirectoryToWatchFailedLookupLocationFromTypeRoot" ,
100
- ( ) => `When watched typeRoot handler is invoked, this method determines the directory for which the failedLookupLocation would need to be invalidated.\r\nSince this is invoked only when watching default typeRoot and is used to handle flaky directory watchers, this is used as a fail safe where if failed lookup starts with returned directory we will invalidate that resolution.` ,
101
- ( paths , longestPathLength , baseline ) => {
102
- const maxLength = longestPathLength + "/node_modules/@types" . length ;
103
- const maxLengths = [ maxLength , maxLength ] as const ;
104
- baselineCanWatchForRoot ( paths , baseline , ( rootPathCompoments , root ) => {
105
- pushHeader ( baseline , [ "Directory" , "getDirectoryToWatchFailedLookupLocationFromTypeRoot" ] , maxLengths ) ;
106
- paths . forEach ( path => {
107
- path = combinePaths ( path , "node_modules/@types" ) ;
108
- // This is invoked only on paths that are watched
109
- if ( ! ts . canWatchAtTypes ( path ) ) return ;
110
- const result = ts . getDirectoryToWatchFailedLookupLocationFromTypeRoot (
111
- path ,
112
- path ,
113
- root ,
114
- rootPathCompoments ,
115
- ts . returnUndefined ,
116
- ts . returnTrue ,
117
- ) ;
118
- pushRow ( baseline , [ path , result !== undefined ? result : "" ] , maxLengths ) ;
101
+ [ undefined , true ] . forEach ( preferNonRecursiveWatch => {
102
+ baselineCanWatch (
103
+ `getDirectoryToWatchFailedLookupLocationFromTypeRoot${ preferNonRecursiveWatch ? "NonRecursive" : "" } ` ,
104
+ ( ) => `When watched typeRoot handler is invoked, this method determines the directory for which the failedLookupLocation would need to be invalidated.\r\nSince this is invoked only when watching default typeRoot and is used to handle flaky directory watchers, this is used as a fail safe where if failed lookup starts with returned directory we will invalidate that resolution.` ,
105
+ ( paths , longestPathLength , baseline ) => {
106
+ const maxLength = longestPathLength + "/node_modules/@types" . length ;
107
+ const maxLengths = [ maxLength , maxLength ] as const ;
108
+ baselineCanWatchForRoot ( paths , baseline , ( rootPathCompoments , root ) => {
109
+ pushHeader ( baseline , [ "Directory" , "getDirectoryToWatchFailedLookupLocationFromTypeRoot" ] , maxLengths ) ;
110
+ paths . forEach ( path => {
111
+ path = combinePaths ( path , "node_modules/@types" ) ;
112
+ // This is invoked only on paths that are watched
113
+ if ( ! ts . canWatchAtTypes ( path ) ) return ;
114
+ const result = ts . getDirectoryToWatchFailedLookupLocationFromTypeRoot (
115
+ path ,
116
+ path ,
117
+ root ,
118
+ rootPathCompoments ,
119
+ ts . returnUndefined ,
120
+ preferNonRecursiveWatch ,
121
+ ts . returnTrue ,
122
+ ) ;
123
+ pushRow ( baseline , [ path , result !== undefined ? result : "" ] , maxLengths ) ;
124
+ } ) ;
119
125
} ) ;
120
- } ) ;
121
- } ,
122
- ) ;
126
+ } ,
127
+ ) ;
128
+ } ) ;
123
129
124
130
function baselineCanWatchForRoot ( paths : readonly ts . Path [ ] , baseline : string [ ] , baselineForRoot : ( rootPathCompoments : Readonly < ts . PathPathComponents > , root : ts . Path ) => void ) {
125
131
paths . forEach ( rootDirForResolution => {
0 commit comments