Step 1 of adding a backend proxy server (API keys held server-side instead of shipped in the installer). Moves everything app-specific into "Max Avatar/" via git mv (preserves history): src/, tests/, scripts/, assets/, build/, resources/, package.json/-lock.json, electron-builder.yml, electron.vite.config.ts, eslint.config.mjs, playwright.config.ts, vitest.config.mts, sonar-project.properties, tsconfig*.json, Dockerfile, .editorconfig/.env*/.gitignore/.prettier*. CLAUDE.md, README.md, docs/, .claude/, .gitea/, .husky/, .vscode/, and the docker-compose files stay at the repo root, since they'll apply to both the app and the future backend. No application code needed changes (all its internal paths are relative to its own tree). Adjusted what referenced the old root from outside: - .husky/pre-commit: cd into "Max Avatar" before lint-staged - .gitea/workflows/*.yml: working-directory + cache-dependency-path + artifact paths + SonarQube projectBaseDir - docker-compose.yml: build context -> ./Max Avatar - Max Avatar/Dockerfile: node:20-alpine -> node:24-alpine (same node:sqlite issue already fixed elsewhere, never applied here before) - .vscode/launch.json, README.md: updated paths/instructions Verified from Max Avatar/ after the move: npm ci, typecheck, lint, test:coverage (473/473, same coverage numbers), build, and dev all work unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
const ipcMainOn = vi.fn()
|
|
const ipcMainRemoveListener = vi.fn()
|
|
vi.mock('electron', () => ({
|
|
ipcMain: { on: ipcMainOn, removeListener: ipcMainRemoveListener }
|
|
}))
|
|
|
|
const { setMainWindow, sendToRenderer, requestCameraFrame } =
|
|
await import('../../src/main/windowBridge')
|
|
|
|
describe('sendToRenderer()', () => {
|
|
it('should do nothing when no main window has been set', () => {
|
|
expect(() => sendToRenderer('some-channel', 1, 2)).not.toThrow()
|
|
})
|
|
|
|
it('should forward the channel and args to the main window webContents', () => {
|
|
const send = vi.fn()
|
|
setMainWindow({ webContents: { send } } as never)
|
|
sendToRenderer('some-channel', 'a', 'b')
|
|
expect(send).toHaveBeenCalledWith('some-channel', 'a', 'b')
|
|
})
|
|
})
|
|
|
|
describe('requestCameraFrame()', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('should reject immediately when no main window is available', async () => {
|
|
setMainWindow(null as never)
|
|
await expect(requestCameraFrame()).rejects.toThrow(/Fenetre indisponible/)
|
|
})
|
|
|
|
it('should resolve with the data URL once the renderer responds for the matching request', async () => {
|
|
const send = vi.fn()
|
|
setMainWindow({ webContents: { send } } as never)
|
|
|
|
const promise = requestCameraFrame(1000)
|
|
const requestId = send.mock.calls[0]?.[1] as string
|
|
const handler = ipcMainOn.mock.calls.find((c) => c[0] === 'camera-frame-result')?.[1] as (
|
|
event: unknown,
|
|
id: string,
|
|
dataUrl: string | null
|
|
) => void
|
|
|
|
handler({}, requestId, 'data:image/png;base64,abc')
|
|
await expect(promise).resolves.toBe('data:image/png;base64,abc')
|
|
})
|
|
|
|
it('should reject when the renderer responds with null (camera unavailable)', async () => {
|
|
const send = vi.fn()
|
|
setMainWindow({ webContents: { send } } as never)
|
|
|
|
const promise = requestCameraFrame(1000)
|
|
const requestId = send.mock.calls[0]?.[1] as string
|
|
const handler = ipcMainOn.mock.calls.find((c) => c[0] === 'camera-frame-result')?.[1] as (
|
|
event: unknown,
|
|
id: string,
|
|
dataUrl: string | null
|
|
) => void
|
|
|
|
handler({}, requestId, null)
|
|
await expect(promise).rejects.toThrow(/Impossible d'acceder a la camera/)
|
|
})
|
|
|
|
it('should ignore a response for a different request id', async () => {
|
|
const send = vi.fn()
|
|
setMainWindow({ webContents: { send } } as never)
|
|
|
|
const promise = requestCameraFrame(1000)
|
|
const handler = ipcMainOn.mock.calls.find((c) => c[0] === 'camera-frame-result')?.[1] as (
|
|
event: unknown,
|
|
id: string,
|
|
dataUrl: string | null
|
|
) => void
|
|
|
|
handler({}, 'un-autre-id', 'data:image/png;base64,ignore')
|
|
const handlerAgain = ipcMainOn.mock.calls.find((c) => c[0] === 'camera-frame-result')?.[1] as (
|
|
event: unknown,
|
|
id: string,
|
|
dataUrl: string | null
|
|
) => void
|
|
const requestId = send.mock.calls[0]?.[1] as string
|
|
handlerAgain({}, requestId, 'data:image/png;base64,bon')
|
|
await expect(promise).resolves.toBe('data:image/png;base64,bon')
|
|
})
|
|
})
|