Skip to content

Commit 5abdc18

Browse files
Akos Kittakittaakos
authored andcommitted
fix: make hosted plugin support testable
Hide the concrete implementation behind an interface so that tests can `require` it. Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 633346a commit 5abdc18

File tree

9 files changed

+49
-20
lines changed

9 files changed

+49
-20
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ import { MonitorModel } from './monitor-model';
271271
import { MonitorManagerProxyClientImpl } from './monitor-manager-proxy-client-impl';
272272
import { EditorManager as TheiaEditorManager } from '@theia/editor/lib/browser/editor-manager';
273273
import { EditorManager } from './theia/editor/editor-manager';
274-
import { HostedPluginEvents } from './hosted-plugin-events';
275-
import { HostedPluginSupport } from './theia/plugin-ext/hosted-plugin';
274+
import { HostedPluginEvents } from './hosted/hosted-plugin-events';
275+
import { HostedPluginSupportImpl } from './theia/plugin-ext/hosted-plugin';
276276
import { HostedPluginSupport as TheiaHostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
277277
import { Formatter, FormatterPath } from '../common/protocol/formatter';
278278
import { Format } from './contributions/format';
@@ -985,8 +985,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
985985
})
986986
.inSingletonScope();
987987

988-
bind(HostedPluginSupport).toSelf().inSingletonScope();
989-
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupport);
988+
bind(HostedPluginSupportImpl).toSelf().inSingletonScope();
989+
bind(HostedPluginSupport).toService(HostedPluginSupportImpl);
990+
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupportImpl);
990991
bind(HostedPluginEvents).toSelf().inSingletonScope();
991992
bind(FrontendApplicationContribution).toService(HostedPluginEvents);
992993

arduino-ide-extension/src/browser/contributions/debug.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import { inject, injectable } from '@theia/core/shared/inversify';
2-
import { Event, Emitter } from '@theia/core/lib/common/event';
3-
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
4-
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
5-
import { NotificationCenter } from '../notification-center';
62
import {
73
Board,
84
BoardIdentifier,
@@ -12,6 +8,11 @@ import {
128
Sketch,
139
} from '../../common/protocol';
1410
import { BoardsServiceProvider } from '../boards/boards-service-provider';
11+
import { HostedPluginSupport } from '../hosted/hosted-plugin-support';
12+
import { ArduinoMenus } from '../menu/arduino-menus';
13+
import { NotificationCenter } from '../notification-center';
14+
import { CurrentSketch } from '../sketches-service-client-impl';
15+
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
1516
import {
1617
URI,
1718
Command,
@@ -97,6 +98,22 @@ export class Debug extends SketchContribution {
9798
});
9899
this.notificationCenter.onPlatformDidInstall(() => this.refreshState());
99100
this.notificationCenter.onPlatformDidUninstall(() => this.refreshState());
101+
this.boardsDataStore.onDidChange((event) => {
102+
const selectedFqbn =
103+
this.boardsServiceProvider.boardsConfig.selectedBoard?.fqbn;
104+
if (event.changes.find((change) => change.fqbn === selectedFqbn)) {
105+
this.refreshState();
106+
}
107+
});
108+
this.commandService.onDidExecuteCommand((event) => {
109+
const { commandId, args } = event;
110+
if (
111+
commandId === 'arduino.languageserver.notifyBuildDidComplete' &&
112+
isCompileSummary(args[0])
113+
) {
114+
this.refreshState();
115+
}
116+
});
100117
}
101118

102119
override onReady(): void {

arduino-ide-extension/src/browser/contributions/ino-language.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '../../common/protocol';
1616
import { CurrentSketch } from '../sketches-service-client-impl';
1717
import { BoardsServiceProvider } from '../boards/boards-service-provider';
18-
import { HostedPluginEvents } from '../hosted-plugin-events';
18+
import { HostedPluginEvents } from '../hosted/hosted-plugin-events';
1919
import { NotificationCenter } from '../notification-center';
2020
import { SketchContribution, URI } from './contribution';
2121
import { BoardsDataStore } from '../boards/boards-data-store';

arduino-ide-extension/src/browser/contributions/update-arduino-state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DisposableCollection } from '@theia/core/lib/common/disposable';
22
import URI from '@theia/core/lib/common/uri';
33
import { inject, injectable } from '@theia/core/shared/inversify';
4-
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
4+
import { HostedPluginSupport } from '../hosted/hosted-plugin-support';
55
import type { ArduinoState } from 'vscode-arduino-api';
66
import {
77
BoardsService,

arduino-ide-extension/src/browser/hosted-plugin-events.ts renamed to arduino-ide-extension/src/browser/hosted/hosted-plugin-events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DisposableCollection, Emitter, Event } from '@theia/core';
22
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
33
import { inject, injectable } from '@theia/core/shared/inversify';
4-
import { HostedPluginSupport } from './theia/plugin-ext/hosted-plugin';
4+
import { HostedPluginSupport } from './hosted-plugin-support';
55

