mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-14 07:26:44 +03:00
fix: resolve CI test failures and timeouts
- Update Bun version in CI to match local version (1.2.16) - Add bunfig.toml with 5s test timeout to prevent hanging tests - Mock setTimeout globally in test setup to avoid timing issues - Add NODE_ENV check to skip delays during tests - Fix missing exports in config-encryption mock - Remove retryDelay in tests to ensure immediate execution These changes ensure tests run consistently between local and CI environments
This commit is contained in:
@@ -8,6 +8,23 @@ import { mock } from "bun:test";
|
||||
// Set NODE_ENV to test
|
||||
process.env.NODE_ENV = "test";
|
||||
|
||||
// Mock setTimeout globally to prevent hanging tests
|
||||
const originalSetTimeout = global.setTimeout;
|
||||
global.setTimeout = ((fn: Function, delay?: number) => {
|
||||
// In tests, execute immediately or with minimal delay
|
||||
if (delay && delay > 100) {
|
||||
// For long delays, execute immediately
|
||||
Promise.resolve().then(() => fn());
|
||||
} else {
|
||||
// For short delays, use setImmediate-like behavior
|
||||
Promise.resolve().then(() => fn());
|
||||
}
|
||||
return 0;
|
||||
}) as any;
|
||||
|
||||
// Restore setTimeout for any code that needs real timing
|
||||
(global as any).__originalSetTimeout = originalSetTimeout;
|
||||
|
||||
// Mock the database module to prevent real database access during tests
|
||||
mock.module("@/lib/db", () => {
|
||||
const mockDb = {
|
||||
@@ -66,6 +83,14 @@ mock.module("@/lib/utils/config-encryption", () => {
|
||||
encryptConfigTokens: (config: any) => {
|
||||
// Return the config as-is for tests
|
||||
return config;
|
||||
},
|
||||
getDecryptedGitHubToken: (config: any) => {
|
||||
// Return the token as-is for tests
|
||||
return config.githubConfig?.token || "";
|
||||
},
|
||||
getDecryptedGiteaToken: (config: any) => {
|
||||
// Return the token as-is for tests
|
||||
return config.giteaConfig?.token || "";
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user