Skip to content

Commit

Permalink
test: test Arduino state update for extensions
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Dec 13, 2023
1 parent 615a684 commit e149eaa
Show file tree
Hide file tree
Showing 7 changed files with 716 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -39,6 +39,7 @@ import {
uno,
unoSerialPort,
} from '../common/fixtures';
import { bindBrowser } from './browser-test-bindings';

disableJSDOM();

Expand Down Expand Up @@ -390,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 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

0 comments on commit e149eaa

Please sign in to comment.