Skip to content

Commit

Permalink
✅ Add tests for webm audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumolari committed Aug 31, 2022
1 parent 976be39 commit ab65534
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Binary file added test/file_example_WEBM_480_900KB.webm
Binary file not shown.
14 changes: 14 additions & 0 deletions test/index.integration.test.ts
Expand Up @@ -8,6 +8,7 @@ import getDuration, { getAudioDurationInSeconds } from '../src'
const expectedOGGAudioDuration = 33
const expectedFLACAudioDuration = 97
const expectedWAVAudioDuration = 33
const expectedWEBMAudioDuration = 31
const expectedAudioDurationThreshold = -1

const sampleOGGFilePath = resolvePath(__dirname, './Rayman_2_music_sample.ogg')
Expand All @@ -20,6 +21,10 @@ const sampleFLACFilePath = resolvePath(
'./2L-125_stereo-44k-16b_04.flac'
)
const sampleWAVFilePath = resolvePath(__dirname, './file_example_WAV_1MG.wav')
const sampleWEBMFilePath = resolvePath(
__dirname,
'./file_example_WEBM_480_900KB.webm'
)

describe('get-audio-duration', () => {
it('Should export function under named export, too', () => {
Expand Down Expand Up @@ -53,6 +58,15 @@ describe('get-audio-duration', () => {
)
})

it('Should return proper duration for webm files', async function () {
const inputFileReadStream = fs.createReadStream(sampleWEBMFilePath)
const duration = await getDuration(inputFileReadStream)
expect(duration).toBeCloseTo(
expectedWEBMAudioDuration,
expectedAudioDurationThreshold
)
})

it('Should throw an error if not an audio stream', async () => {
const input = getInput(resolvePath(__dirname, __filename))
const durationPromise = getDuration(input)
Expand Down

0 comments on commit ab65534

Please sign in to comment.