mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-09 06:21:06 -05:00
* chore: update to Go 1.25.3 Signed-off-by: Deluan <deluan@navidrome.org> * chore: update to golangci-lint Signed-off-by: Deluan <deluan@navidrome.org> * chore: update go dependencies Signed-off-by: Deluan <deluan@navidrome.org> * chore: update vite dependencies in package.json and improve EventSource mock in tests - Upgraded @vitejs/plugin-react to version 5.1.0 and @vitest/coverage-v8 to version 4.0.3. - Updated vite to version 7.1.12 and vite-plugin-pwa to version 1.1.0. - Enhanced the EventSource mock implementation in eventStream.test.js for better test isolation. * ci: remove coverage flag from Go test command in pipeline * chore: update Node.js version to v24 in devcontainer, pipeline, and .nvmrc * chore: prettier Signed-off-by: Deluan <deluan@navidrome.org> * chore: update actions/checkout from v4 to v5 in pipeline and update-translations workflows * chore: update JS dependencies remove unused jest-dom import in Linkify.test.jsx * chore: update actions/download-artifact from v4 to v5 in pipeline --------- Signed-off-by: Deluan <deluan@navidrome.org>
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import { describe, it, beforeEach, vi, expect } from 'vitest'
|
|
import { startEventStream } from './eventStream'
|
|
import { serverDown } from './actions'
|
|
import config from './config'
|
|
|
|
class MockEventSource {
|
|
constructor(url) {
|
|
this.url = url
|
|
this.readyState = 1
|
|
this.listeners = {}
|
|
this.onerror = null
|
|
}
|
|
addEventListener(type, handler) {
|
|
this.listeners[type] = handler
|
|
}
|
|
close() {
|
|
this.readyState = 2
|
|
}
|
|
}
|
|
|
|
describe('startEventStream', () => {
|
|
vi.useFakeTimers()
|
|
let dispatch
|
|
let instance
|
|
|
|
beforeEach(() => {
|
|
dispatch = vi.fn()
|
|
global.EventSource = vi.fn().mockImplementation(function (url) {
|
|
instance = new MockEventSource(url)
|
|
return instance
|
|
})
|
|
localStorage.setItem('is-authenticated', 'true')
|
|
localStorage.setItem('token', 'abc')
|
|
config.devNewEventStream = true
|
|
// Mock console.log to suppress output during tests
|
|
vi.spyOn(console, 'log').mockImplementation(() => {})
|
|
})
|
|
|
|
afterEach(() => {
|
|
config.devNewEventStream = false
|
|
})
|
|
|
|
it('reconnects after an error', async () => {
|
|
await startEventStream(dispatch)
|
|
expect(global.EventSource).toHaveBeenCalledTimes(1)
|
|
instance.onerror(new Event('error'))
|
|
expect(dispatch).toHaveBeenCalledWith(serverDown())
|
|
vi.advanceTimersByTime(5000)
|
|
expect(global.EventSource).toHaveBeenCalledTimes(2)
|
|
})
|
|
})
|