1
- import { DisposableCollection } from '@theia/core/lib/common/disposable' ;
1
+ import {
2
+ Disposable ,
3
+ DisposableCollection ,
4
+ } from '@theia/core/lib/common/disposable' ;
2
5
import { Container } from '@theia/core/shared/inversify' ;
3
6
import { expect } from 'chai' ;
4
- import { BoardSearch , BoardsService , Installable } from '../../common/protocol' ;
7
+ import { promises as fs } from 'node:fs' ;
8
+ import path from 'node:path' ;
9
+ import temp from 'temp' ;
10
+ import {
11
+ BoardSearch ,
12
+ BoardsPackage ,
13
+ BoardsService ,
14
+ Installable ,
15
+ } from '../../common/protocol' ;
5
16
import { createBaseContainer , startDaemon } from './node-test-bindings' ;
6
17
7
18
describe ( 'boards-service-impl' , ( ) => {
@@ -10,8 +21,12 @@ describe('boards-service-impl', () => {
10
21
11
22
before ( async function ( ) {
12
23
this . timeout ( 20_000 ) ;
13
- toDispose = new DisposableCollection ( ) ;
14
- const container = await createContainer ( ) ;
24
+ const tracked = temp . track ( ) ;
25
+ toDispose = new DisposableCollection (
26
+ Disposable . create ( ( ) => tracked . cleanupSync ( ) )
27
+ ) ;
28
+ const testDirPath = tracked . mkdirSync ( ) ;
29
+ const container = await createContainer ( testDirPath ) ;
15
30
await start ( container , toDispose ) ;
16
31
boardService = container . get < BoardsService > ( BoardsService ) ;
17
32
} ) ;
@@ -110,10 +125,45 @@ describe('boards-service-impl', () => {
110
125
expect ( first . deprecated ) . to . be . false ;
111
126
} ) ;
112
127
} ) ;
128
+
129
+ it ( 'should have the installed version set' , async function ( ) {
130
+ const timeout = 5 * 60 * 1_000 ; // five minutes to install/uninstall the core
131
+ this . timeout ( timeout ) ;
132
+
133
+ // ensure installed
134
+ let result = await boardService . search ( { query : 'arduino:avr' } ) ;
135
+ let avr = result . find (
136
+ ( boardsPackage ) => boardsPackage . id === 'arduino:avr'
137
+ ) ;
138
+ expect ( avr ) . to . be . not . undefined ;
139
+ await boardService . install ( {
140
+ item : < BoardsPackage > avr ,
141
+ skipPostInstall : true ,
142
+ } ) ;
143
+
144
+ // when installed the version is set
145
+ result = await boardService . search ( { query : 'arduino:avr' } ) ;
146
+ avr = result . find ( ( boardsPackage ) => boardsPackage . id === 'arduino:avr' ) ;
147
+ expect ( avr ) . to . be . not . undefined ;
148
+ expect ( avr ?. installedVersion ) . to . be . not . undefined ;
149
+
150
+ // uninstall the core
151
+ await boardService . uninstall ( { item : < BoardsPackage > avr } ) ;
152
+ result = await boardService . search ( { query : 'arduino:avr' } ) ;
153
+ avr = result . find ( ( boardsPackage ) => boardsPackage . id === 'arduino:avr' ) ;
154
+ expect ( avr ) . to . be . not . undefined ;
155
+ expect ( avr ?. installedVersion ) . to . be . undefined ;
156
+ } ) ;
113
157
} ) ;
114
158
115
- async function createContainer ( ) : Promise < Container > {
116
- return createBaseContainer ( ) ;
159
+ async function createContainer ( testDirPath : string ) : Promise < Container > {
160
+ const data = path . join ( testDirPath , 'data' ) ;
161
+ const user = path . join ( testDirPath , 'user' ) ;
162
+ await Promise . all ( [
163
+ fs . mkdir ( data , { recursive : true } ) ,
164
+ fs . mkdir ( user , { recursive : true } ) ,
165
+ ] ) ;
166
+ return createBaseContainer ( { cliConfig : { directories : { data, user } } } ) ;
117
167
}
118
168
119
169
async function start (
0 commit comments