setup.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Test setup file for vitest
  2. import { beforeEach, afterEach, vi } from 'vitest'
  3. import { JSDOM } from 'jsdom'
  4. // Create a proper DOM environment
  5. const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>', {
  6. url: 'http://localhost',
  7. pretendToBeVisual: true,
  8. resources: 'usable'
  9. })
  10. // Set up global DOM objects
  11. global.window = dom.window
  12. global.document = dom.window.document
  13. global.navigator = dom.window.navigator
  14. global.HTMLElement = dom.window.HTMLElement
  15. global.Element = dom.window.Element
  16. global.Node = dom.window.Node
  17. // Mock DOM environment setup
  18. beforeEach(() => {
  19. // Reset DOM before each test
  20. document.body.innerHTML = ''
  21. // Ensure documentElement exists and has style property
  22. if (!document.documentElement) {
  23. document.documentElement = document.createElement('html')
  24. }
  25. if (!document.documentElement.style) {
  26. document.documentElement.style = {
  27. setProperty: vi.fn(),
  28. getProperty: vi.fn(),
  29. removeProperty: vi.fn()
  30. }
  31. }
  32. // Add basic CSS custom properties for testing
  33. document.documentElement.style.setProperty('--status-ready', '#00a63e')
  34. document.documentElement.style.setProperty('--status-downloading', '#00a63e')
  35. document.documentElement.style.setProperty('--status-converting', '#155dfc')
  36. document.documentElement.style.setProperty('--status-completed', '#4a5565')
  37. document.documentElement.style.setProperty('--status-error', '#e7000b')
  38. // Mock window.electronAPI (will be overridden by individual tests)
  39. if (!global.window.electronAPI) {
  40. global.window.electronAPI = null
  41. }
  42. // Mock console methods to reduce noise in tests
  43. global.console.log = vi.fn()
  44. global.console.warn = vi.fn()
  45. global.console.error = vi.fn()
  46. })
  47. afterEach(() => {
  48. // Clean up after each test
  49. document.body.innerHTML = ''
  50. // Clear all mocks
  51. vi.clearAllMocks()
  52. })