Improve desktop runtime execution tests
Test improvements: - Capture titles for all macOS windows, not just the frontmost. - Incorporate missing application log files. - Improve log clarity with enriched context. - Improve application termination on macOS by reducing grace period. - Ensure complete application termination on macOS. - Validate Vue application loading through an initial log. - Support ignoring environment-specific `stderr` errors. - Do not fail the test if working directory cannot be deleted. - Use retry pattern when installing dependencies due to network errors. Refactorings: - Migrate the test code to TypeScript. - Replace deprecated `rmdir` with `rm` for error-resistant directory removal. - Improve sanity checking by shifting from App.vue to Vue bootstrapper. - Centralize environment variable management with `EnvironmentVariables` construct. - Rename infrastructure/Environment to RuntimeEnvironment for clarity. - Isolate WindowVariables and SystemOperations from RuntimeEnvironment. - Inject logging via preloader. - Correct mislabeled RuntimeSanity tests. Configuration: - Introduce `npm run check:desktop` for simplified execution. - Omit `console.log` override due to `nodeIntegration` restrictions and reveal logging functionality using context-bridging.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
describe, it, beforeEach, afterEach,
|
||||
} from 'vitest';
|
||||
import { IRuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/IRuntimeEnvironment';
|
||||
import { ClientLoggerFactory } from '@/presentation/bootstrapping/ClientLoggerFactory';
|
||||
import { ILogger } from '@/infrastructure/Log/ILogger';
|
||||
import { WindowInjectedLogger } from '@/infrastructure/Log/WindowInjectedLogger';
|
||||
import { ConsoleLogger } from '@/infrastructure/Log/ConsoleLogger';
|
||||
import { NoopLogger } from '@/infrastructure/Log/NoopLogger';
|
||||
import { RuntimeEnvironmentStub } from '@tests/unit/shared/Stubs/RuntimeEnvironmentStub';
|
||||
import { Constructible } from '@/TypeHelpers';
|
||||
import { itIsSingleton } from '@tests/unit/shared/TestCases/SingletonTests';
|
||||
import { LoggerStub } from '@tests/unit/shared/Stubs/LoggerStub';
|
||||
|
||||
describe('ClientLoggerFactory', () => {
|
||||
describe('Current', () => {
|
||||
itIsSingleton({
|
||||
getter: () => ClientLoggerFactory.Current,
|
||||
expectedType: ClientLoggerFactory,
|
||||
});
|
||||
});
|
||||
describe('logger instantiation based on environment', () => {
|
||||
const originalWindow = { ...window };
|
||||
beforeEach(() => {
|
||||
Object.assign(window, { log: new LoggerStub() });
|
||||
});
|
||||
afterEach(() => {
|
||||
Object.assign(window, originalWindow);
|
||||
});
|
||||
const testCases: Array<{
|
||||
readonly description: string,
|
||||
readonly expectedType: Constructible<ILogger>,
|
||||
readonly environment: IRuntimeEnvironment,
|
||||
}> = [
|
||||
{
|
||||
description: 'desktop environment',
|
||||
expectedType: WindowInjectedLogger,
|
||||
environment: new RuntimeEnvironmentStub()
|
||||
.withIsDesktop(true),
|
||||
},
|
||||
{
|
||||
description: 'non-production and desktop environment',
|
||||
expectedType: WindowInjectedLogger,
|
||||
environment: new RuntimeEnvironmentStub()
|
||||
.withIsDesktop(true)
|
||||
.withIsNonProduction(true),
|
||||
},
|
||||
{
|
||||
description: 'non-production without desktop',
|
||||
expectedType: ConsoleLogger,
|
||||
environment: new RuntimeEnvironmentStub()
|
||||
.withIsDesktop(false)
|
||||
.withIsNonProduction(true),
|
||||
},
|
||||
{
|
||||
description: 'production without desktop',
|
||||
expectedType: NoopLogger,
|
||||
environment: new RuntimeEnvironmentStub()
|
||||
.withIsDesktop(false)
|
||||
.withIsNonProduction(false),
|
||||
},
|
||||
];
|
||||
testCases.forEach(({ description, expectedType, environment }) => {
|
||||
it(`instantiates ${expectedType.name} for ${description}`, () => {
|
||||
// arrange
|
||||
const factory = new TestableClientLoggerFactory(environment);
|
||||
// act
|
||||
const { logger } = factory;
|
||||
// assert
|
||||
expect(logger).to.be.instanceOf(expectedType);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
class TestableClientLoggerFactory extends ClientLoggerFactory {
|
||||
public constructor(environment: IRuntimeEnvironment) {
|
||||
super(environment);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user