|
7 | 7 | import { bindContributionProvider } from '@theia/core/lib/common/contribution-provider';
|
8 | 8 | import { Disposable } from '@theia/core/lib/common/disposable';
|
9 | 9 | import { EnvVariablesServer as TheiaEnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
10 |
| -import { ILogger } from '@theia/core/lib/common/logger'; |
| 10 | +import { ILogger, Loggable } from '@theia/core/lib/common/logger'; |
| 11 | +import { LogLevel } from '@theia/core/lib/common/logger-protocol'; |
11 | 12 | import { isWindows } from '@theia/core/lib/common/os';
|
12 | 13 | import { waitForEvent } from '@theia/core/lib/common/promise-util';
|
13 | 14 | import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
|
@@ -66,7 +67,7 @@ describe('core-service-impl', () => {
|
66 | 67 | let toDispose: Disposable[];
|
67 | 68 |
|
68 | 69 | before(() => {
|
69 |
| - BackendApplicationConfigProvider.set({ configDirName: 'testArduinoIDE' }); |
| 70 | + BackendApplicationConfigProvider.set({ configDirName: '.testArduinoIDE' }); |
70 | 71 | });
|
71 | 72 |
|
72 | 73 | beforeEach(async function () {
|
@@ -175,10 +176,11 @@ function createContainer(): Container {
|
175 | 176 | );
|
176 | 177 | bind(EnvVariablesServer).toSelf().inSingletonScope();
|
177 | 178 | bind(TheiaEnvVariablesServer).toService(EnvVariablesServer);
|
178 |
| - bind(ArduinoDaemonImpl).toSelf().inSingletonScope(); |
179 |
| - bind(ArduinoDaemon).toService(ArduinoDaemonImpl); |
180 |
| - bind(MockLogger).toSelf().inSingletonScope(); |
181 |
| - bind(ILogger).toService(MockLogger); |
| 179 | + bind(SilentArduinoDaemon).toSelf().inSingletonScope(); |
| 180 | + bind(ArduinoDaemon).toService(SilentArduinoDaemon); |
| 181 | + bind(ArduinoDaemonImpl).toService(SilentArduinoDaemon); |
| 182 | + bind(ConsoleLogger).toSelf().inSingletonScope(); |
| 183 | + bind(ILogger).toService(ConsoleLogger); |
182 | 184 | bind(TestNotificationServiceServer).toSelf().inSingletonScope();
|
183 | 185 | bind(NotificationServiceServer).toService(TestNotificationServiceServer);
|
184 | 186 | bind(ConfigServiceImpl).toSelf().inSingletonScope();
|
@@ -312,3 +314,88 @@ class TestCommandRegistry extends CommandRegistry {
|
312 | 314 | return undefined;
|
313 | 315 | }
|
314 | 316 | }
|
| 317 | + |
| 318 | +@injectable() |
| 319 | +class ConsoleLogger extends MockLogger { |
| 320 | + override log( |
| 321 | + logLevel: number, |
| 322 | + arg2: string | Loggable | Error, |
| 323 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 324 | + ...params: any[] |
| 325 | + ): Promise<void> { |
| 326 | + if (arg2 instanceof Error) { |
| 327 | + return this.error(String(arg2), params); |
| 328 | + } |
| 329 | + switch (logLevel) { |
| 330 | + case LogLevel.INFO: |
| 331 | + return this.info(arg2, params); |
| 332 | + case LogLevel.WARN: |
| 333 | + return this.warn(arg2, params); |
| 334 | + case LogLevel.TRACE: |
| 335 | + return this.trace(arg2, params); |
| 336 | + case LogLevel.ERROR: |
| 337 | + return this.error(arg2, params); |
| 338 | + case LogLevel.FATAL: |
| 339 | + return this.fatal(arg2, params); |
| 340 | + default: |
| 341 | + return this.info(arg2, params); |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 346 | + override async info(arg: string | Loggable, ...params: any[]): Promise<void> { |
| 347 | + if (params.length) { |
| 348 | + console.info(arg, ...params); |
| 349 | + } else { |
| 350 | + console.info(arg); |
| 351 | + } |
| 352 | + } |
| 353 | + |
| 354 | + override async trace( |
| 355 | + arg: string | Loggable, |
| 356 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 357 | + ...params: any[] |
| 358 | + ): Promise<void> { |
| 359 | + if (params.length) { |
| 360 | + console.trace(arg, ...params); |
| 361 | + } else { |
| 362 | + console.trace(arg); |
| 363 | + } |
| 364 | + } |
| 365 | + |
| 366 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 367 | + override async warn(arg: string | Loggable, ...params: any[]): Promise<void> { |
| 368 | + if (params.length) { |
| 369 | + console.warn(arg, ...params); |
| 370 | + } else { |
| 371 | + console.warn(arg); |
| 372 | + } |
| 373 | + } |
| 374 | + |
| 375 | + override async error( |
| 376 | + arg: string | Loggable, |
| 377 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 378 | + ...params: any[] |
| 379 | + ): Promise<void> { |
| 380 | + if (params.length) { |
| 381 | + console.error(arg, ...params); |
| 382 | + } else { |
| 383 | + console.error(arg); |
| 384 | + } |
| 385 | + } |
| 386 | + |
| 387 | + override async fatal( |
| 388 | + arg: string | Loggable, |
| 389 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 390 | + ...params: any[] |
| 391 | + ): Promise<void> { |
| 392 | + return this.error(arg, params); |
| 393 | + } |
| 394 | +} |
| 395 | + |
| 396 | +@injectable() |
| 397 | +class SilentArduinoDaemon extends ArduinoDaemonImpl { |
| 398 | + protected override onData(): void { |
| 399 | + // NOOP |
| 400 | + } |
| 401 | +} |
0 commit comments