mirror of
https://github.com/CloakHQ/CloakBrowser.git
synced 2026-06-23 11:41:46 +02:00
test: add comprehensive unit tests for all public APIs
Python (75 new tests): - launch_context(): viewport, timezone bypass, geoip, close cleanup, error cleanup - launch_persistent_context(): sync + async, args, proxy, close/pw.stop() - config: binary paths, archive names, cache dir, stealth args profiles - extract: tar/zip with path traversal protection, .app bundle preservation - ensure_binary(), clear_cache(), check_for_update(), version markers - geoip: private IP detection JavaScript (26 new tests): - puppeteer wrapper: stealth args, proxy string/dict, auth monkey-patch - launchContext/launchPersistentContext: viewport, timezone, proxy, close - ensureBinary, clearCache, checkForUpdate, archive helpers Total: 169 Python + 88 JS tests (was 59 + 47)
This commit is contained in:
@@ -9,7 +9,11 @@ import {
|
||||
versionNewer,
|
||||
} from "../src/config.js";
|
||||
import {
|
||||
binaryInfo,
|
||||
checkForUpdate,
|
||||
checkWrapperUpdate,
|
||||
clearCache,
|
||||
ensureBinary,
|
||||
getLatestChromiumVersion,
|
||||
parseChecksums,
|
||||
resetWrapperUpdateChecked,
|
||||
@@ -271,3 +275,53 @@ describe("effective version", () => {
|
||||
expect(getEffectiveVersion()).toBe(getChromiumVersion());
|
||||
});
|
||||
});
|
||||
|
||||
describe("ensureBinary", () => {
|
||||
afterEach(() => {
|
||||
delete process.env.CLOAKBROWSER_BINARY_PATH;
|
||||
});
|
||||
|
||||
it("returns local override when set", async () => {
|
||||
// Use this test file as a "binary" that exists
|
||||
process.env.CLOAKBROWSER_BINARY_PATH = __filename;
|
||||
const result = await ensureBinary();
|
||||
expect(result).toBe(__filename);
|
||||
});
|
||||
|
||||
it("throws when local override path missing", async () => {
|
||||
process.env.CLOAKBROWSER_BINARY_PATH = "/nonexistent/chrome";
|
||||
await expect(ensureBinary()).rejects.toThrow("does not exist");
|
||||
});
|
||||
});
|
||||
|
||||
describe("clearCache", () => {
|
||||
it("does not throw when cache dir missing", () => {
|
||||
const orig = process.env.CLOAKBROWSER_CACHE_DIR;
|
||||
process.env.CLOAKBROWSER_CACHE_DIR = "/tmp/cloakbrowser-test-nonexistent";
|
||||
expect(() => clearCache()).not.toThrow();
|
||||
if (orig) {
|
||||
process.env.CLOAKBROWSER_CACHE_DIR = orig;
|
||||
} else {
|
||||
delete process.env.CLOAKBROWSER_CACHE_DIR;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkForUpdate", () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("returns null when no newer version", async () => {
|
||||
vi.spyOn(globalThis, "fetch").mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => [],
|
||||
} as Response);
|
||||
expect(await checkForUpdate()).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null on network error", async () => {
|
||||
vi.spyOn(globalThis, "fetch").mockRejectedValue(new Error("timeout"));
|
||||
expect(await checkForUpdate()).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user