11import { DisposableCollection } from '@theia/core/lib/common/disposable' ;
2- import { waitForEvent } from '@theia/core/lib/common/promise-util' ;
32import type { MaybePromise } from '@theia/core/lib/common/types' ;
43import { FileUri } from '@theia/core/lib/node/file-uri' ;
54import { Container } from '@theia/core/shared/inversify' ;
@@ -16,6 +15,7 @@ import { ArduinoDaemonImpl } from '../../node/arduino-daemon-impl';
1615import { CLI_CONFIG , DefaultCliConfig } from '../../node/cli-config' ;
1716import { BoardListRequest } from '../../node/cli-protocol/cc/arduino/cli/commands/v1/board_pb' ;
1817import { CoreClientProvider } from '../../node/core-client-provider' ;
18+ import { spawnCommand } from '../../node/exec-util' ;
1919import { ConfigDirUriProvider } from '../../node/theia/env-variables/env-variables-server' ;
2020import { ErrnoException } from '../../node/utils/errors' ;
2121import {
@@ -177,10 +177,9 @@ describe('core-client-provider', () => {
177177 boardsPackages . filter ( ( { id } ) => id === 'teensy:avr' ) . length
178178 ) . to . be . equal ( 1 ) ;
179179 } ;
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+ } ) ;
184183 const thirdPartyPackageIndexPath = join (
185184 configDirPath ,
186185 'data' ,
@@ -273,27 +272,31 @@ async function assertFunctionalCli(
273272 * the config folder.
274273 */
275274async function prepareTestConfigDir (
276- configOverrides : Partial < DefaultCliConfig > = { } ,
277- otherExpect ?: ( services : Services ) => MaybePromise < void >
275+ configOverrides : Partial < DefaultCliConfig > = { }
278276) : Promise < string > {
279- const toDispose = new DisposableCollection ( ) ;
280277 const params = { configDirPath : newTempConfigDirPath ( ) , configOverrides } ;
281278 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 ) ;
297300}
298301
299302async function startCli (
@@ -312,15 +315,8 @@ async function startCli(
312315 throw err ;
313316 }
314317 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 > {
323318 await startDaemon ( container , toDispose ) ;
319+ return container ;
324320}
325321
326322async function createContainer (
0 commit comments