Skip to content

Commit

Permalink
implement unit tests for boards-auto-installer (arduino#513)
Browse files Browse the repository at this point in the history
Co-authored-by: Francesco Stasi <f.stasi@me.com>
  • Loading branch information
Alberto Iannaccone and fstasi authored Sep 27, 2021
1 parent 79b075c commit e9db1c0
Show file tree
Hide file tree
Showing 14 changed files with 583 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"args": [
"--require",
"reflect-metadata/Reflect",
"--require",
"ignore-styles",
"--no-timeouts",
"--colors",
"**/${fileBasenameNoExtension}.js"
Expand Down
6 changes: 4 additions & 2 deletions arduino-ide-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "An extension for Theia building the Arduino IDE",
"license": "AGPL-3.0-or-later",
"scripts": {
"prepare": "yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn clean && yarn download-examples && yarn build",
"prepare": "yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn clean && yarn download-examples && yarn build && yarn test",
"clean": "rimraf lib",
"download-cli": "node ./scripts/download-cli.js",
"download-fwuploader": "node ./scripts/download-fwuploader.js",
Expand Down Expand Up @@ -101,6 +101,7 @@
"protoc": "^1.0.4",
"shelljs": "^0.8.3",
"sinon": "^9.0.1",
"typemoq": "^2.1.0",
"uuid": "^3.2.1",
"yargs": "^11.1.0"
},
Expand All @@ -109,7 +110,8 @@
},
"mocha": {
"require": [
"reflect-metadata/Reflect"
"reflect-metadata/Reflect",
"ignore-styles"
],
"reporter": "spec",
"colors": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ import { MonacoTextModelService as TheiaMonacoTextModelService } from '@theia/mo
import { MonacoTextModelService } from './theia/monaco/monaco-text-model-service';
import { ResponseServiceImpl } from './response-service-impl';
import {
ResponseServicePath,
ResponseService,
ResponseServiceArduino,
ResponseServicePath,
} from '../common/protocol/response-service';
import { NotificationCenter } from './notification-center';
import {
Expand Down Expand Up @@ -617,7 +618,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
);
return responseService;
});

bind(ResponseService).toService(ResponseServiceImpl);
bind(ResponseServiceArduino).toService(ResponseServiceImpl);

