mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 07:57:40 +00:00
test: add lighter extensions vitest setup
This commit is contained in:
62
test/setup.shared.ts
Normal file
62
test/setup.shared.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
vi.mock("@mariozechner/pi-ai", async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import("@mariozechner/pi-ai")>();
|
||||
return {
|
||||
...original,
|
||||
getOAuthApiKey: () => undefined,
|
||||
getOAuthProviders: () => [],
|
||||
loginOpenAICodex: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@mariozechner/clipboard", () => ({
|
||||
availableFormats: () => [],
|
||||
getText: async () => "",
|
||||
setText: async () => {},
|
||||
hasText: () => false,
|
||||
getImageBinary: async () => [],
|
||||
getImageBase64: async () => "",
|
||||
setImageBinary: async () => {},
|
||||
setImageBase64: async () => {},
|
||||
hasImage: () => false,
|
||||
getHtml: async () => "",
|
||||
setHtml: async () => {},
|
||||
hasHtml: () => false,
|
||||
getRtf: async () => "",
|
||||
setRtf: async () => {},
|
||||
hasRtf: () => false,
|
||||
clear: async () => {},
|
||||
watch: () => {},
|
||||
callThreadsafeFunction: () => {},
|
||||
}));
|
||||
|
||||
// Ensure Vitest environment is properly set.
|
||||
process.env.VITEST = "true";
|
||||
// Config validation walks plugin manifests; keep an aggressive cache in tests to avoid
|
||||
// repeated filesystem discovery across suites/workers.
|
||||
process.env.OPENCLAW_PLUGIN_MANIFEST_CACHE_MS ??= "60000";
|
||||
// Vitest vm forks can load transitive lockfile helpers many times per worker.
|
||||
// Raise listener budget to avoid noisy MaxListeners warnings and warning-stack overhead.
|
||||
const TEST_PROCESS_MAX_LISTENERS = 128;
|
||||
if (process.getMaxListeners() > 0 && process.getMaxListeners() < TEST_PROCESS_MAX_LISTENERS) {
|
||||
process.setMaxListeners(TEST_PROCESS_MAX_LISTENERS);
|
||||
}
|
||||
|
||||
import { installProcessWarningFilter } from "../src/infra/warning-filter.js";
|
||||
import { withIsolatedTestHome } from "./test-env.js";
|
||||
|
||||
type SharedTestSetupOptions = {
|
||||
loadProfileEnv?: boolean;
|
||||
};
|
||||
|
||||
export function installSharedTestSetup(options?: SharedTestSetupOptions): {
|
||||
cleanup: () => void;
|
||||
tempHome: string;
|
||||
} {
|
||||
const testEnv = withIsolatedTestHome({
|
||||
loadProfileEnv: options?.loadProfileEnv,
|
||||
});
|
||||
installProcessWarningFilter();
|
||||
return testEnv;
|
||||
}
|
||||
Reference in New Issue
Block a user