Skip to content

Commit e9db1c0

Browse files
Alberto Iannacconefstasi
Alberto Iannaccone
andauthored
implement unit tests for boards-auto-installer (#513)
Co-authored-by: Francesco Stasi <[email protected]>
1 parent 79b075c commit e9db1c0

14 files changed

+583
-36
lines changed

Diff for: .vscode/launch.json

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
"args": [
8080
"--require",
8181
"reflect-metadata/Reflect",
82+
"--require",
83+
"ignore-styles",
8284
"--no-timeouts",
8385
"--colors",
8486
"**/${fileBasenameNoExtension}.js"

Diff for: arduino-ide-extension/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "An extension for Theia building the Arduino IDE",
55
"license": "AGPL-3.0-or-later",
66
"scripts": {
7-
"prepare": "yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn clean && yarn download-examples && yarn build",
7+
"prepare": "yarn download-cli && yarn download-fwuploader && yarn download-ls && yarn clean && yarn download-examples && yarn build && yarn test",
88
"clean": "rimraf lib",
99
"download-cli": "node ./scripts/download-cli.js",
1010
"download-fwuploader": "node ./scripts/download-fwuploader.js",
@@ -101,6 +101,7 @@
101101
"protoc": "^1.0.4",
102102
"shelljs": "^0.8.3",
103103
"sinon": "^9.0.1",
104+
"typemoq": "^2.1.0",
104105
"uuid": "^3.2.1",
105106
"yargs": "^11.1.0"
106107
},
@@ -109,7 +110,8 @@
109110
},
110111
"mocha": {
111112
"require": [
112-
"reflect-metadata/Reflect"
113+
"reflect-metadata/Reflect",
114+
"ignore-styles"
113115
],
114116
"reporter": "spec",
115117
"colors": true,

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ import { MonacoTextModelService as TheiaMonacoTextModelService } from '@theia/mo
165165
import { MonacoTextModelService } from './theia/monaco/monaco-text-model-service';
166166
import { ResponseServiceImpl } from './response-service-impl';
167167
import {
168-
ResponseServicePath,
169168
ResponseService,
169+
ResponseServiceArduino,
170+
ResponseServicePath,
170171
} from '../common/protocol/response-service';
171172
import { NotificationCenter } from './notification-center';
172173
import {
@@ -617,7 +618,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
617618
);
618619
return responseService;
619620
});
621+
620622
bind(ResponseService).toService(ResponseServiceImpl);
623+
bind(ResponseServiceArduino).toService(ResponseServiceImpl);
621624

622625
bind(NotificationCenter).toSelf().inSingletonScope();
623626
bind(FrontendApplicationContribution).toService(NotificationCenter);

Diff for: arduino-ide-extension/src/browser/boards/boards-auto-installer.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import {
77
Board,
88
} from '../../common/protocol/boards-service';
99
import { BoardsServiceProvider } from './boards-service-provider';
10-
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution';
1110
import { BoardsConfig } from './boards-config';
12-
import { Installable } from '../../common/protocol';
13-
import { ResponseServiceImpl } from '../response-service-impl';
11+
import { Installable, ResponseServiceArduino } from '../../common/protocol';
12+
import { BoardsListWidgetFrontendContribution } from './boards-widget-frontend-contribution';
1413

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

30-
@inject(ResponseServiceImpl)
31-
protected readonly responseService: ResponseServiceImpl;
29+
@inject(ResponseServiceArduino)
30+
protected readonly responseService: ResponseServiceArduino;
3231