bind(NotificationCenter).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(NotificationCenter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {
Board,
} from '../../common/protocol/boards-service';
import { BoardsServiceProvider } from './boards-service-provider';
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution';
import { BoardsConfig } from './boards-config';
import { Installable } from '../../common/protocol';
import { ResponseServiceImpl } from '../response-service-impl';
import { Installable, ResponseServiceArduino } from '../../common/protocol';
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution';

/**
* Listens on `BoardsConfig.Config` changes, if a board is selected which does not
Expand All @@ -27,8 +26,8 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
@inject(BoardsServiceProvider)
protected readonly boardsServiceClient: BoardsServiceProvider;

@inject(ResponseServiceImpl)
protected readonly responseService: ResponseServiceImpl;
@inject(ResponseServiceArduino)
protected readonly responseService: ResponseServiceArduino;

@inject(BoardsListWidgetFrontendContribution)
protected readonly boardsManagerFrontendContribution: BoardsListWidgetFrontendContribution;
Expand Down Expand Up @@ -106,7 +105,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
});
return;
}
if (answer) {
if (answer === 'Install Manually') {
this.boardsManagerFrontendContribution
.openView({ reveal: true })
.then((widget) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import URI from '@theia/core/lib/common/uri';
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { ArduinoMenus } from '../menu/arduino-menus';
import { ResponseServiceImpl } from '../response-service-impl';
import { Installable, LibraryService } from '../../common/protocol';
import {
Installable,
LibraryService,
ResponseServiceArduino,
} from '../../common/protocol';
import {
SketchContribution,
Command,
Expand All @@ -18,8 +21,8 @@ export class AddZipLibrary extends SketchContribution {
@inject(EnvVariablesServer)
protected readonly envVariableServer: EnvVariablesServer;

@inject(ResponseServiceImpl)
protected readonly responseService: ResponseServiceImpl;
@inject(ResponseServiceArduino)
protected readonly responseService: ResponseServiceArduino;

@inject(LibraryService)
protected readonly libraryService: LibraryService;
Expand Down
13 changes: 7 additions & 6 deletions arduino-ide-extension/src/browser/response-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ import { Emitter } from '@theia/core/lib/common/event';
import { OutputContribution } from '@theia/output/lib/browser/output-contribution';
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
import {
ResponseService,
OutputMessage,
ProgressMessage,
ResponseServiceArduino,
} from '../common/protocol/response-service';

@injectable()
export class ResponseServiceImpl implements ResponseService {
export class ResponseServiceImpl implements ResponseServiceArduino {
@inject(OutputContribution)
protected outputContribution: OutputContribution;

@inject(OutputChannelManager)
protected outputChannelManager: OutputChannelManager;

protected readonly progressDidChangeEmitter = new Emitter<ProgressMessage>();

readonly onProgressDidChange = this.progressDidChangeEmitter.event;

clearArduinoChannel(): void {
this.outputChannelManager.getChannel('Arduino').clear();
}

appendToOutput(message: OutputMessage): void {
const { chunk } = message;
const channel = this.outputChannelManager.getChannel('Arduino');
channel.show({ preserveFocus: true });
channel.append(chunk);
}

clearArduinoChannel(): void {
this.outputChannelManager.getChannel('Arduino').clear();
}

reportProgress(progress: ProgressMessage): void {
this.progressDidChangeEmitter.fire(progress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SearchBar } from './search-bar';
import { ListWidget } from './list-widget';
import { ComponentList } from './component-list';
import { ListItemRenderer } from './list-item-renderer';
import { ResponseServiceImpl } from '../../response-service-impl';
import { ResponseServiceArduino } from '../../../common/protocol';

export class FilterableListContainer<
T extends ArduinoComponent
Expand Down Expand Up @@ -153,7 +153,7 @@ export namespace FilterableListContainer {
readonly resolveFocus: (element: HTMLElement | undefined) => void;
readonly filterTextChangeEvent: Event<string | undefined>;
readonly messageService: MessageService;
readonly responseService: ResponseServiceImpl;
readonly responseService: ResponseServiceArduino;
readonly install: ({
item,
progressId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
Installable,
Searchable,
ArduinoComponent,
ResponseServiceArduino,
} from '../../../common/protocol';
import { FilterableListContainer } from './filterable-list-container';
import { ListItemRenderer } from './list-item-renderer';
import { NotificationCenter } from '../../notification-center';
import { ResponseServiceImpl } from '../../response-service-impl';

@injectable()
export abstract class ListWidget<
Expand All @@ -28,8 +28,8 @@ export abstract class ListWidget<
@inject(CommandService)
protected readonly commandService: CommandService;

@inject(ResponseServiceImpl)
protected readonly responseService: ResponseServiceImpl;
@inject(ResponseServiceArduino)
protected readonly responseService: ResponseServiceArduino;

@inject(NotificationCenter)
protected readonly notificationCenter: NotificationCenter;
Expand Down
8 changes: 4 additions & 4 deletions arduino-ide-extension/src/common/protocol/installable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { naturalCompare } from './../utils';
import { ArduinoComponent } from './arduino-component';
import { MessageService } from '@theia/core';
import { ResponseServiceImpl } from '../../browser/response-service-impl';
import { ResponseServiceArduino } from './response-service';

export interface Installable<T extends ArduinoComponent> {
/**
Expand Down Expand Up @@ -44,7 +44,7 @@ export namespace Installable {
>(options: {
installable: Installable<T>;
messageService: MessageService;
responseService: ResponseServiceImpl;
responseService: ResponseServiceArduino;
item: T;
version: Installable.Version;
}): Promise<void> {
Expand All @@ -66,7 +66,7 @@ export namespace Installable {
>(options: {
installable: Installable<T>;
messageService: MessageService;
responseService: ResponseServiceImpl;
responseService: ResponseServiceArduino;
item: T;
}): Promise<void> {
const { item } = options;
Expand All @@ -86,7 +86,7 @@ export namespace Installable {
export async function doWithProgress(options: {
run: ({ progressId }: { progressId: string }) => Promise<void>;
messageService: MessageService;
responseService: ResponseServiceImpl;
responseService: ResponseServiceArduino;
progressText: string;
}): Promise<void> {
return withProgress(
Expand Down
8 changes: 8 additions & 0 deletions arduino-ide-extension/src/common/protocol/response-service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Event } from '@theia/core/lib/common/event';

export interface OutputMessage {
readonly chunk: string;
readonly severity?: 'error' | 'warning' | 'info'; // Currently not used!
Expand All @@ -21,3 +23,9 @@ export interface ResponseService {
appendToOutput(message: OutputMessage): void;
reportProgress(message: ProgressMessage): void;
}

export const ResponseServiceArduino = Symbol('ResponseServiceArduino');
export interface ResponseServiceArduino extends ResponseService {
onProgressDidChange: Event<ProgressMessage>;
clearArduinoChannel: () => void;
}
Loading

0 comments on commit e9db1c0

Please sign in to comment.