import { expect , use } from 'chai' ; import { before , after } from 'mocha' ; use ( require ( 'chai-string' ) ) ; import { exists } from '../../util/workspaceFs' ; import { activateExtension } from './testUtils' ; import { assertDefined } from '../../utils' ; import { workspace , Uri , WorkspaceFolder } from 'vscode' ; import { fail } from 'assert' ; suite ( 'workspace FS' , ( ) => { let folderUri ; let fileUri ; let wf ; before ( async ( ) => { await activateExtension ( ) ; wf = assertDefined ( workspace . workspaceFolders , "workspace folders" ) [ 0 ] ; folderUri = Uri . joinPath ( wf . uri , "existentialTestFolder" ) ; await workspace . fs . createDirectory ( folderUri ) ; fileUri = Uri . joinPath ( wf . uri , "existentialTestFile" ) ; await workspace . fs . createDirectory ( fileUri ) ; } ) ; after ( async ( ) => { fileUri && await workspace . fs . delete ( fileUri , { useTrash : true } ) ; folderUri && await workspace . fs . delete ( folderUri , { useTrash : true , recursive : true } ) ; } ) ; test ( 'workspace.fs.createDirectory if it exists' , async ( ) => { folderUri && await workspace . fs . createDirectory ( folderUri ) ; } ) ; test ( 'workspace.fs.createDirectory nested directory if it exists' , async ( ) => { if ( ! folderUri ) { fail ( ) ; } const nestedNestedDirUri = Uri . joinPath ( folderUri , "nested1" , "nested2" ) ; await workspace . fs . createDirectory ( nestedNestedDirUri ) ; const actual = await exists ( nestedNestedDirUri ) ; expect ( actual ) . true ; } ) ; test ( 'existing directory exists' , async ( ) => { if ( ! folderUri ) { fail ( ) ; } const folderExists = await exists ( folderUri ) ; expect ( folderExists ) . to . equal ( true ) ; } ) ; test ( 'existing file exists' , async ( ) => { if ( ! fileUri ) { fail ( ) ; } const fileExists = await exists ( fileUri ) ; expect ( fileExists ) . to . equal ( true ) ; } ) ; test ( 'non-existent path does not exist' , async ( ) => { if ( ! wf ) { fail ( ) ; } const nonFolderUri = Uri . joinPath ( wf . uri , "nonExistent" ) ; const fileExists = await exists ( nonFolderUri ) ; expect ( fileExists ) . to . equal ( false ) ; } ) ; } ) ;