gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit8ed6da458ed6da45|||PR README: media-player pin df9e7dfmre8ed6da45/tests/jb14.mjs

7.0 KB

  1. // tests/jb14.mjs — JB14 (jukebox#14): the Songs screen opens the way it was left: the sort the listener chose is remembered, the sort control shows it,
  2. // and the rows really are in that order (before: the browser restored 'most played' in the control while the rows stayed sorted by artist).
  3. // Own server on a generated database of 300 songs, headless Chrome. (Header of the older gate follows.) JB13: Own server on a generated database of 300 songs (one 3 s tone), headless Chrome.
  4. // Songs sorted by plays and Favourites: the screen is open, a play is counted for another song through POST /api/played/<id> (the order
  5. // changes), then a row is tapped: the song that plays (currentSrc of the audio element) must be the tapped row's id. The queue goes on
  6. // from that song's place in the new order, and the rows on the screen refresh to what the server now has.
  7. // node tests/jb14.mjs env: JB14_PORT (default 8736), JB14_DIR (scratch), JB14_ROOT (checkout to test), HL_PORT_BASE (default 8520), JUKEBOX_COLD_MS
  8. import { spawn, execFileSync } from 'node:child_process'
  9. import { rmSync, mkdirSync } from 'node:fs'
  10. import { dirname, join } from 'node:path'
  11. import { fileURLToPath } from 'node:url'
  12. process.env.HL_CHROME = process.env.HL_CHROME || '/opt/google/chrome/chrome'
  13. process.env.HL_PORT_BASE = process.env.HL_PORT_BASE || '8520'
  14. const { launchBrowser, sleep } = await import('./cdp.mjs')
  15. const root = process.env.JB14_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..')
  16. const dir = process.env.JB14_DIR || '/media/STORAGE/claude-scratch/atlas/JB14/gate'
  17. const port = Number(process.env.JB14_PORT || 8736)
  18. const BASE = `http://127.0.0.1:${port}`
  19. const COLD_MS = Number(process.env.JUKEBOX_COLD_MS || 150000)
  20. let pass = 0, fail = 0
  21. const check = (name, ok, detail = '') => { console.log((ok ? 'ok ' : 'FAIL ') + name + (ok ? '' : ' — ' + detail)); if (ok) pass++; else fail++ }
  22. mkdirSync(dir, { recursive: true })
  23. process.env.TMPDIR = dir
  24. let server = null, browser = null, log = ''
  25. async function stop() {
  26. if (browser) { try { await browser.close() } catch {} browser = null }
  27. if (server) { try { server.kill('SIGTERM') } catch {} await sleep(500); server = null }
  28. }
  29. process.on('SIGINT', async () => { await stop(); process.exit(1) })
  30. const storage = join(dir, 'storage')
  31. const tone = join(dir, 'tone3.mp3')
  32. rmSync(storage, { recursive: true, force: true })
  33. execFileSync('ffmpeg', ['-v', 'error', '-y', '-f', 'lavfi', '-i', 'sine=frequency=440:duration=3', '-q:a', '9', tone])
  34. const cover = join(root, 'tests/fixtures/withcover/folder.jpg')
  35. execFileSync(join(root, 'bin/hybriel'), [join(root, 'tools/make-test-db.hl'), tone, cover, '300'], { env: { ...process.env, JUKEBOX_STORAGE: storage }, encoding: 'utf8', timeout: 600000 })
  36. server = spawn(join(root, 'bin/hybriel'), ['project.hl'], { cwd: root, env: { ...process.env, JUKEBOX_PORT: String(port), JUKEBOX_STORAGE: storage, JUKEBOX_AUTOSCAN: '0', JUKEBOX_WATCH: '0', HL_HOST: '127.0.0.1' }, stdio: ['ignore', 'pipe', 'pipe'] })
  37. console.log('server pid ' + server.pid)
  38. server.stdout.on('data', (d) => { log += d }); server.stderr.on('data', (d) => { log += d })
  39. const api = async (path) => (await fetch(BASE + path)).json()
  40. try {
  41. for (const t0 = Date.now(); ; ) {
  42. try { if ((await fetch(BASE + '/api/stats')).ok) break } catch {}
  43. if (Date.now() - t0 > COLD_MS) { console.log(log); throw new Error('the server did not come up') }
  44. await sleep(500)
  45. }
  46. browser = await launchBrowser()
  47. console.log('chrome pid ' + browser.proc?.pid)
  48. const page = await browser.newPage()
  49. const ev = (e) => page.evaluate(e)
  50. const press = async (key, code, vk) => { await page.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', key, code, windowsVirtualKeyCode: vk }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code, windowsVirtualKeyCode: vk }) }
  51. await page.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true })
  52. const titles = () => ev(`[...document.querySelectorAll('virtual-list .vl-row:not(.blank) .vl-title')].slice(0, 8).map((e) => e.textContent)`)
  53. const shown = () => ev(`document.querySelector('#sort').value`)
  54. const apiTitles = async (sort) => (await api('/api/songs?sort=' + sort + '&limit=8')).items.map((s) => s.title)
  55. const settle = async () => { await page.waitFor(`document.querySelectorAll('virtual-list .vl-row:not(.blank)').length > 4 && document.querySelector('virtual-list .vl-row .vl-title').textContent !== ''`, { label: 'rows' }); await sleep(700) }
  56. // some plays so that "most played" differs from the artist order
  57. const byArtist = (await api('/api/songs?sort=artist&limit=200')).items
  58. for (const [i, n] of [[150, 4], [151, 3], [152, 2]]) for (let k = 0; k < n; k++) await fetch(BASE + '/api/played/' + byArtist[i].id, { method: 'POST' })
  59. await page.goto(BASE + '/')
  60. await settle()
  61. check('first visit: the control shows "artist" and the rows are in artist order', (await shown()) === 'artist' && JSON.stringify(await titles()) === JSON.stringify(await apiTitles('artist')), await shown())
  62. await page.focus('#sort')
  63. for (let i = 0; i < 3; i++) { await press('ArrowDown', 'ArrowDown', 40); await sleep(300) }
  64. await settle()
  65. check('chosen "most played": the rows are in plays order', (await shown()) === 'plays' && JSON.stringify(await titles()) === JSON.stringify(await apiTitles('plays')), JSON.stringify(await titles()))
  66. // the browser reloads the page (and may restore the control by itself)
  67. await page.send('Page.reload')
  68. await settle()
  69. const t1 = JSON.stringify(await titles())
  70. check('after a reload: the control shows "most played" and the rows ARE in plays order', (await shown()) === 'plays' && t1 === JSON.stringify(await apiTitles('plays')), `control ${await shown()}, rows ${t1}`)
  71. // a fresh tab (nothing restored by the browser): the screen opens the way it was left
  72. const tab2 = await browser.newPage()
  73. await tab2.goto(BASE + '/')
  74. await tab2.waitFor(`document.querySelectorAll('virtual-list .vl-row:not(.blank)').length > 4 && document.querySelector('virtual-list .vl-row .vl-title').textContent !== ''`, { label: 'rows in the fresh tab' })
  75. await sleep(700)
  76. const t2 = JSON.stringify(await tab2.evaluate(`[...document.querySelectorAll('virtual-list .vl-row:not(.blank) .vl-title')].slice(0, 8).map((e) => e.textContent)`))
  77. const c2 = await tab2.evaluate(`document.querySelector('#sort').value`)
  78. check('a fresh tab opens sorted by plays, the control says so', c2 === 'plays' && t2 === JSON.stringify(await apiTitles('plays')), `control ${c2}, rows ${t2}`)
  79. await tab2.close()
  80. // choosing another sort is remembered too
  81. await page.focus('#sort')
  82. await press('ArrowUp', 'ArrowUp', 38); await sleep(300); await press('ArrowUp', 'ArrowUp', 38) // album, then title
  83. await settle()
  84. await page.send('Page.reload')
  85. await settle()
  86. check('title chosen, reloaded: the control and the rows agree (title)', (await shown()) === 'title' && JSON.stringify(await titles()) === JSON.stringify(await apiTitles('title')), `control ${await shown()}`)
  87. } finally {
  88. await stop()
  89. }
  90. console.log(`${pass} passed, ${fail} failed`)
  91. process.exit(fail ? 1 : 0)

Branches

Latest commits

  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
  • 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
  • 1fecd6a7Merge branch 'records-day39' into mainJukebox
  • d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
  • 5fa19e89Merge branch 'day39' into mainJukebox
  • cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
  • f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
  • 9f5c6532Merge branch 'status-22-pr' into mainJukebox
  • 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
  • 29d2029cRecords: PR-only rule (Kunibert)mre
  • adacb0abRecords: neutral ticket rule, #22 decision recordedmre
  • b2d6f121Records: #308 hold liftedmre
  • 7ab67533Records: day39 on hold (hybriel#308)mre
  • 22f21739Records: note rebase before mergemre
  • f7368ea3Records: mission 011 day39, waits for lisbethmre
  • 9515d2cdRecords: jb20 livemre
  • 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
  • 277a2722README: provenance linemre
  • 4169ca6aREADME: sync pinmre