mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-02 02:42:28 +00:00
chore(ai): CI health fixes (test isolation)
Refactored tests to prevent global pollution. Cleaned up global variables in after hooks. - tests/ui/uploadModal-integration.test.mjs: Save and restore global window, document, fetch, etc. - tests/ui/storageService.test.mjs: Save and restore global indexedDB, crypto, etc. - Added daily agent report. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
a4a1de2c85
commit
7fdcecfc64
3 files changed
+83
No files matched your search
@@ -10,6 +10,7 @@ let PROVIDERS;
|
||||
describe("StorageService", () => {
|
||||
let dom;
|
||||
const mockPubkey = "0000000000000000000000000000000000000000000000000000000000000001";
|
||||
const originalGlobals = {};
|
||||
|
||||
// Mock Signer (NIP-04 style for simplicity)
|
||||
// In a real app, this does ECIES. Here we just reverse string or something reversible for test speed/simplicity
|
||||
@@ -34,6 +35,13 @@ describe("StorageService", () => {
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
originalGlobals.window = global.window;
|
||||
originalGlobals.indexedDB = global.indexedDB;
|
||||
originalGlobals.globalThisIndexedDB = globalThis.indexedDB;
|
||||
originalGlobals.IDBKeyRange = global.IDBKeyRange;
|
||||
originalGlobals.globalThisIDBKeyRange = globalThis.IDBKeyRange;
|
||||
originalGlobals.crypto = global.crypto;
|
||||
|
||||
dom = createUiDom();
|
||||
|
||||
// Polyfill Globals
|
||||
@@ -66,6 +74,27 @@ describe("StorageService", () => {
|
||||
|
||||
after(() => {
|
||||
if (dom) dom.cleanup();
|
||||
|
||||
if ('window' in originalGlobals) global.window = originalGlobals.window; else delete global.window;
|
||||
|
||||
if ('indexedDB' in originalGlobals) global.indexedDB = originalGlobals.indexedDB; else delete global.indexedDB;
|
||||
if ('globalThisIndexedDB' in originalGlobals) globalThis.indexedDB = originalGlobals.globalThisIndexedDB; else delete globalThis.indexedDB;
|
||||
|
||||
if ('IDBKeyRange' in originalGlobals) global.IDBKeyRange = originalGlobals.IDBKeyRange; else delete global.IDBKeyRange;
|
||||
if ('globalThisIDBKeyRange' in originalGlobals) globalThis.IDBKeyRange = originalGlobals.globalThisIDBKeyRange; else delete globalThis.IDBKeyRange;
|
||||
|
||||
if ('crypto' in originalGlobals) {
|
||||
if (global.crypto !== originalGlobals.crypto) {
|
||||
try {
|
||||
global.crypto = originalGlobals.crypto;
|
||||
} catch (e) {
|
||||
// If read-only/getter, use defineProperty
|
||||
Object.defineProperty(global, 'crypto', { value: originalGlobals.crypto, writable: true, configurable: true });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete global.crypto;
|
||||
}
|
||||
});
|
||||
|
||||
// Since storageService is a singleton, state might persist.
|
||||
|
||||
@@ -5,6 +5,7 @@ import { createUiDom } from "./helpers/jsdom-test-helpers.mjs";
|
||||
describe("UploadModal Integration", () => {
|
||||
let dom;
|
||||
let UploadModal;
|
||||
const originalGlobals = {};
|
||||
|
||||
// Mock StorageService
|
||||
const mockStorageService = {
|
||||
@@ -77,6 +78,17 @@ describe("UploadModal Integration", () => {
|
||||
`;
|
||||
|
||||
before(async () => {
|
||||
// Capture original globals to restore later
|
||||
originalGlobals.window = global.window;
|
||||
originalGlobals.document = global.document;
|
||||
originalGlobals.EventTarget = global.EventTarget;
|
||||
originalGlobals.alert = global.alert;
|
||||
originalGlobals.HTMLElement = global.HTMLElement;
|
||||
originalGlobals.HTMLInputElement = global.HTMLInputElement;
|
||||
originalGlobals.HTMLButtonElement = global.HTMLButtonElement;
|
||||
originalGlobals.HTMLDivElement = global.HTMLDivElement;
|
||||
originalGlobals.fetch = global.fetch;
|
||||
|
||||
dom = createUiDom();
|
||||
global.window = dom.window;
|
||||
global.document = dom.document;
|
||||
@@ -106,6 +118,17 @@ describe("UploadModal Integration", () => {
|
||||
|
||||
after(() => {
|
||||
if (dom) dom.cleanup();
|
||||
|
||||
// Restore globals
|
||||
if ('window' in originalGlobals) global.window = originalGlobals.window; else delete global.window;
|
||||
if ('document' in originalGlobals) global.document = originalGlobals.document; else delete global.document;
|
||||
if ('EventTarget' in originalGlobals) global.EventTarget = originalGlobals.EventTarget; else delete global.EventTarget;
|
||||
if ('alert' in originalGlobals) global.alert = originalGlobals.alert; else delete global.alert;
|
||||
if ('HTMLElement' in originalGlobals) global.HTMLElement = originalGlobals.HTMLElement; else delete global.HTMLElement;
|
||||
if ('HTMLInputElement' in originalGlobals) global.HTMLInputElement = originalGlobals.HTMLInputElement; else delete global.HTMLInputElement;
|
||||
if ('HTMLButtonElement' in originalGlobals) global.HTMLButtonElement = originalGlobals.HTMLButtonElement; else delete global.HTMLButtonElement;
|
||||
if ('HTMLDivElement' in originalGlobals) global.HTMLDivElement = originalGlobals.HTMLDivElement; else delete global.HTMLDivElement;
|
||||
if ('fetch' in originalGlobals) global.fetch = originalGlobals.fetch; else delete global.fetch;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in new issue
Block a user