66
/**
77
* Frontend contribution to watch VS Code extension start/stop events from Theia.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Event } from '@theia/core/lib/common/event';
2+
3+
/*
4+
This implementation hides the default HostedPluginSupport implementation from Theia to be able to test it.
5+
Otherwise, the default implementation fails at require time due to the `import.meta` in the Theia plugin worker code.
6+
https://github.com/eclipse-theia/theia/blob/964f69ca3b3a5fb87ffa0177fb300b74ba0ca39f/packages/plugin-ext/src/hosted/browser/plugin-worker.ts#L30-L32
7+
*/
8+
9+
export const HostedPluginSupport = Symbol('HostedPluginSupport');
10+
export interface HostedPluginSupport {
11+
readonly didStart: Promise<void>;
12+
readonly onDidLoad: Event<void>;
13+
readonly onDidCloseConnection: Event<void>;
14+
}

arduino-ide-extension/src/browser/theia/monaco/monaco-theming-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '@theia/monaco/lib/browser/monaco-theming-service';
2121
import { MonacoThemeRegistry as TheiaMonacoThemeRegistry } from '@theia/monaco/lib/browser/textmate/monaco-theme-registry';
2222
import type { ThemeMix } from '@theia/monaco/lib/browser/textmate/monaco-theme-types';
23-
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
23+
import { HostedPluginSupport } from '../../hosted/hosted-plugin-support';
2424
import { ArduinoThemes, compatibleBuiltInTheme } from '../core/theming';
2525
import { WindowServiceExt } from '../core/window-service-ext';
2626

arduino-ide-extension/src/browser/theia/plugin-ext/hosted-plugin.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import {
55
PluginContributions,
66
HostedPluginSupport as TheiaHostedPluginSupport,
77
} from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
8+
import { HostedPluginSupport } from '../../hosted/hosted-plugin-support';
89

910
@injectable()
10-
export class HostedPluginSupport extends TheiaHostedPluginSupport {
11+
export class HostedPluginSupportImpl
12+
extends TheiaHostedPluginSupport
13+
implements HostedPluginSupport
14+
{
1115
private readonly onDidLoadEmitter = new Emitter<void>();
1216
private readonly onDidCloseConnectionEmitter = new Emitter<void>();
1317

arduino-ide-extension/src/test/browser/board-service-provider.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
DisposableCollection,
1616
} from '@theia/core/lib/common/disposable';
1717
import { MessageService } from '@theia/core/lib/common/message-service';
18-
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
1918
import { Container, ContainerModule } from '@theia/core/shared/inversify';
2019
import { expect } from 'chai';
2120
import { BoardsDataStore } from '../../browser/boards/boards-data-store';
@@ -31,7 +30,6 @@ import {
3130
PortIdentifierChangeEvent,
3231
} from '../../common/protocol/boards-service';
3332
import { NotificationServiceServer } from '../../common/protocol/notification-service';
34-
import { bindCommon, ConsoleLogger } from '../common/common-test-bindings';
3533
import {
3634
detectedPort,
3735
esp32S3DevModule,
@@ -414,11 +412,6 @@ describe('board-service-provider', () => {
414412
bind(WindowService).toConstantValue(<WindowService>{});
415413
bind(StorageService).toService(LocalStorageService);
416414
bind(BoardsServiceProvider).toSelf().inSingletonScope();
417-
// IDE2's test console logger does not support `Loggable` arg.
418-
// Rebind logger to suppress `[Function (anonymous)]` messages in tests when the storage service is initialized without `window.localStorage`.
419-
// https://github.com/eclipse-theia/theia/blob/04c8cf07843ea67402131132e033cdd54900c010/packages/core/src/browser/storage-service.ts#L60
420-
bind(MockLogger).toSelf().inSingletonScope();
421-
rebind(ConsoleLogger).toService(MockLogger);
422415
})
423416
);
424417
return container;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy