Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e149eaa

Browse files
author
Akos Kitta
committedDec 13, 2023
test: test Arduino state update for extensions
Signed-off-by: Akos Kitta <[email protected]>
1 parent 615a684 commit e149eaa

File tree

7 files changed

+716
-11
lines changed

7 files changed

+716
-11
lines changed
 

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import { BoardsServiceProvider } from '../boards/boards-service-provider';
2121
import { CurrentSketch } from '../sketches-service-client-impl';
2222
import { SketchContribution } from './contribution';
2323

24-
interface UpdateStateParams<T extends ArduinoState> {
24+
/**
25+
* (non-API) exported for tests
26+
*/
27+
export interface UpdateStateParams<T extends ArduinoState = ArduinoState> {
2528
readonly key: keyof T;
2629
readonly value: T[keyof T];
2730
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
uno,
4040
unoSerialPort,
4141
} from '../common/fixtures';
42+
import { bindBrowser } from './browser-test-bindings';
4243

4344
disableJSDOM();
4445

@@ -390,7 +391,7 @@ describe('board-service-provider', () => {
390391
const container = new Container({ defaultScope: 'Singleton' });
391392
container.load(
392393
new ContainerModule((bind, unbind, isBound, rebind) => {
393-
bindCommon(bind);
394+
bindBrowser(bind, unbind, isBound, rebind);
394395
bind(MessageService).toConstantValue(<MessageService>{});
395396
bind(BoardsService).toConstantValue(<BoardsService>{
396397
getDetectedPorts() {
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
12
import { Container, ContainerModule } from '@theia/core/shared/inversify';
2-
import { bindCommon } from '../common/common-test-bindings';
3+
import {
4+
Bind,
5+
ConsoleLogger,
6+
bindCommon,
7+
} from '../common/common-test-bindings';
38

4-
export function createBaseContainer(): Container {
9+
export function createBaseContainer(bind: Bind = bindBrowser): Container {
510
const container = new Container({ defaultScope: 'Singleton' });
6-
container.load(new ContainerModule((bind) => bindCommon(bind)));
11+
container.load(new ContainerModule(bind));
712
return container;
813
}
14+
15+
export const bindBrowser: Bind = function (
16+
...args: Parameters<Bind>
17+
): ReturnType<Bind> {
18+
bindCommon(...args);
19+
const [bind, , , rebind] = args;
20+
// IDE2's test console logger does not support `Loggable` arg.
21+
// Rebind logger to suppress `[Function (anonymous)]` messages in tests when the storage service is initialized without `window.localStorage`.
22+
// https://github.com/eclipse-theia/theia/blob/04c8cf07843ea67402131132e033cdd54900c010/packages/core/src/browser/storage-service.ts#L60
23+
bind(MockLogger).toSelf().inSingletonScope();
24+
rebind(ConsoleLogger).toService(MockLogger);
25+
};

‎arduino-ide-extension/src/test/browser/update-arduino-state.test.ts

Lines changed: 670 additions & 0 deletions
Large diffs are not rendered by default.

‎arduino-ide-extension/src/test/common/common-test-bindings.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ import { LogLevel } from '@theia/core/lib/common/logger-protocol';
99
import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
1010
import { injectable, interfaces } from '@theia/core/shared/inversify';
1111

12-
export function bindCommon(bind: interfaces.Bind): interfaces.Bind {
12+
export interface Bind {
13+
(
14+
bind: interfaces.Bind,
15+
unbind: interfaces.Unbind,
16+
isBound: interfaces.IsBound,
17+
rebind: interfaces.Rebind
18+
): void;
19+
}
20+
21+
export const bindCommon: Bind = function (
22+
...args: Parameters<Bind>
23+
): ReturnType<Bind> {
24+
const [bind] = args;
1325
bind(ConsoleLogger).toSelf().inSingletonScope();
1426
bind(ILogger).toService(ConsoleLogger);
1527
bind(CommandRegistry).toSelf().inSingletonScope();
1628
bind(CommandService).toService(CommandRegistry);
1729
bindContributionProvider(bind, CommandContribution);
18-
return bind;
19-
}
30+
};
2031

2132
@injectable()
2233
export class ConsoleLogger extends MockLogger {

‎arduino-ide-extension/src/test/node/node-test-bindings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export async function createBaseContainer(
222222
}
223223
const container = new Container({ defaultScope: 'Singleton' });
224224
const module = new ContainerModule((bind, unbind, isBound, rebind) => {
225-
bindCommon(bind);
225+
bindCommon(bind, unbind, isBound, rebind);
226226
bind(CoreClientProvider).toSelf().inSingletonScope();
227227
bind(CoreServiceImpl).toSelf().inSingletonScope();
228228
bind(CoreService).toService(CoreServiceImpl);
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
export function tick(): Promise<void> {
2-
return new Promise((res) => setTimeout(res, 1));
1+
import { Emitter, Event } from '@theia/core/lib/common/event';
2+
3+
const neverEmitter = new Emitter<unknown>();
4+
export function never<T = void>(): Event<T> {
5+
return neverEmitter.event as Event<T>;
36
}

0 commit comments

Comments
 (0)
Please sign in to comment.