Files
privacy.sexy/tests/checks/desktop-runtime-errors/check-desktop-runtime-errors/utils/platform.ts
undergroundwires 19e42c9c52 Refactor and improve external URL checks
- Move external URL checks to its own module under `tests/`. This
  separates them from integration test, addressing long runs and
  frequent failures that led to ignoring test results.
- Move `check-desktop-runtime-errors` to `tests/checks` to keep all
  test-related checks into one directory.
- Replace `ts-node` with `vite` for running
  `check-desktop-runtime-errors` to maintain a consistent execution
  environment across checks.
- Implement a timeout for each fetch call.
- Be nice to external sources, wait 5 seconds before sending another
  request to an URL under same domain. This solves rate-limiting issues.
- Instead of running test on every push/pull request, run them only
  weekly.
- Do not run tests on each commit/PR but only scheduled (weekly) to
  minimize noise.
- Fix URLs are not captured correctly inside backticks or parenthesis.
2023-09-01 00:18:47 +02:00

32 lines
827 B
TypeScript

import { platform } from 'os';
import { die } from './log';
export enum SupportedPlatform {
macOS,
Windows,
Linux,
}
const NODE_PLATFORM_MAPPINGS: {
readonly [K in SupportedPlatform]: NodeJS.Platform;
} = {
[SupportedPlatform.macOS]: 'darwin',
[SupportedPlatform.Linux]: 'linux',
[SupportedPlatform.Windows]: 'win32',
};
function findCurrentPlatform(): SupportedPlatform | undefined {
const nodePlatform = platform();
for (const key of Object.keys(NODE_PLATFORM_MAPPINGS)) {
const keyAsSupportedPlatform = parseInt(key, 10) as SupportedPlatform;
if (NODE_PLATFORM_MAPPINGS[keyAsSupportedPlatform] === nodePlatform) {
return keyAsSupportedPlatform;
}
}
return die(`Unsupported platform: ${nodePlatform}`);
}
export const CURRENT_PLATFORM: SupportedPlatform = findCurrentPlatform();