Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions package/expo-package/src/optionalDependencies/AudioVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,4 @@ try {
// do nothing
}

if (!AudioComponent) {
console.log(
'The audio library is currently not installed. To allow in-app audio playback, install the "expo-av" package.',
);
}

export { AudioComponent, RecordingObject };
7 changes: 7 additions & 0 deletions package/expo-package/src/optionalDependencies/Sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ try {
// do nothing
}

// Playback and recording use expo-audio, or the deprecated expo-av when only that is installed.
if (!ExpoAudioComponent && !AudioComponent) {
console.log(
'The audio library is currently not installed. To allow in-app audio playback and voice recording, install the "expo-audio" package.',
);
}

export const Sound = {
// Always try to prioritize expo-audio if it's there.
initializeSound: ExpoAudioComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// A missing module is a mock whose factory throws, as `require` does for a package that isn't installed.
const mockOptionalModule = (name: string, exports?: object) =>
jest.doMock(
name,
() => {
if (!exports) {
throw new Error(`Cannot find module '${name}'`);
}
return exports;
},
{ virtual: true },
);

const audioLibraryLogsOnLoad = () => {
const log = jest.spyOn(console, 'log').mockImplementation(() => undefined);
require('../Sound');
return log.mock.calls
.flat()
.filter((message) => typeof message === 'string' && message.includes('audio library'));
};

describe('expo Sound', () => {
afterEach(() => {
jest.resetModules();
jest.restoreAllMocks();
});

it('asks for no audio library when only expo-audio is installed', () => {
mockOptionalModule('expo-audio', { AudioModule: {}, createAudioPlayer: jest.fn() });
mockOptionalModule('expo-av');

expect(audioLibraryLogsOnLoad()).toEqual([]);
});

it('asks for no audio library when only expo-av is installed', () => {
mockOptionalModule('expo-audio');
mockOptionalModule('expo-av', { Audio: {} });

expect(audioLibraryLogsOnLoad()).toEqual([]);
});

it('asks for expo-audio when no audio library is installed', () => {
mockOptionalModule('expo-audio');
mockOptionalModule('expo-av');

expect(audioLibraryLogsOnLoad()).toEqual([expect.stringContaining('"expo-audio"')]);
});
});
Loading