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.
This commit is contained in:
40
tests/checks/desktop-runtime-errors/main.spec.ts
Normal file
40
tests/checks/desktop-runtime-errors/main.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { test } from 'vitest';
|
||||
import { main } from './check-desktop-runtime-errors/main';
|
||||
import { COMMAND_LINE_FLAGS, CommandLineFlag } from './check-desktop-runtime-errors/cli-args';
|
||||
|
||||
test('should have no desktop runtime errors', async () => {
|
||||
// arrange
|
||||
setCommandLineFlagsFromEnvironmentVariables();
|
||||
let exitCode: number;
|
||||
global.process.exit = (code?: number): never => {
|
||||
exitCode = code;
|
||||
return undefined as never;
|
||||
};
|
||||
// act
|
||||
await main();
|
||||
// assert
|
||||
expect(exitCode).to.equal(0);
|
||||
}, {
|
||||
timeout: 60 /* minutes */ * 10000,
|
||||
});
|
||||
|
||||
/*
|
||||
Map environment variables to CLI arguments for compatibility with Vitest.
|
||||
*/
|
||||
function setCommandLineFlagsFromEnvironmentVariables() {
|
||||
const flagEnvironmentVariableKeyMappings: {
|
||||
readonly [key in CommandLineFlag]: string;
|
||||
} = {
|
||||
[CommandLineFlag.ForceRebuild]: 'BUILD',
|
||||
[CommandLineFlag.TakeScreenshot]: 'SCREENSHOT',
|
||||
};
|
||||
Object.entries(flagEnvironmentVariableKeyMappings)
|
||||
.forEach(([flag, environmentVariableKey]) => {
|
||||
if (process.env[environmentVariableKey] !== undefined) {
|
||||
process.argv = [
|
||||
...process.argv,
|
||||
COMMAND_LINE_FLAGS[flag],
|
||||
];
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user