UNPKG

@4884org/jumble

Version:

🛡️ Advanced bot detection & content protection component with 100ms optimized timing. Automatically detects bots and scrambles text content while obfuscating media to protect websites. Universal implementation works with React, Vue, Angular, Svelte.

104 lines (103 loc) 3.05 kB
// Global test setup // Mock console methods to keep test output clean global.console = { ...console, log: jest.fn(), debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn(), }; // Mock DOM APIs that might not be available in test environment Object.defineProperty(window, 'matchMedia', { writable: true, value: jest.fn().mockImplementation(query => ({ matches: false, media: query, onchange: null, addListener: jest.fn(), // deprecated removeListener: jest.fn(), // deprecated addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), })), }); // Mock IntersectionObserver global.IntersectionObserver = class IntersectionObserver { root = null; rootMargin = ''; thresholds = []; constructor() { } disconnect() { } observe() { } unobserve() { } takeRecords() { return []; } }; // Mock NodeFilter for TreeWalker global.NodeFilter = { SHOW_TEXT: 4, FILTER_ACCEPT: 1, FILTER_REJECT: 2, FILTER_SKIP: 3, }; // Also mock it on window for browsers if (typeof window !== 'undefined') { window.NodeFilter = global.NodeFilter; } // Mock createTreeWalker for DOM traversal tests Object.defineProperty(document, 'createTreeWalker', { value: jest.fn((root, whatToShow, filter) => { // Collect all text nodes that match the filter const textNodes = []; function collectTextNodes(node) { if (node.nodeType === Node.TEXT_NODE) { const parent = node.parentElement; if (parent && filter) { const result = filter.acceptNode(node); if (result === global.NodeFilter.FILTER_ACCEPT) { textNodes.push(node); } } else if (!filter) { textNodes.push(node); } } for (let i = 0; i < node.childNodes.length; i++) { collectTextNodes(node.childNodes[i]); } } collectTextNodes(root); let currentIndex = -1; const walker = { currentNode: root, nextNode: jest.fn(() => { currentIndex++; if (currentIndex < textNodes.length) { walker.currentNode = textNodes[currentIndex]; return textNodes[currentIndex]; } return null; }), root: root, whatToShow: whatToShow, filter: filter, }; return walker; }), writable: true, }); // Setup global test configuration export const config = { namespace: 'jumble-test', testing: { browserHeadless: true, collectCoverageFrom: [ 'src/components/**/*.{ts,tsx}', '!src/components/**/*.spec.ts', '!src/components/**/*.e2e.ts', ], }, }; //# sourceMappingURL=test-setup.js.map