@@ -2008,73 +2008,72 @@ suite('Disk File Service', function () {
2008
2008
2009
2009
const runWatchTests = isLinux ;
2010
2010
2011
- ( runWatchTests ? test : test . skip ) ( 'watch - file' , done => {
2011
+ ( runWatchTests ? test : test . skip ) ( 'watch - file' , async ( ) => {
2012
2012
const toWatch = URI . file ( join ( testDir , 'index-watch1.html' ) ) ;
2013
2013
writeFileSync ( toWatch . fsPath , 'Init' ) ;
2014
2014
2015
- assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] , done ) ;
2016
-
2015
+ const promise = assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] ) ;
2017
2016
setTimeout ( ( ) => writeFileSync ( toWatch . fsPath , 'Changes' ) , 50 ) ;
2017
+ await promise ;
2018
2018
} ) ;
2019
2019
2020
- ( runWatchTests && ! isWindows /* symbolic links not reliable on windows */ ? test : test . skip ) ( 'watch - file symbolic link' , async done => {
2020
+ ( runWatchTests && ! isWindows /* symbolic links not reliable on windows */ ? test : test . skip ) ( 'watch - file symbolic link' , async ( ) => {
2021
2021
const toWatch = URI . file ( join ( testDir , 'lorem.txt-linked' ) ) ;
2022
2022
await symlink ( join ( testDir , 'lorem.txt' ) , toWatch . fsPath ) ;
2023
2023
2024
- assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] , done ) ;
2025
-
2024
+ const promise = assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] ) ;
2026
2025
setTimeout ( ( ) => writeFileSync ( toWatch . fsPath , 'Changes' ) , 50 ) ;
2026
+ await promise ;
2027
2027
} ) ;
2028
2028
2029
- ( runWatchTests ? test : test . skip ) ( 'watch - file - multiple writes' , done => {
2029
+ ( runWatchTests ? test : test . skip ) ( 'watch - file - multiple writes' , async ( ) => {
2030
2030
const toWatch = URI . file ( join ( testDir , 'index-watch1.html' ) ) ;
2031
2031
writeFileSync ( toWatch . fsPath , 'Init' ) ;
2032
2032
2033
- assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] , done ) ;
2034
-
2033
+ const promise = assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] ) ;
2035
2034
setTimeout ( ( ) => writeFileSync ( toWatch . fsPath , 'Changes 1' ) , 0 ) ;
2036
2035
setTimeout ( ( ) => writeFileSync ( toWatch . fsPath , 'Changes 2' ) , 10 ) ;
2037
2036
setTimeout ( ( ) => writeFileSync ( toWatch . fsPath , 'Changes 3' ) , 20 ) ;
2037
+ await promise ;
2038
2038
} ) ;
2039
2039
2040
- ( runWatchTests ? test : test . skip ) ( 'watch - file - delete file' , done => {
2040
+ ( runWatchTests ? test : test . skip ) ( 'watch - file - delete file' , async ( ) => {
2041
2041
const toWatch = URI . file ( join ( testDir , 'index-watch1.html' ) ) ;
2042
2042
writeFileSync ( toWatch . fsPath , 'Init' ) ;
2043
2043
2044
- assertWatch ( toWatch , [ [ FileChangeType . DELETED , toWatch ] ] , done ) ;
2045
-
2044
+ const promise = assertWatch ( toWatch , [ [ FileChangeType . DELETED , toWatch ] ] ) ;
2046
2045
setTimeout ( ( ) => unlinkSync ( toWatch . fsPath ) , 50 ) ;
2046
+ await promise ;
2047
2047
} ) ;
2048
2048
2049
- ( runWatchTests ? test : test . skip ) ( 'watch - file - rename file' , done => {
2049
+ ( runWatchTests ? test : test . skip ) ( 'watch - file - rename file' , async ( ) => {
2050
2050
const toWatch = URI . file ( join ( testDir , 'index-watch1.html' ) ) ;
2051
2051
const toWatchRenamed = URI . file ( join ( testDir , 'index-watch1-renamed.html' ) ) ;
2052
2052
writeFileSync ( toWatch . fsPath , 'Init' ) ;
2053
2053
2054
- assertWatch ( toWatch , [ [ FileChangeType . DELETED , toWatch ] ] , done ) ;
2055
-
2054
+ const promise = assertWatch ( toWatch , [ [ FileChangeType . DELETED , toWatch ] ] ) ;
2056
2055
setTimeout ( ( ) => renameSync ( toWatch . fsPath , toWatchRenamed . fsPath ) , 50 ) ;
2056
+ await promise ;
2057
2057
} ) ;
2058
2058
2059
- ( runWatchTests ? test : test . skip ) ( 'watch - file - rename file (different case)' , done => {
2059
+ ( runWatchTests ? test : test . skip ) ( 'watch - file - rename file (different case)' , async ( ) => {
2060
2060
const toWatch = URI . file ( join ( testDir , 'index-watch1.html' ) ) ;
2061
2061
const toWatchRenamed = URI . file ( join ( testDir , 'INDEX-watch1.html' ) ) ;
2062
2062
writeFileSync ( toWatch . fsPath , 'Init' ) ;
2063
2063
2064
- if ( isLinux ) {
2065
- assertWatch ( toWatch , [ [ FileChangeType . DELETED , toWatch ] ] , done ) ;
2066
- } else {
2067
- assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] , done ) ; // case insensitive file system treat this as change
2068
- }
2064
+ const promise = isLinux
2065
+ ? assertWatch ( toWatch , [ [ FileChangeType . DELETED , toWatch ] ] )
2066
+ : assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] ) ; // case insensitive file system treat this as change
2069
2067
2070
2068
setTimeout ( ( ) => renameSync ( toWatch . fsPath , toWatchRenamed . fsPath ) , 50 ) ;
2069
+ await promise ;
2071
2070
} ) ;
2072
2071
2073
- ( runWatchTests ? test : test . skip ) ( 'watch - file (atomic save)' , function ( done ) {
2072
+ ( runWatchTests ? test : test . skip ) ( 'watch - file (atomic save)' , async ( ) => {
2074
2073
const toWatch = URI . file ( join ( testDir , 'index-watch2.html' ) ) ;
2075
2074
writeFileSync ( toWatch . fsPath , 'Init' ) ;
2076
2075
2077
- assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] , done ) ;
2076
+ const promise = assertWatch ( toWatch , [ [ FileChangeType . UPDATED , toWatch ] ] ) ;
2078
2077
2079
2078
setTimeout ( ( ) => {
2080
2079
// Simulate atomic save by deleting the file, creating it under different name
@@ -2084,79 +2083,81 @@ suite('Disk File Service', function () {
2084
2083
writeFileSync ( renamed , 'Changes' ) ;
2085
2084
renameSync ( renamed , toWatch . fsPath ) ;
2086
2085
} , 50 ) ;
2086
+
2087
+ await promise ;
2087
2088
} ) ;
2088
2089
2089
- ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - change file' , done => {
2090
+ ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - change file' , async ( ) => {
2090
2091
const watchDir = URI . file ( join ( testDir , 'watch3' ) ) ;
2091
2092
mkdirSync ( watchDir . fsPath ) ;
2092
2093
2093
2094
const file = URI . file ( join ( watchDir . fsPath , 'index.html' ) ) ;
2094
2095
writeFileSync ( file . fsPath , 'Init' ) ;
2095
2096
2096
- assertWatch ( watchDir , [ [ FileChangeType . UPDATED , file ] ] , done ) ;
2097
-
2097
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . UPDATED , file ] ] ) ;
2098
2098
setTimeout ( ( ) => writeFileSync ( file . fsPath , 'Changes' ) , 50 ) ;
2099
+ await promise ;
2099
2100
} ) ;
2100
2101
2101
- ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - add file' , done => {
2102
+ ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - add file' , async ( ) => {
2102
2103
const watchDir = URI . file ( join ( testDir , 'watch4' ) ) ;
2103
2104
mkdirSync ( watchDir . fsPath ) ;
2104
2105
2105
2106
const file = URI . file ( join ( watchDir . fsPath , 'index.html' ) ) ;
2106
2107
2107
- assertWatch ( watchDir , [ [ FileChangeType . ADDED , file ] ] , done ) ;
2108
-
2108
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . ADDED , file ] ] ) ;
2109
2109
setTimeout ( ( ) => writeFileSync ( file . fsPath , 'Changes' ) , 50 ) ;
2110
+ await promise ;
2110
2111
} ) ;
2111
2112
2112
- ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - delete file' , done => {
2113
+ ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - delete file' , async ( ) => {
2113
2114
const watchDir = URI . file ( join ( testDir , 'watch5' ) ) ;
2114
2115
mkdirSync ( watchDir . fsPath ) ;
2115
2116
2116
2117
const file = URI . file ( join ( watchDir . fsPath , 'index.html' ) ) ;
2117
2118
writeFileSync ( file . fsPath , 'Init' ) ;
2118
2119
2119
- assertWatch ( watchDir , [ [ FileChangeType . DELETED , file ] ] , done ) ;
2120
-
2120
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . DELETED , file ] ] ) ;
2121
2121
setTimeout ( ( ) => unlinkSync ( file . fsPath ) , 50 ) ;
2122
+ await promise ;
2122
2123
} ) ;
2123
2124
2124
- ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - add folder' , done => {
2125
+ ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - add folder' , async ( ) => {
2125
2126
const watchDir = URI . file ( join ( testDir , 'watch6' ) ) ;
2126
2127
mkdirSync ( watchDir . fsPath ) ;
2127
2128
2128
2129
const folder = URI . file ( join ( watchDir . fsPath , 'folder' ) ) ;
2129
2130
2130
- assertWatch ( watchDir , [ [ FileChangeType . ADDED , folder ] ] , done ) ;
2131
-
2131
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . ADDED , folder ] ] ) ;
2132
2132
setTimeout ( ( ) => mkdirSync ( folder . fsPath ) , 50 ) ;
2133
+ await promise ;
2133
2134
} ) ;
2134
2135
2135
- ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - delete folder' , done => {
2136
+ ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - delete folder' , async ( ) => {
2136
2137
const watchDir = URI . file ( join ( testDir , 'watch7' ) ) ;
2137
2138
mkdirSync ( watchDir . fsPath ) ;
2138
2139
2139
2140
const folder = URI . file ( join ( watchDir . fsPath , 'folder' ) ) ;
2140
2141
mkdirSync ( folder . fsPath ) ;
2141
2142
2142
- assertWatch ( watchDir , [ [ FileChangeType . DELETED , folder ] ] , done ) ;
2143
-
2143
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . DELETED , folder ] ] ) ;
2144
2144
setTimeout ( ( ) => rimrafSync ( folder . fsPath ) , 50 ) ;
2145
+ await promise ;
2145
2146
} ) ;
2146
2147
2147
- ( runWatchTests && ! isWindows /* symbolic links not reliable on windows */ ? test : test . skip ) ( 'watch - folder (non recursive) - symbolic link - change file' , async done => {
2148
+ ( runWatchTests && ! isWindows /* symbolic links not reliable on windows */ ? test : test . skip ) ( 'watch - folder (non recursive) - symbolic link - change file' , async ( ) => {
2148
2149
const watchDir = URI . file ( join ( testDir , 'deep-link' ) ) ;
2149
2150
await symlink ( join ( testDir , 'deep' ) , watchDir . fsPath ) ;
2150
2151
2151
2152
const file = URI . file ( join ( watchDir . fsPath , 'index.html' ) ) ;
2152
2153
writeFileSync ( file . fsPath , 'Init' ) ;
2153
2154
2154
- assertWatch ( watchDir , [ [ FileChangeType . UPDATED , file ] ] , done ) ;
2155
-
2155
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . UPDATED , file ] ] ) ;
2156
2156
setTimeout ( ( ) => writeFileSync ( file . fsPath , 'Changes' ) , 50 ) ;
2157
+ await promise ;
2157
2158
} ) ;
2158
2159
2159
- ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - rename file' , done => {
2160
+ ( runWatchTests ? test : test . skip ) ( 'watch - folder (non recursive) - rename file' , async ( ) => {
2160
2161
const watchDir = URI . file ( join ( testDir , 'watch8' ) ) ;
2161
2162
mkdirSync ( watchDir . fsPath ) ;
2162
2163
@@ -2165,12 +2166,12 @@ suite('Disk File Service', function () {
2165
2166
2166
2167
const fileRenamed = URI . file ( join ( watchDir . fsPath , 'index-renamed.html' ) ) ;
2167
2168
2168
- assertWatch ( watchDir , [ [ FileChangeType . DELETED , file ] , [ FileChangeType . ADDED , fileRenamed ] ] , done ) ;
2169
-
2169
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . DELETED , file ] , [ FileChangeType . ADDED , fileRenamed ] ] ) ;
2170
2170
setTimeout ( ( ) => renameSync ( file . fsPath , fileRenamed . fsPath ) , 50 ) ;
2171
+ await promise ;
2171
2172
} ) ;
2172
2173
2173
- ( runWatchTests && isLinux /* this test requires a case sensitive file system */ ? test : test . skip ) ( 'watch - folder (non recursive) - rename file (different case)' , done => {
2174
+ ( runWatchTests && isLinux /* this test requires a case sensitive file system */ ? test : test . skip ) ( 'watch - folder (non recursive) - rename file (different case)' , async ( ) => {
2174
2175
const watchDir = URI . file ( join ( testDir , 'watch8' ) ) ;
2175
2176
mkdirSync ( watchDir . fsPath ) ;
2176
2177
@@ -2179,46 +2180,48 @@ suite('Disk File Service', function () {
2179
2180
2180
2181
const fileRenamed = URI . file ( join ( watchDir . fsPath , 'INDEX.html' ) ) ;
2181
2182
2182
- assertWatch ( watchDir , [ [ FileChangeType . DELETED , file ] , [ FileChangeType . ADDED , fileRenamed ] ] , done ) ;
2183
-
2183
+ const promise = assertWatch ( watchDir , [ [ FileChangeType . DELETED , file ] , [ FileChangeType . ADDED , fileRenamed ] ] ) ;
2184
2184
setTimeout ( ( ) => renameSync ( file . fsPath , fileRenamed . fsPath ) , 50 ) ;
2185
+ await promise ;
2185
2186
} ) ;
2186
2187
2187
- function assertWatch ( toWatch : URI , expected : [ FileChangeType , URI ] [ ] , done : MochaDone ) : void {
2188
- const watcherDisposable = service . watch ( toWatch ) ;
2188
+ function assertWatch ( toWatch : URI , expected : [ FileChangeType , URI ] [ ] ) : Promise < void > {
2189
+ return new Promise < void > ( ( resolve , reject ) => {
2190
+ const watcherDisposable = service . watch ( toWatch ) ;
2189
2191
2190
- function toString ( type : FileChangeType ) : string {
2191
- switch ( type ) {
2192
- case FileChangeType . ADDED : return 'added' ;
2193
- case FileChangeType . DELETED : return 'deleted' ;
2194
- case FileChangeType . UPDATED : return 'updated' ;
2192
+ function toString ( type : FileChangeType ) : string {
2193
+ switch ( type ) {
2194
+ case FileChangeType . ADDED : return 'added' ;
2195
+ case FileChangeType . DELETED : return 'deleted' ;
2196
+ case FileChangeType . UPDATED : return 'updated' ;
2197
+ }
2195
2198
}
2196
- }
2197
2199
2198
- function printEvents ( event : FileChangesEvent ) : string {
2199
- return event . changes . map ( change => `Change: type ${ toString ( change . type ) } path ${ change . resource . toString ( ) } ` ) . join ( '\n' ) ;
2200
- }
2200
+ function printEvents ( event : FileChangesEvent ) : string {
2201
+ return event . changes . map ( change => `Change: type ${ toString ( change . type ) } path ${ change . resource . toString ( ) } ` ) . join ( '\n' ) ;
2202
+ }
2201
2203
2202
- const listenerDisposable = service . onDidFilesChange ( event => {
2203
- watcherDisposable . dispose ( ) ;
2204
- listenerDisposable . dispose ( ) ;
2204
+ const listenerDisposable = service . onDidFilesChange ( event => {
2205
+ watcherDisposable . dispose ( ) ;
2206
+ listenerDisposable . dispose ( ) ;
2205
2207
2206
- try {
2207
- assert . equal ( event . changes . length , expected . length , `Expected ${ expected . length } events, but got ${ event . changes . length } . Details (${ printEvents ( event ) } )` ) ;
2208
+ try {
2209
+ assert . equal ( event . changes . length , expected . length , `Expected ${ expected . length } events, but got ${ event . changes . length } . Details (${ printEvents ( event ) } )` ) ;
2208
2210
2209
- if ( expected . length === 1 ) {
2210
- assert . equal ( event . changes [ 0 ] . type , expected [ 0 ] [ 0 ] , `Expected ${ toString ( expected [ 0 ] [ 0 ] ) } but got ${ toString ( event . changes [ 0 ] . type ) } . Details (${ printEvents ( event ) } )` ) ;
2211
- assert . equal ( event . changes [ 0 ] . resource . fsPath , expected [ 0 ] [ 1 ] . fsPath ) ;
2212
- } else {
2213
- for ( const expect of expected ) {
2214
- assert . equal ( hasChange ( event . changes , expect [ 0 ] , expect [ 1 ] ) , true , `Unable to find ${ toString ( expect [ 0 ] ) } for ${ expect [ 1 ] . fsPath } . Details (${ printEvents ( event ) } )` ) ;
2211
+ if ( expected . length === 1 ) {
2212
+ assert . equal ( event . changes [ 0 ] . type , expected [ 0 ] [ 0 ] , `Expected ${ toString ( expected [ 0 ] [ 0 ] ) } but got ${ toString ( event . changes [ 0 ] . type ) } . Details (${ printEvents ( event ) } )` ) ;
2213
+ assert . equal ( event . changes [ 0 ] . resource . fsPath , expected [ 0 ] [ 1 ] . fsPath ) ;
2214
+ } else {
2215
+ for ( const expect of expected ) {
2216
+ assert . equal ( hasChange ( event . changes , expect [ 0 ] , expect [ 1 ] ) , true , `Unable to find ${ toString ( expect [ 0 ] ) } for ${ expect [ 1 ] . fsPath } . Details (${ printEvents ( event ) } )` ) ;
2217
+ }
2215
2218
}
2216
- }
2217
2219
2218
- done ( ) ;
2219
- } catch ( error ) {
2220
- done ( error ) ;
2221
- }
2220
+ resolve ( ) ;
2221
+ } catch ( error ) {
2222
+ reject ( error ) ;
2223
+ }
2224
+ } ) ;
2222
2225
} ) ;
2223
2226
}
2224
2227
0 commit comments