@@ -56,6 +56,7 @@ interface IRawFS extends IPaths {
56
56
writeFile ( uri : vscode . Uri , content : Uint8Array ) : Thenable < void > ;
57
57
58
58
// "fs-extra"
59
+ pathExists ( filename : string ) : Promise < boolean > ;
59
60
lstat ( filename : string ) : Promise < fs . Stats > ;
60
61
chmod ( filePath : string , mode : string | number ) : Promise < void > ;
61
62
appendFile ( filename : string , data : { } ) : Promise < void > ;
@@ -926,51 +927,26 @@ suite('FileSystemUtils', () => {
926
927
suite ( 'pathExists' , ( ) => {
927
928
test ( 'exists (without type)' , async ( ) => {
928
929
const filename = 'x/y/z/spam.py' ;
929
- const stat = createMockStat ( ) ;
930
- deps . setup ( ( d ) => d . stat ( filename ) ) // The "file" exists.
931
- . returns ( ( ) => Promise . resolve ( stat . object ) ) ;
930
+ deps . setup ( ( d ) => d . pathExists ( filename ) ) // The "file" exists.
931
+ . returns ( ( ) => Promise . resolve ( true ) ) ;
932
932
933
933
const exists = await utils . pathExists ( filename ) ;
934
934
935
935
expect ( exists ) . to . equal ( true ) ;
936
936
verifyAll ( ) ;
937
937
} ) ;
938
938
939
- test ( 'does not exist' , async ( ) => {
939
+ test ( 'does not exist (without type) ' , async ( ) => {
940
940
const filename = 'x/y/z/spam.py' ;
941
- const err = vscode . FileSystemError . FileNotFound ( filename ) ;
942
- deps . setup ( ( d ) => d . stat ( filename ) ) // The file does not exist.
943
- . throws ( err ) ;
941
+ deps . setup ( ( d ) => d . pathExists ( filename ) ) // The "file" exists.
942
+ . returns ( ( ) => Promise . resolve ( false ) ) ;
944
943
945
944
const exists = await utils . pathExists ( filename ) ;
946
945
947
946
expect ( exists ) . to . equal ( false ) ;
948
947
verifyAll ( ) ;
949
948
} ) ;
950
949
951
- test ( 'ignores errors from stat()' , async ( ) => {
952
- const filename = 'x/y/z/spam.py' ;
953
- deps . setup ( ( d ) => d . stat ( filename ) ) // It's broken.
954
- . returns ( ( ) => Promise . reject ( new Error ( 'oops!' ) ) ) ;
955
-
956
- const exists = await utils . pathExists ( filename ) ;
957
-
958
- expect ( exists ) . to . equal ( false ) ;
959
- verifyAll ( ) ;
960
- } ) ;
961
-
962
- test ( 'matches (type: undefined)' , async ( ) => {
963
- const filename = 'x/y/z/spam.py' ;
964
- const stat = createMockStat ( ) ;
965
- deps . setup ( ( d ) => d . stat ( filename ) ) // The "file" exists.
966
- . returns ( ( ) => Promise . resolve ( stat . object ) ) ;
967
-
968
- const exists = await utils . pathExists ( filename ) ;
969
-
970
- expect ( exists ) . to . equal ( true ) ;
971
- verifyAll ( ) ;
972
- } ) ;
973
-
974
950
test ( 'matches (type: file)' , async ( ) => {
975
951
const filename = 'x/y/z/spam.py' ;
976
952
const stat = createMockStat ( ) ;
@@ -1231,8 +1207,8 @@ suite('FileSystemUtils', () => {
1231
1207
const err = vscode . FileSystemError . FileNotFound ( dirname ) ;
1232
1208
deps . setup ( ( d ) => d . listdir ( dirname ) ) // The "file" does not exist.
1233
1209
. returns ( ( ) => Promise . reject ( err ) ) ;
1234
- deps . setup ( ( d ) => d . stat ( dirname ) ) // The "file" does not exist.
1235
- . returns ( ( ) => Promise . reject ( err ) ) ;
1210
+ deps . setup ( ( d ) => d . pathExists ( dirname ) ) // The "file" does not exist.
1211
+ . returns ( ( ) => Promise . resolve ( false ) ) ;
1236
1212
1237
1213
const entries = await utils . listdir ( dirname ) ;
1238
1214
@@ -1245,9 +1221,7 @@ suite('FileSystemUtils', () => {
1245
1221
const err = vscode . FileSystemError . FileNotADirectory ( dirname ) ;
1246
1222
deps . setup ( ( d ) => d . listdir ( dirname ) ) // Fail (async) with not-a-directory.
1247
1223
. returns ( ( ) => Promise . reject ( err ) ) ;
1248
- const stat = createMockStat ( ) ;
1249
- deps . setup ( ( d ) => d . stat ( dirname ) ) // The "file" exists.
1250
- . returns ( ( ) => Promise . resolve ( stat . object ) ) ;
1224
+ deps . setup ( ( d ) => d . pathExists ( dirname ) ) . returns ( ( ) => Promise . resolve ( true ) ) ; // The "file" exists.
1251
1225
1252
1226
const promise = utils . listdir ( dirname ) ;
1253
1227
@@ -1260,29 +1234,13 @@ suite('FileSystemUtils', () => {
1260
1234
const err = new Error ( 'oops!' ) ;
1261
1235
deps . setup ( ( d ) => d . listdir ( dirname ) ) // Fail (async) with an arbitrary error.
1262
1236
. returns ( ( ) => Promise . reject ( err ) ) ;
1263
- deps . setup ( ( d ) => d . stat ( dirname ) ) // Fail with file-not-found.
1264
- . throws ( vscode . FileSystemError . FileNotFound ( dirname ) ) ;
1237
+ deps . setup ( ( d ) => d . pathExists ( dirname ) ) . returns ( ( ) => Promise . resolve ( false ) ) ;
1265
1238
1266
1239
const entries = await utils . listdir ( dirname ) ;
1267
1240
1268
1241
expect ( entries ) . to . deep . equal ( [ ] ) ;
1269
1242
verifyAll ( ) ;
1270
1243
} ) ;
1271
-
1272
- test ( 'fails if the raw call fails' , async ( ) => {
1273
- const dirname = 'x/y/z/spam' ;
1274
- const err = new Error ( 'oops!' ) ;
1275
- deps . setup ( ( d ) => d . listdir ( dirname ) ) // Fail with an arbirary error.
1276
- . throws ( err ) ;
1277
- const stat = createMockStat ( ) ;
1278
- deps . setup ( ( d ) => d . stat ( dirname ) ) // The "file" exists.
1279
- . returns ( ( ) => Promise . resolve ( stat . object ) ) ;
1280
-
1281
- const promise = utils . listdir ( dirname ) ;
1282
-
1283
- await expect ( promise ) . to . eventually . be . rejected ;
1284
- verifyAll ( ) ;
1285
- } ) ;
1286
1244
} ) ;
1287
1245
1288
1246
suite ( 'getSubDirectories' , ( ) => {
0 commit comments