Skip to content

test: test Arduino state update for extensions #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ import { MonitorModel } from './monitor-model';
import { MonitorManagerProxyClientImpl } from './monitor-manager-proxy-client-impl';
import { EditorManager as TheiaEditorManager } from '@theia/editor/lib/browser/editor-manager';
import { EditorManager } from './theia/editor/editor-manager';
import { HostedPluginEvents } from './hosted-plugin-events';
import { HostedPluginSupport } from './theia/plugin-ext/hosted-plugin';
import { HostedPluginEvents } from './hosted/hosted-plugin-events';
import { HostedPluginSupportImpl } from './theia/plugin-ext/hosted-plugin';
import { HostedPluginSupport as TheiaHostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
import { Formatter, FormatterPath } from '../common/protocol/formatter';
import { Format } from './contributions/format';
Expand Down Expand Up @@ -361,6 +361,7 @@ import { TerminalFrontendContribution as TheiaTerminalFrontendContribution } fro
import { SelectionService } from '@theia/core/lib/common/selection-service';
import { CommandService } from '@theia/core/lib/common/command';
import { CorePreferences } from '@theia/core/lib/browser/core-preferences';
import { HostedPluginSupport } from './hosted/hosted-plugin-support';

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

bind(HostedPluginSupport).toSelf().inSingletonScope();
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupport);
bind(HostedPluginSupportImpl).toSelf().inSingletonScope();
bind(HostedPluginSupport).toService(HostedPluginSupportImpl);
rebind(TheiaHostedPluginSupport).toService(HostedPluginSupportImpl);
bind(HostedPluginEvents).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(HostedPluginEvents);

