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.
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { describe } from 'vitest';
|
|
import { OperatingSystem } from '@/domain/OperatingSystem';
|
|
import { formatAssertionMessage } from '@tests/shared/FormatAssertionMessage';
|
|
import { convertPlatformToOs } from '@/infrastructure/RuntimeEnvironment/Node/NodeOsMapper';
|
|
|
|
describe('NodeOsMapper', () => {
|
|
describe('convertPlatformToOs', () => {
|
|
describe('determines desktop OS', () => {
|
|
// arrange
|
|
interface IDesktopTestCase {
|
|
readonly nodePlatform: NodeJS.Platform;
|
|
readonly expectedOs: ReturnType<typeof convertPlatformToOs>;
|
|
}
|
|
const testScenarios: readonly IDesktopTestCase[] = [ // https://nodejs.org/api/process.html#process_process_platform
|
|
{
|
|
nodePlatform: 'aix',
|
|
expectedOs: undefined,
|
|
},
|
|
{
|
|
nodePlatform: 'darwin',
|
|
expectedOs: OperatingSystem.macOS,
|
|
},
|
|
{
|
|
nodePlatform: 'freebsd',
|
|
expectedOs: undefined,
|
|
},
|
|
{
|
|
nodePlatform: 'linux',
|
|
expectedOs: OperatingSystem.Linux,
|
|
},
|
|
{
|
|
nodePlatform: 'openbsd',
|
|
expectedOs: undefined,
|
|
},
|
|
{
|
|
nodePlatform: 'sunos',
|
|
expectedOs: undefined,
|
|
},
|
|
{
|
|
nodePlatform: 'win32',
|
|
expectedOs: OperatingSystem.Windows,
|
|
},
|
|
];
|
|
testScenarios.forEach(({ nodePlatform, expectedOs }) => {
|
|
it(nodePlatform, () => {
|
|
// act
|
|
const actualOs = convertPlatformToOs(nodePlatform);
|
|
// assert
|
|
expect(actualOs).to.equal(expectedOs, formatAssertionMessage([
|
|
`Expected: "${printResult(expectedOs)}"\n`,
|
|
`Actual: "${printResult(actualOs)}"\n`,
|
|
`Platform: "${nodePlatform}"`,
|
|
]));
|
|
function printResult(os: ReturnType<typeof convertPlatformToOs>): string {
|
|
return os === undefined ? 'undefined' : OperatingSystem[os];
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|