From 6f5feb31f9ceb7812b5f2a782b8e72b8f0c696c4 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Thu, 18 Jan 2024 09:23:15 +0100 Subject: [PATCH] fix: platform release version ordering Signed-off-by: Akos Kitta --- .../src/node/boards-service-impl.ts | 5 +++- .../node/boards-service-impl.slow-test.ts | 25 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/arduino-ide-extension/src/node/boards-service-impl.ts b/arduino-ide-extension/src/node/boards-service-impl.ts index da7a91ebf..dbd206cf9 100644 --- a/arduino-ide-extension/src/node/boards-service-impl.ts +++ b/arduino-ide-extension/src/node/boards-service-impl.ts @@ -589,6 +589,9 @@ function createBoardsPackage( return undefined; // never show incompatible platforms } const { id, website, maintainer } = summary.metadata; + const availableVersions = Array.from(versionReleaseMap.keys()) + .sort(Installable.Version.COMPARATOR) + .reverse(); return { id, name, @@ -602,7 +605,7 @@ function createBoardsPackage( moreInfoLink: website, author: maintainer, deprecated, - availableVersions: Array.from(versionReleaseMap.keys()), + availableVersions, }; } diff --git a/arduino-ide-extension/src/test/node/boards-service-impl.slow-test.ts b/arduino-ide-extension/src/test/node/boards-service-impl.slow-test.ts index fbd5aeb4d..767bb9d6e 100644 --- a/arduino-ide-extension/src/test/node/boards-service-impl.slow-test.ts +++ b/arduino-ide-extension/src/test/node/boards-service-impl.slow-test.ts @@ -1,7 +1,7 @@ import { DisposableCollection } from '@theia/core/lib/common/disposable'; import { Container } from '@theia/core/shared/inversify'; import { expect } from 'chai'; -import { BoardSearch, BoardsService } from '../../common/protocol'; +import { BoardSearch, BoardsService, Installable } from '../../common/protocol'; import { createBaseContainer, startDaemon } from './node-test-bindings'; describe('boards-service-impl', () => { @@ -24,6 +24,29 @@ describe('boards-service-impl', () => { expect(result).is.not.empty; }); + it('should order the available platform release versions in descending order', async function () { + const result = await boardService.search({}); + result.forEach((platform) => + platform.availableVersions.forEach( + (currentVersion, index, versions) => { + if (index < versions.length - 2) { + const nextArrayElement = versions[index + 1]; + const actual = Installable.Version.COMPARATOR( + currentVersion, + nextArrayElement + ); + expect(actual).to.be.greaterThan( + 0, + `Expected '${currentVersion}' to be gt '${nextArrayElement}'. All versions: ${JSON.stringify( + versions + )}` + ); + } + } + ) + ); + }); + it("should boost a result when 'types' includes 'arduino', and lower the score if deprecated", async () => { const result = await boardService.search({}); const arduinoIndexes: number[] = [];