Initial project setup
Some checks failed
Build and Test YT2AI Bookmarklet / build-and-test (16.x) (push) Has been cancelled
Build and Test YT2AI Bookmarklet / build-and-test (18.x) (push) Has been cancelled
Build and Test YT2AI Bookmarklet / build-and-test (20.x) (push) Has been cancelled
Build and Test YT2AI Bookmarklet / release (push) Has been cancelled
Build and Test YT2AI Bookmarklet / security-scan (push) Has been cancelled
Some checks failed
Build and Test YT2AI Bookmarklet / build-and-test (16.x) (push) Has been cancelled
Build and Test YT2AI Bookmarklet / build-and-test (18.x) (push) Has been cancelled
Build and Test YT2AI Bookmarklet / build-and-test (20.x) (push) Has been cancelled
Build and Test YT2AI Bookmarklet / release (push) Has been cancelled
Build and Test YT2AI Bookmarklet / security-scan (push) Has been cancelled
Add project structure with package.json, source code, tests, documentation, and GitHub workflows. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
66
tests/setup.js
Normal file
66
tests/setup.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Jest Test Setup
|
||||
* Configure testing environment for YT2AI Bookmarklet
|
||||
*/
|
||||
|
||||
// Mock performance API with proper Jest mocks
|
||||
const performanceMocks = {
|
||||
now: jest.fn(() => Date.now()),
|
||||
mark: jest.fn(),
|
||||
measure: jest.fn()
|
||||
};
|
||||
|
||||
global.performance = performanceMocks;
|
||||
|
||||
// Ensure window.performance is available
|
||||
window.performance = global.performance;
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset DOM
|
||||
document.head.innerHTML = '';
|
||||
document.body.innerHTML = '';
|
||||
document.body.style.overflow = '';
|
||||
|
||||
// Reset window properties
|
||||
delete window.__YT2AI_INITIALIZED__;
|
||||
delete window.__YT2AI_VERSION__;
|
||||
delete window.__YT2AI__;
|
||||
|
||||
// Reset performance mocks
|
||||
performanceMocks.mark.mockClear();
|
||||
performanceMocks.measure.mockClear();
|
||||
performanceMocks.now.mockClear();
|
||||
|
||||
// Clear module cache to allow fresh requires
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// Clear timers
|
||||
jest.clearAllTimers();
|
||||
|
||||
// Clear mocks
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Global test utilities
|
||||
global.mockYouTubeUrl = (videoId = 'dQw4w9WgXcQ') => {
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: {
|
||||
href: `https://www.youtube.com/watch?v=${videoId}`,
|
||||
hostname: 'youtube.com',
|
||||
search: ''
|
||||
},
|
||||
writable: true
|
||||
});
|
||||
};
|
||||
|
||||
global.mockMobileEnvironment = () => {
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
writable: true,
|
||||
value: 'Mozilla/5.0 (Linux; Android 10; SM-G975F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36'
|
||||
});
|
||||
|
||||
Object.defineProperty(window, 'innerWidth', { writable: true, value: 375 });
|
||||
Object.defineProperty(window, 'innerHeight', { writable: true, value: 667 });
|
||||
};
|
||||
Reference in New Issue
Block a user