WIP: Audio context fixes - single context, playback switching, playhead sync improvements
This commit is contained in:
@@ -84,7 +84,7 @@ describe('setupAudioContext', () => {
|
||||
expect(audioService['audioContext']).toBeDefined();
|
||||
});
|
||||
|
||||
it('should create new AudioContext if no methods work', () => {
|
||||
it('should handle case when no audio context methods work but not throw error', () => {
|
||||
const mockWaveSurferNoMethods = {
|
||||
...mockWaveSurfer,
|
||||
backend: {
|
||||
@@ -95,10 +95,11 @@ describe('setupAudioContext', () => {
|
||||
getAudioContext: null
|
||||
};
|
||||
|
||||
// Should not throw error - just continue without audio context
|
||||
audioService['setupAudioContext'](mockWaveSurferNoMethods);
|
||||
|
||||
expect((globalThis as any).window.AudioContext).toHaveBeenCalled();
|
||||
expect(audioService['audioContext']).toBeDefined();
|
||||
// Audio context should remain null in this case
|
||||
expect(audioService['audioContext']).toBeNull();
|
||||
});
|
||||
|
||||
it('should handle suspended audio context by resuming it', () => {
|
||||
@@ -110,7 +111,7 @@ describe('setupAudioContext', () => {
|
||||
expect(suspendedContext.resume).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should throw error if audio context cannot be created', () => {
|
||||
it('should not throw error if audio context cannot be created - just continue', () => {
|
||||
global.window.AudioContext = vi.fn(() => {
|
||||
throw new Error('AudioContext creation failed');
|
||||
}) as any;
|
||||
@@ -125,8 +126,10 @@ describe('setupAudioContext', () => {
|
||||
getAudioContext: null
|
||||
};
|
||||
|
||||
// Should not throw error - just continue without audio context
|
||||
expect(() => audioService['setupAudioContext'](mockWaveSurferNoMethods))
|
||||
.toThrow('AudioContext creation failed');
|
||||
.not.toThrow();
|
||||
expect(audioService['audioContext']).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -190,4 +193,34 @@ describe('getWaveSurferVersion', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('initializeAudioContext', () => {
|
||||
it('should initialize audio context successfully', async () => {
|
||||
const result = await audioService.initializeAudioContext();
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.state).toBe('running');
|
||||
expect(audioService['audioContext']).toBe(result);
|
||||
});
|
||||
|
||||
it('should resume suspended audio context', async () => {
|
||||
const suspendedContext = createMockAudioContext('suspended');
|
||||
global.window.AudioContext = vi.fn(() => suspendedContext) as any;
|
||||
|
||||
const result = await audioService.initializeAudioContext();
|
||||
|
||||
expect(suspendedContext.resume).toHaveBeenCalled();
|
||||
expect(result).toBe(suspendedContext);
|
||||
});
|
||||
|
||||
it('should handle audio context creation errors', async () => {
|
||||
global.window.AudioContext = vi.fn(() => {
|
||||
throw new Error('AudioContext creation failed');
|
||||
}) as any;
|
||||
|
||||
await expect(audioService.initializeAudioContext())
|
||||
.rejects
|
||||
.toThrow('Failed to initialize audio context: AudioContext creation failed');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user