3332
@inject(BoardsListWidgetFrontendContribution)
3433
protected readonly boardsManagerFrontendContribution: BoardsListWidgetFrontendContribution;
@@ -106,7 +105,7 @@ export class BoardsAutoInstaller implements FrontendApplicationContribution {
106105
});
107106
return;
108107
}
109-
if (answer) {
108+
if (answer === 'Install Manually') {
110109
this.boardsManagerFrontendContribution
111110
.openView({ reveal: true })
112111
.then((widget) =>

Diff for: arduino-ide-extension/src/browser/contributions/add-zip-library.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import URI from '@theia/core/lib/common/uri';
44
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
55
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
66
import { ArduinoMenus } from '../menu/arduino-menus';
7-
import { ResponseServiceImpl } from '../response-service-impl';
8-
import { Installable, LibraryService } from '../../common/protocol';
7+
import {
8+
Installable,
9+
LibraryService,
10+
ResponseServiceArduino,
11+
} from '../../common/protocol';
912
import {
1013
SketchContribution,
1114
Command,
@@ -18,8 +21,8 @@ export class AddZipLibrary extends SketchContribution {
1821
@inject(EnvVariablesServer)
1922
protected readonly envVariableServer: EnvVariablesServer;
2023

21-
@inject(ResponseServiceImpl)
22-
protected readonly responseService: ResponseServiceImpl;
24+
@inject(ResponseServiceArduino)
25+
protected readonly responseService: ResponseServiceArduino;
2326

2427
@inject(LibraryService)
2528
protected readonly libraryService: LibraryService;

Diff for: arduino-ide-extension/src/browser/response-service-impl.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ import { Emitter } from '@theia/core/lib/common/event';
33
import { OutputContribution } from '@theia/output/lib/browser/output-contribution';
44
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';
55
import {
6-
ResponseService,
76
OutputMessage,
87
ProgressMessage,
8+
ResponseServiceArduino,
99
} from '../common/protocol/response-service';
1010

1111
@injectable()
12-
export class ResponseServiceImpl implements ResponseService {
12+
export class ResponseServiceImpl implements ResponseServiceArduino {
1313
@inject(OutputContribution)
1414
protected outputContribution: OutputContribution;
1515

1616
@inject(OutputChannelManager)
1717
protected outputChannelManager: OutputChannelManager;
1818

1919
protected readonly progressDidChangeEmitter = new Emitter<ProgressMessage>();
20+
2021
readonly onProgressDidChange = this.progressDidChangeEmitter.event;
2122

23+
clearArduinoChannel(): void {
24+
this.outputChannelManager.getChannel('Arduino').clear();
25+
}
26+
2227
appendToOutput(message: OutputMessage): void {
2328
const { chunk } = message;
2429
const channel = this.outputChannelManager.getChannel('Arduino');
2530
channel.show({ preserveFocus: true });
2631
channel.append(chunk);
2732
}
2833

29-
clearArduinoChannel(): void {
30-
this.outputChannelManager.getChannel('Arduino').clear();
31-
}
32-
3334
reportProgress(progress: ProgressMessage): void {
3435
this.progressDidChangeEmitter.fire(progress);
3536
}

Diff for: arduino-ide-extension/src/browser/widgets/component-list/filterable-list-container.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { SearchBar } from './search-bar';
1111
import { ListWidget } from './list-widget';
1212
import { ComponentList } from './component-list';
1313
import { ListItemRenderer } from './list-item-renderer';
14-
import { ResponseServiceImpl } from '../../response-service-impl';
14+
import { ResponseServiceArduino } from '../../../common/protocol';
1515

1616
export class FilterableListContainer<
1717
T extends ArduinoComponent
@@ -153,7 +153,7 @@ export namespace FilterableListContainer {
153153
readonly resolveFocus: (element: HTMLElement | undefined) => void;
154154
readonly filterTextChangeEvent: Event<string | undefined>;
155155
readonly messageService: MessageService;
156-
readonly responseService: ResponseServiceImpl;
156+
readonly responseService: ResponseServiceArduino;
157157
readonly install: ({
158158
item,
159159
progressId,

Diff for: arduino-ide-extension/src/browser/widgets/component-list/list-widget.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
Installable,
1313
Searchable,
1414
ArduinoComponent,
15+
ResponseServiceArduino,
1516
} from '../../../common/protocol';
1617
import { FilterableListContainer } from './filterable-list-container';
1718
import { ListItemRenderer } from './list-item-renderer';
1819
import { NotificationCenter } from '../../notification-center';
19-
import { ResponseServiceImpl } from '../../response-service-impl';
2020

2121
@injectable()
2222
export abstract class ListWidget<
@@ -28,8 +28,8 @@ export abstract class ListWidget<
2828
@inject(CommandService)
2929
protected readonly commandService: CommandService;
3030

31-
@inject(ResponseServiceImpl)
32-
protected readonly responseService: ResponseServiceImpl;
31+
@inject(ResponseServiceArduino)
32+
protected readonly responseService: ResponseServiceArduino;
3333

3434
@inject(NotificationCenter)
3535
protected readonly notificationCenter: NotificationCenter;

Diff for: arduino-ide-extension/src/common/protocol/installable.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { naturalCompare } from './../utils';
88
import { ArduinoComponent } from './arduino-component';
99
import { MessageService } from '@theia/core';
10-
import { ResponseServiceImpl } from '../../browser/response-service-impl';
10+
import { ResponseServiceArduino } from './response-service';
1111

1212
export interface Installable<T extends ArduinoComponent> {
1313
/**
@@ -44,7 +44,7 @@ export namespace Installable {
4444
>(options: {
4545
installable: Installable<T>;
4646
messageService: MessageService;
47-
responseService: ResponseServiceImpl;
47+
responseService: ResponseServiceArduino;
4848
item: T;
4949
version: Installable.Version;
5050
}): Promise<void> {
@@ -66,7 +66,7 @@ export namespace Installable {
6666
>(options: {
6767
installable: Installable<T>;
6868
messageService: MessageService;
69-
responseService: ResponseServiceImpl;
69+
responseService: ResponseServiceArduino;
7070
item: T;
7171
}): Promise<void> {
7272
const { item } = options;
@@ -86,7 +86,7 @@ export namespace Installable {
8686
export async function doWithProgress(options: {
8787
run: ({ progressId }: { progressId: string }) => Promise<void>;
8888
messageService: MessageService;
89-
responseService: ResponseServiceImpl;
89+
responseService: ResponseServiceArduino;
9090
progressText: string;
9191
}): Promise<void> {
9292
return withProgress(

Diff for: arduino-ide-extension/src/common/protocol/response-service.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Event } from '@theia/core/lib/common/event';
2+
13
export interface OutputMessage {
24
readonly chunk: string;
35
readonly severity?: 'error' | 'warning' | 'info'; // Currently not used!
@@ -21,3 +23,9 @@ export interface ResponseService {
2123
appendToOutput(message: OutputMessage): void;
2224
reportProgress(message: ProgressMessage): void;
2325
}
26+
27+
export const ResponseServiceArduino = Symbol('ResponseServiceArduino');
28+
export interface ResponseServiceArduino extends ResponseService {
29+
onProgressDidChange: Event<ProgressMessage>;
30+
clearArduinoChannel: () => void;
31+
}

0 commit comments

Comments
 (0)