@@ -16,26 +16,33 @@ async function fakeInstallVersion(version: string, installationDir: string): Pro
1616 await fs . writeFile ( path . join ( versionDir , 'file.txt' ) , 'content' )
1717}
1818
19+ async function fakeInstallVersions ( versions : string [ ] , installationDir : string ) : Promise < void > {
20+ for ( const v of versions ) {
21+ await fakeInstallVersion ( v , installationDir )
22+ }
23+ }
24+
1925describe ( 'workspaceInstaller' , function ( ) {
2026 describe ( 'cleanUp' , function ( ) {
2127 let installationDir : Uri
22- let lspVersions : string [ ]
2328
2429 before ( async function ( ) {
2530 installationDir = ( await createTestWorkspaceFolder ( ) ) . uri
26- lspVersions = [ '1.0.0' , '1.0.1' , '1.1.1' , '2.1.1' ]
2731 } )
2832
29- beforeEach ( async function ( ) {
30- for ( const v of lspVersions ) {
31- await fakeInstallVersion ( v , installationDir . fsPath )
33+ afterEach ( async function ( ) {
34+ const files = await fs . readdir ( installationDir . fsPath )
35+ for ( const [ name , _type ] of files ) {
36+ await fs . delete ( path . join ( installationDir . fsPath , name ) , { force : true , recursive : true } )
3237 }
3338 } )
3439
3540 after ( async function ( ) {
3641 await fs . delete ( installationDir , { force : true , recursive : true } )
3742 } )
43+
3844 it ( 'keeps two newest versions' , async function ( ) {
45+ await fakeInstallVersions ( [ '1.0.0' , '1.0.1' , '1.1.1' , '2.1.1' ] , installationDir . fsPath )
3946 const wsr = new WorkspaceLSPResolver ( )
4047 await wsr . cleanUp ( [ ] , installationDir . fsPath )
4148
@@ -46,6 +53,7 @@ describe('workspaceInstaller', function () {
4653 } )
4754
4855 it ( 'deletes delisted versions' , async function ( ) {
56+ await fakeInstallVersions ( [ '1.0.0' , '1.0.1' , '1.1.1' , '2.1.1' ] , installationDir . fsPath )
4957 const wsr = new WorkspaceLSPResolver ( )
5058 await wsr . cleanUp ( [ { serverVersion : '1.1.1' , isDelisted : true , targets : [ ] } ] , installationDir . fsPath )
5159
@@ -56,6 +64,7 @@ describe('workspaceInstaller', function () {
5664 } )
5765
5866 it ( 'handles case where less than 2 versions are not delisted' , async function ( ) {
67+ await fakeInstallVersions ( [ '1.0.0' , '1.0.1' , '1.1.1' , '2.1.1' ] , installationDir . fsPath )
5968 const wsr = new WorkspaceLSPResolver ( )
6069 await wsr . cleanUp (
6170 [
@@ -70,5 +79,23 @@ describe('workspaceInstaller', function () {
7079 assert . strictEqual ( result . length , 1 )
7180 assert . ok ( result . includes ( '1.0.1' ) )
7281 } )
82+
83+ it ( 'handles case where less than 2 versions exist' , async function ( ) {
84+ await fakeInstallVersions ( [ '1.0.0' ] , installationDir . fsPath )
85+ const wsr = new WorkspaceLSPResolver ( )
86+ await wsr . cleanUp ( [ ] , installationDir . fsPath )
87+
88+ const result = ( await fs . readdir ( installationDir . fsPath ) ) . map ( ( [ filename , _filetype ] , _index ) => filename )
89+ assert . strictEqual ( result . length , 1 )
90+ } )
91+
92+ it ( 'does not install delisted version when no other option exists' , async function ( ) {
93+ await fakeInstallVersions ( [ '1.0.0' ] , installationDir . fsPath )
94+ const wsr = new WorkspaceLSPResolver ( )
95+ await wsr . cleanUp ( [ { serverVersion : '1.0.0' , isDelisted : true , targets : [ ] } ] , installationDir . fsPath )
96+
97+ const result = ( await fs . readdir ( installationDir . fsPath ) ) . map ( ( [ filename , _filetype ] , _index ) => filename )
98+ assert . strictEqual ( result . length , 0 )
99+ } )
73100 } )
74101} )
0 commit comments