This commit fixes an issue seen on certain Windows environments (Windows 10 22H2 and 11 23H2 Pro Azure VMs) where scripts were being deleted during execution due to temporary directory usage. To resolve this, scripts are now stored in a persistent directory, enhancing reliability for long-running scripts and improving auditability along with troubleshooting. Key changes: - Move script execution logic to the `main` process from `preloader` to utilize Electron's `app.getPath`. - Improve runtime environment detection for non-browser environments to allow its usage in Electron main process. - Introduce a secure module to expose IPC channels from the main process to the renderer via the preloader process. Supporting refactorings include: - Simplify `CodeRunner` interface by removing the `tempScriptFolderName` parameter. - Rename `NodeSystemOperations` to `NodeElectronSystemOperations` as it now wraps electron APIs too, and convert it to class for simplicity. - Rename `TemporaryFileCodeRunner` to `ScriptFileCodeRunner` to reflect its new functinoality. - Rename `SystemOperations` folder to `System` for simplicity. - Rename `HostRuntimeEnvironment` to `BrowserRuntimeEnvironment` for clarity. - Refactor main Electron process configuration to align with latest Electron documentation/recommendations. - Refactor unit tests `BrowserRuntimeEnvironment` to simplify singleton workaround. - Use alias imports like `electron/main` and `electron/common` for better clarity.
67 lines
2.9 KiB
TypeScript
67 lines
2.9 KiB
TypeScript
import { describe, it, afterEach } from 'vitest';
|
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
|
import { MobileSafariActivePseudoClassEnabler } from '@/presentation/bootstrapping/Modules/MobileSafariActivePseudoClassEnabler';
|
|
import { EventName, createWindowEventSpies } from '@tests/shared/Spies/WindowEventSpies';
|
|
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
|
|
import { isTouchEnabledDevice } from '@/infrastructure/RuntimeEnvironment/Browser/TouchSupportDetection';
|
|
import { BrowserRuntimeEnvironment } from '@/infrastructure/RuntimeEnvironment/Browser/BrowserRuntimeEnvironment';
|
|
import { MobileSafariDetectionTestCases } from './MobileSafariDetectionTestCases';
|
|
|
|
describe('MobileSafariActivePseudoClassEnabler', () => {
|
|
describe('bootstrap', () => {
|
|
MobileSafariDetectionTestCases.forEach(({
|
|
description, userAgent, supportsTouch, expectedResult,
|
|
}) => {
|
|
it(description, () => {
|
|
// arrange
|
|
const expectedEvent: EventName = 'touchstart';
|
|
patchUserAgent(userAgent, afterEach);
|
|
const { isAddEventCalled, currentListeners } = createWindowEventSpies(afterEach);
|
|
const patchedEnvironment = new TouchSupportControlledBrowserEnvironment(supportsTouch);
|
|
const sut = new MobileSafariActivePseudoClassEnabler(patchedEnvironment);
|
|
// act
|
|
sut.bootstrap();
|
|
// assert
|
|
const isSet = isAddEventCalled(expectedEvent);
|
|
expect(isSet).to.equal(expectedResult, formatAssertionMessage([
|
|
`Expected result\t\t: ${expectedResult ? 'true (mobile Safari)' : 'false (not mobile Safari)'}`,
|
|
`Actual result\t\t: ${isSet ? 'true (mobile Safari)' : 'false (not mobile Safari)'}`,
|
|
`User agent\t\t: ${navigator.userAgent}`,
|
|
`Touch supported\t\t: ${supportsTouch}`,
|
|
`Current OS\t\t: ${patchedEnvironment.os === undefined ? 'unknown' : OperatingSystem[patchedEnvironment.os]}`,
|
|
`Is desktop?\t\t: ${patchedEnvironment.isDesktop ? 'Yes (Desktop app)' : 'No (Browser)'}`,
|
|
`Listeners (${currentListeners.length})\t\t: ${JSON.stringify(currentListeners)}`,
|
|
]));
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function patchUserAgent(
|
|
userAgent: string,
|
|
restoreCallback: (restoreFunc: () => void) => void,
|
|
) {
|
|
const originalNavigator = window.navigator;
|
|
const userAgentGetter = { get: () => userAgent };
|
|
window.navigator = Object.create(navigator, {
|
|
userAgent: userAgentGetter,
|
|
});
|
|
restoreCallback(() => {
|
|
Object.assign(window, {
|
|
navigator: originalNavigator,
|
|
});
|
|
});
|
|
}
|
|
|
|
function getTouchDetectorMock(
|
|
isTouchEnabled: boolean,
|
|
): typeof isTouchEnabledDevice {
|
|
return () => isTouchEnabled;
|
|
}
|
|
|
|
class TouchSupportControlledBrowserEnvironment extends BrowserRuntimeEnvironment {
|
|
public constructor(isTouchEnabled: boolean) {
|
|
super(window, undefined, undefined, getTouchDetectorMock(isTouchEnabled));
|
|
}
|
|
}
|