1
1
import { DisposableCollection } from '@theia/core/lib/common/disposable' ;
2
- import { waitForEvent } from '@theia/core/lib/common/promise-util' ;
3
2
import type { MaybePromise } from '@theia/core/lib/common/types' ;
4
3
import { FileUri } from '@theia/core/lib/node/file-uri' ;
5
4
import { Container } from '@theia/core/shared/inversify' ;
@@ -16,6 +15,7 @@ import { ArduinoDaemonImpl } from '../../node/arduino-daemon-impl';
16
15
import { CLI_CONFIG , DefaultCliConfig } from '../../node/cli-config' ;
17
16
import { BoardListRequest } from '../../node/cli-protocol/cc/arduino/cli/commands/v1/board_pb' ;
18
17
import { CoreClientProvider } from '../../node/core-client-provider' ;
18
+ import { spawnCommand } from '../../node/exec-util' ;
19
19
import { ConfigDirUriProvider } from '../../node/theia/env-variables/env-variables-server' ;
20
20
import { ErrnoException } from '../../node/utils/errors' ;
21
21
import {
@@ -177,10 +177,9 @@ describe('core-client-provider', () => {
177
177
boardsPackages . filter ( ( { id } ) => id === 'teensy:avr' ) . length
178
178
) . to . be . equal ( 1 ) ;
179
179
} ;
180
- const configDirPath = await prepareTestConfigDir (
181
- { board_manager : { additional_urls : additionalUrls } } ,
182
- ( { boardsService } ) => assertTeensyAvailable ( boardsService )
183
- ) ;
180
+ const configDirPath = await prepareTestConfigDir ( {
181
+ board_manager : { additional_urls : additionalUrls } ,
182
+ } ) ;
184
183
const thirdPartyPackageIndexPath = join (
185
184
configDirPath ,
186
185
'data' ,
@@ -273,27 +272,31 @@ async function assertFunctionalCli(
273
272
* the config folder.
274
273
*/
275
274
async function prepareTestConfigDir (
276
- configOverrides : Partial < DefaultCliConfig > = { } ,
277
- otherExpect ?: ( services : Services ) => MaybePromise < void >
275
+ configOverrides : Partial < DefaultCliConfig > = { }
278
276
) : Promise < string > {
279
- const toDispose = new DisposableCollection ( ) ;
280
277
const params = { configDirPath : newTempConfigDirPath ( ) , configOverrides } ;
281
278
const container = await createContainer ( params ) ;
282
- try {
283
- await start ( container , toDispose ) ;
284
- await assertFunctionalCli ( container , otherExpect ) ;
285
- const configDirUriProvider =
286
- container . get < ConfigDirUriProvider > ( ConfigDirUriProvider ) ;
287
- return FileUri . fsPath ( configDirUriProvider . configDirUri ( ) ) ;
288
- } finally {
289
- const daemon = container . get < ArduinoDaemonImpl > ( ArduinoDaemonImpl ) ;
290
- // Wait for the daemon stop event. All subprocesses (such as `serial-discovery` and `mdns-discovery`) must terminate.
291
- // Otherwise, `EPERM: operation not permitted, unlink` is thrown on Windows when "corrupting" the `directories.data` folder for the tests.
292
- await Promise . all ( [
293
- waitForEvent ( daemon . onDaemonStopped , 5_000 ) ,
294
- Promise . resolve ( toDispose . dispose ( ) ) ,
295
- ] ) ;
296
- }
279
+ const daemon = container . get < ArduinoDaemonImpl > ( ArduinoDaemonImpl ) ;
280
+ const cliPath = await daemon . getExecPath ( ) ;
281
+ const configDirUriProvider =
282
+ container . get < ConfigDirUriProvider > ( ConfigDirUriProvider ) ;
283
+ const configDirPath = FileUri . fsPath ( configDirUriProvider . configDirUri ( ) ) ;
284
+ await coreUpdateIndex ( cliPath , configDirPath ) ;
285
+ return configDirPath ;
286
+ }
287
+
288
+ async function coreUpdateIndex (
289
+ cliPath : string ,
290
+ configDirPath : string
291
+ ) : Promise < void > {
292
+ const cliConfigPath = join ( configDirPath , 'arduino-cli.yaml' ) ;
293
+ await fs . access ( cliConfigPath ) ;
294
+ const stdout = await spawnCommand (
295
+ cliPath ,
296
+ [ 'core' , 'update-index' , '--config-file' , cliConfigPath ] ,
297
+ ( error ) => console . error ( error )
298
+ ) ;
299
+ console . log ( stdout ) ;
297
300
}
298
301
299
302
async function startCli (
@@ -312,15 +315,8 @@ async function startCli(
312
315
throw err ;
313
316
}
314
317
const container = await createContainer ( configDirPath ) ;
315
- await start ( container , toDispose ) ;
316
- return container ;
317
- }
318
-
319
- async function start (
320
- container : Container ,
321
- toDispose : DisposableCollection
322
- ) : Promise < void > {
323
318
await startDaemon ( container , toDispose ) ;
319
+ return container ;
324
320
}
325
321
326
322
async function createContainer (
0 commit comments