Files
moeka-project/packages/testing-audio/src/expect-extend.test.ts
T
2026-08-26 19:49:58 +08:00

61 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { PiniaActionEvent } from '@proj-airi/stage-shared/types/pinia-action-event'
import type { AudioInputObservations } from './types'
import { describe, it } from 'vitest'
import { expect, installAudioInputMatchers } from './expect-extend'
installAudioInputMatchers()
describe('audio input matchers', () => {
it('normalizes transcription case, width, punctuation, and whitespace', async () => {
const session = createAudioInputSession(['lease, SAY hello!'])
await expect(session).toHaveTranscriptions([
['please say hello'],
])
})
it('reports a failed transcription action', async () => {
const session = createAudioInputSession([], [{
...actionEvent('modules:hearing:speech:audio-input-pipeline', 'transcribeForRecording'),
errorMessage: 'Request failed',
status: 'failed',
}])
await expect(expect(session).toHaveCompletedTranscription()).rejects.toThrow('ASR failed: Request failed')
})
})
function actionEvent(storeId: string, actionName: string): PiniaActionEvent {
return {
actionName,
invocationId: `${storeId}:${actionName}`,
status: 'completed',
storeId,
timestamp: 0,
}
}
function createAudioInputSession(
transcriptions: string[],
actions: PiniaActionEvent[] = [],
): AudioInputObservations {
return {
capturedTranscriptionAudio: async () => [],
completedSpans: async () => [],
piniaActionEvents: async () => actions,
streamingTranscriptionUpdates: async () => [],
transcriptionResults: async () => transcriptions,
waitForPiniaAction: async () => {
throw new Error('This matcher fixture does not observe Pinia actions.')
},
waitForStreamingTranscriptionReady: async () => {},
waitForTurn: async () => {
throw new Error('This matcher fixture does not observe completed turns.')
},
waitForVadReady: async () => {},
}
}