This commit improves the handling of paths with spaces or special characters during script execution in the desktop application. Key improvements: - Paths are now quoted for macOS/Linux, addressing issues with whitespace or single quotes. - Windows paths are enclosed in double quotes to handle special characters. Other supporting changes: - Add more documentation for terminal execution commands. - Refactor terminal script file execution into a dedicated file for improved separation of concerns. - Refactor naming of `RuntimeEnvironment` to align with naming conventions (no interface with I prefix) and for clarity. - Refactor `TemporaryFileCodeRunner` to simplify it by removing the `os` parameter and handling OS-specific logic within the filename generator instead. - Refactor `fileName` to `filename` for consistency.
81 lines
2.8 KiB
TypeScript
81 lines
2.8 KiB
TypeScript
import {
|
|
describe, it, beforeEach, afterEach,
|
|
} from 'vitest';
|
|
import { RuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/RuntimeEnvironment';
|
|
import { ClientLoggerFactory } from '@/presentation/bootstrapping/ClientLoggerFactory';
|
|
import { Logger } from '@/application/Common/Log/Logger';
|
|
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<Logger>,
|
|
readonly environment: RuntimeEnvironment,
|
|
}> = [
|
|
{
|
|
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: RuntimeEnvironment) {
|
|
super(environment);
|
|
}
|
|
}
|