lwe.service.test.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { describe, expect, it, vi } from 'vitest'
  2. vi.mock('electron', () => ({ app: { getPath: () => '/tmp' } }))
  3. vi.mock('./config.service', () => ({
  4. getConfiguredWorkshopPath: () => null,
  5. getLweRepoUrl: () => null,
  6. getLweRepoBranch: () => null,
  7. getLweCmakeArgs: () => null,
  8. getAudioScreen: () => null,
  9. getAmbientVolume: () => null,
  10. getDefaultAudioSensitivity: () => 1,
  11. getDisablePuppetAnimation: () => false
  12. }))
  13. const { buildCleanBuildEnv, buildHotswapLines, parseCustomArgs } = await import('./lwe.service')
  14. describe('parseCustomArgs', () => {
  15. it('splits on whitespace and keeps quoted values together', () => {
  16. expect(parseCustomArgs(`--render-debug skip-effect=726 --set-property foo="bar baz" --x 'a b'`)).toEqual([
  17. '--render-debug',
  18. 'skip-effect=726',
  19. '--set-property',
  20. 'foo=bar baz',
  21. '--x',
  22. 'a b'
  23. ])
  24. expect(parseCustomArgs(' ')).toEqual([])
  25. expect(parseCustomArgs(`--title ""`)).toEqual(['--title', ''])
  26. })
  27. })
  28. describe('buildHotswapLines', () => {
  29. it('writes only the fields that were given', () => {
  30. expect(buildHotswapLines({ volume: 40, xray: false })).toEqual(['volume=40', 'xray=off'])
  31. expect(buildHotswapLines({})).toEqual([])
  32. })
  33. it('replaces the layer lists when either one is present, even empty', () => {
  34. expect(buildHotswapLines({ disabledObjects: [] })).toEqual(['layers=1'])
  35. expect(buildHotswapLines({ disabledObjects: ['12'], enabledObjects: ['fog'] })).toEqual([
  36. 'layers=1',
  37. 'disable-object=12',
  38. 'enable-object=fog'
  39. ])
  40. })
  41. it('writes a full wallpaper swap in the order the engine expects', () => {
  42. expect(
  43. buildHotswapLines({
  44. path: '/w/1',
  45. fps: 30,
  46. offsetX: 0.5,
  47. propertyOverrides: { color: '1 0 0' },
  48. audioSensitivity: { '*': 2 },
  49. soundVolume: { '7': 0.5 }
  50. })
  51. ).toEqual([
  52. 'path=/w/1',
  53. 'fps=30',
  54. 'offset=0.5,0',
  55. 'property=color=1 0 0',
  56. 'audio-sensitivity=*=2',
  57. 'sound-volume=7=0.5'
  58. ])
  59. })
  60. })
  61. describe('buildCleanBuildEnv', () => {
  62. it('drops AppImage mount entries from path lists and the AppImage variables', () => {
  63. const saved = { ...process.env }
  64. process.env.APPDIR = '/tmp/.mount_WE-ManAbc123'
  65. process.env.PATH = '/tmp/.mount_WE-ManAbc123:/tmp/.mount_WE-ManAbc123/usr/sbin:/usr/local/bin:/usr/bin'
  66. process.env.XDG_DATA_DIRS = '/tmp/.mount_WE-ManAbc123/usr/share'
  67. process.env.LD_LIBRARY_PATH = '/tmp/.mount_WE-ManAbc123/usr/lib'
  68. process.env.HOME = '/home/user'
  69. try {
  70. const env = buildCleanBuildEnv()
  71. expect(env.PATH).toBe('/usr/local/bin:/usr/bin')
  72. expect(env.XDG_DATA_DIRS).toBeUndefined()
  73. expect(env.LD_LIBRARY_PATH).toBeUndefined()
  74. expect(env.APPDIR).toBeUndefined()
  75. expect(env.HOME).toBe('/home/user')
  76. } finally {
  77. process.env = saved
  78. }
  79. })
  80. })