Expand Down
2 changes: 1 addition & 1 deletion arduino-ide-extension/src/browser/contributions/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from '@theia/core/shared/inversify';
import { Event, Emitter } from '@theia/core/lib/common/event';
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
import { HostedPluginSupport } from '../hosted/hosted-plugin-support';
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
import { NotificationCenter } from '../notification-center';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from '../../common/protocol';
import { CurrentSketch } from '../sketches-service-client-impl';
import { BoardsServiceProvider } from '../boards/boards-service-provider';
import { HostedPluginEvents } from '../hosted-plugin-events';
import { HostedPluginEvents } from '../hosted/hosted-plugin-events';
import { NotificationCenter } from '../notification-center';
import { SketchContribution, URI } from './contribution';
import { BoardsDataStore } from '../boards/boards-data-store';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DisposableCollection } from '@theia/core/lib/common/disposable';
import URI from '@theia/core/lib/common/uri';
import { inject, injectable } from '@theia/core/shared/inversify';
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
import { HostedPluginSupport } from '../hosted/hosted-plugin-support';
import type { ArduinoState } from 'vscode-arduino-api';
import {
BoardsService,
Expand All @@ -21,7 +21,10 @@ import { BoardsServiceProvider } from '../boards/boards-service-provider';
import { CurrentSketch } from '../sketches-service-client-impl';
import { SketchContribution } from './contribution';

interface UpdateStateParams<T extends ArduinoState> {
/**
* (non-API) exported for tests
*/
export interface UpdateStateParams<T extends ArduinoState = ArduinoState> {
readonly key: keyof T;
readonly value: T[keyof T];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DisposableCollection, Emitter, Event } from '@theia/core';
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
import { inject, injectable } from '@theia/core/shared/inversify';
import { HostedPluginSupport } from './theia/plugin-ext/hosted-plugin';
import { HostedPluginSupport } from './hosted-plugin-support';

/**
* Frontend contribution to watch VS Code extension start/stop events from Theia.
Expand Down
14 changes: 14 additions & 0 deletions arduino-ide-extension/src/browser/hosted/hosted-plugin-support.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Event } from '@theia/core/lib/common/event';

/*
This implementation hides the default HostedPluginSupport implementation from Theia to be able to test it.
Otherwise, the default implementation fails at require time due to the `import.meta` in the Theia plugin worker code.
https://github.com/eclipse-theia/theia/blob/964f69ca3b3a5fb87ffa0177fb300b74ba0ca39f/packages/plugin-ext/src/hosted/browser/plugin-worker.ts#L30-L32
*/

export const HostedPluginSupport = Symbol('HostedPluginSupport');
export interface HostedPluginSupport {
readonly didStart: Promise<void>;
readonly onDidLoad: Event<void>;
readonly onDidCloseConnection: Event<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@theia/monaco/lib/browser/monaco-theming-service';
import { MonacoThemeRegistry as TheiaMonacoThemeRegistry } from '@theia/monaco/lib/browser/textmate/monaco-theme-registry';
import type { ThemeMix } from '@theia/monaco/lib/browser/textmate/monaco-theme-types';
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
import { HostedPluginSupport } from '../../hosted/hosted-plugin-support';
import { ArduinoThemes, compatibleBuiltInTheme } from '../core/theming';
import { WindowServiceExt } from '../core/window-service-ext';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
PluginContributions,
HostedPluginSupport as TheiaHostedPluginSupport,
} from '@theia/plugin-ext/lib/hosted/browser/hosted-plugin';
import { HostedPluginSupport } from '../../hosted/hosted-plugin-support';

@injectable()
export class HostedPluginSupport extends TheiaHostedPluginSupport {
export class HostedPluginSupportImpl
extends TheiaHostedPluginSupport
implements HostedPluginSupport
{
private readonly onDidLoadEmitter = new Emitter<void>();
private readonly onDidCloseConnectionEmitter = new Emitter<void>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
DisposableCollection,
} from '@theia/core/lib/common/disposable';
import { MessageService } from '@theia/core/lib/common/message-service';
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
import { Container, ContainerModule } from '@theia/core/shared/inversify';
import { expect } from 'chai';
import { BoardsDataStore } from '../../browser/boards/boards-data-store';
Expand All @@ -31,7 +30,6 @@ import {
PortIdentifierChangeEvent,
} from '../../common/protocol/boards-service';
import { NotificationServiceServer } from '../../common/protocol/notification-service';
import { bindCommon, ConsoleLogger } from '../common/common-test-bindings';
import {
detectedPort,
esp32S3DevModule,
Expand All @@ -41,6 +39,7 @@ import {
uno,
unoSerialPort,
} from '../common/fixtures';
import { bindBrowser } from './browser-test-bindings';

disableJSDOM();

Expand Down Expand Up @@ -392,7 +391,7 @@ describe('board-service-provider', () => {
const container = new Container({ defaultScope: 'Singleton' });
container.load(
new ContainerModule((bind, unbind, isBound, rebind) => {
bindCommon(bind);
bindBrowser(bind, unbind, isBound, rebind);
bind(MessageService).toConstantValue(<MessageService>{});
bind(BoardsService).toConstantValue(<BoardsService>{
getDetectedPorts() {
Expand All @@ -414,11 +413,6 @@ describe('board-service-provider', () => {
bind(WindowService).toConstantValue(<WindowService>{});
bind(StorageService).toService(LocalStorageService);
bind(BoardsServiceProvider).toSelf().inSingletonScope();
// IDE2's test console logger does not support `Loggable` arg.
// Rebind logger to suppress `[Function (anonymous)]` messages in tests when the storage service is initialized without `window.localStorage`.
// https://github.com/eclipse-theia/theia/blob/04c8cf07843ea67402131132e033cdd54900c010/packages/core/src/browser/storage-service.ts#L60
bind(MockLogger).toSelf().inSingletonScope();
rebind(ConsoleLogger).toService(MockLogger);
})
);
return container;
Expand Down
23 changes: 20 additions & 3 deletions arduino-ide-extension/src/test/browser/browser-test-bindings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
import { Container, ContainerModule } from '@theia/core/shared/inversify';
import { bindCommon } from '../common/common-test-bindings';
import {
Bind,
ConsoleLogger,
bindCommon,
} from '../common/common-test-bindings';

export function createBaseContainer(): Container {
export function createBaseContainer(bind: Bind = bindBrowser): Container {
const container = new Container({ defaultScope: 'Singleton' });
container.load(new ContainerModule((bind) => bindCommon(bind)));
container.load(new ContainerModule(bind));
return container;
}

export const bindBrowser: Bind = function (
...args: Parameters<Bind>
): ReturnType<Bind> {
bindCommon(...args);
const [bind, , , rebind] = args;
// IDE2's test console logger does not support `Loggable` arg.
// Rebind logger to suppress `[Function (anonymous)]` messages in tests when the storage service is initialized without `window.localStorage`.
// https://github.com/eclipse-theia/theia/blob/04c8cf07843ea67402131132e033cdd54900c010/packages/core/src/browser/storage-service.ts#L60
bind(MockLogger).toSelf().inSingletonScope();
rebind(ConsoleLogger).toService(MockLogger);
};
Loading