Skip to content

Commit 9a275fe

Browse files
author
Akos Kitta
committed
fix: make hosted plugin support testable
Hide the concrete implementation behind an interface so that tests can `require` it. Signed-off-by: Akos Kitta <[email protected]>
1 parent 503533d commit 9a275fe

File tree

9 files changed

+30
-17
lines changed

9 files changed

+30
-17
lines changed

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

+6-4
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';
@@ -361,6 +361,7 @@ import { TerminalFrontendContribution as TheiaTerminalFrontendContribution } fro
361361
import { SelectionService } from '@theia/core/lib/common/selection-service';
362362
import { CommandService } from '@theia/core/lib/common/command';
363363
import { CorePreferences } from '@theia/core/lib/browser/core-preferences';
364+
import { HostedPluginSupport } from './hosted/hosted-plugin-support';
364365

365366
// Hack to fix copy/cut/paste issue after electron version update in Theia.
366367
// https://github.com/eclipse-theia/theia/issues/12487
@@ -982,8 +983,9 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
982983
})
983984
.inSingletonScope();
984985

985-
bind(HostedPluginSupport).toSelf().inSingletonScope();
986-
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupport);
986+
bind(HostedPluginSupportImpl).toSelf().inSingletonScope();
987+
bind(HostedPluginSupport).toService(HostedPluginSupportImpl);
988+
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupportImpl);
987989
bind(HostedPluginEvents).toSelf().inSingletonScope();
988990
bind(FrontendApplicationContribution).toService(HostedPluginEvents);
989991

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inject, injectable } from '@theia/core/shared/inversify';
22
import { Event, Emitter } from '@theia/core/lib/common/event';
3-
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
3+
import { HostedPluginSupport } from '../hosted/hosted-plugin-support';
44
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
55
import { NotificationCenter } from '../notification-center';
66
import {

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

+1-1
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

+1-1
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

+1-1
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.
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

+1-1
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

+5-1
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

-7
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)