Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing installed version to the platform #2379

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ILogger } from '@theia/core/lib/common/logger';
import { nls } from '@theia/core/lib/common/nls';
import { notEmpty } from '@theia/core/lib/common/objects';
import { Mutable } from '@theia/core/lib/common/types';
import { inject, injectable } from '@theia/core/shared/inversify';
import {
BoardDetails,
Expand Down Expand Up @@ -592,7 +593,7 @@ function createBoardsPackage(
const availableVersions = Array.from(versionReleaseMap.keys())
.sort(Installable.Version.COMPARATOR)
.reverse();
return {
const boardsPackage: Mutable<BoardsPackage> = {
id,
name,
summary: nls.localize(
Expand All @@ -607,6 +608,10 @@ function createBoardsPackage(
deprecated,
availableVersions,
};
if (summary.installedVersion) {
boardsPackage.installedVersion = summary.installedVersion;
}
return boardsPackage;
}

type PlatformSummaryWithMetadata = PlatformSummary.AsObject &
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import {
Disposable,
DisposableCollection,
} from '@theia/core/lib/common/disposable';
import { Container } from '@theia/core/shared/inversify';
import { expect } from 'chai';
import { BoardSearch, BoardsService, Installable } from '../../common/protocol';
import { promises as fs } from 'node:fs';
import path from 'node:path';
import temp from 'temp';
import {
BoardSearch,
BoardsPackage,
BoardsService,
Installable,
} from '../../common/protocol';
import { createBaseContainer, startDaemon } from './node-test-bindings';

describe('boards-service-impl', () => {
Expand All @@ -10,8 +21,12 @@ describe('boards-service-impl', () => {

before(async function () {
this.timeout(20_000);
toDispose = new DisposableCollection();
const container = await createContainer();
const tracked = temp.track();
toDispose = new DisposableCollection(
Disposable.create(() => tracked.cleanupSync())
);
const testDirPath = tracked.mkdirSync();
const container = await createContainer(testDirPath);
await start(container, toDispose);
boardService = container.get<BoardsService>(BoardsService);
});
Expand Down Expand Up @@ -110,10 +125,45 @@ describe('boards-service-impl', () => {
expect(first.deprecated).to.be.false;
});
});

it('should have the installed version set', async function () {
const timeout = 5 * 60 * 1_000; // five minutes to install/uninstall the core
this.timeout(timeout);

// ensure installed
let result = await boardService.search({ query: 'arduino:avr' });
let avr = result.find(
(boardsPackage) => boardsPackage.id === 'arduino:avr'
);
expect(avr).to.be.not.undefined;
await boardService.install({
item: <BoardsPackage>avr,
skipPostInstall: true,
});

// when installed the version is set
result = await boardService.search({ query: 'arduino:avr' });
avr = result.find((boardsPackage) => boardsPackage.id === 'arduino:avr');
expect(avr).to.be.not.undefined;
expect(avr?.installedVersion).to.be.not.undefined;

// uninstall the core
await boardService.uninstall({ item: <BoardsPackage>avr });
result = await boardService.search({ query: 'arduino:avr' });
avr = result.find((boardsPackage) => boardsPackage.id === 'arduino:avr');
expect(avr).to.be.not.undefined;
expect(avr?.installedVersion).to.be.undefined;
});
});

async function createContainer(): Promise<Container> {
return createBaseContainer();
async function createContainer(testDirPath: string): Promise<Container> {
const data = path.join(testDirPath, 'data');
const user = path.join(testDirPath, 'user');
await Promise.all([
fs.mkdir(data, { recursive: true }),
fs.mkdir(user, { recursive: true }),
]);
return createBaseContainer({ cliConfig: { directories: { data, user } } });
}

async function start(
Expand Down
Loading