Skip to content

Commit

Permalink
Merge pull request #64 from codealchemist/unit-test-incomplete-mp3
Browse files Browse the repository at this point in the history
Added unit test to read incomplete mp3 file; added incomplete mp3 file.
  • Loading branch information
Borewit committed Mar 10, 2018
2 parents e7c78fb + bf6d60f commit cc9755d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Binary file added test/samples/incomplete.mp3
Binary file not shown.
1 change: 0 additions & 1 deletion test/test-id3v1.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,4 @@ describe("Parsing MPEG / ID3v1", () => {
});

});

});
24 changes: 24 additions & 0 deletions test/test-mp3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,28 @@ describe("Parse MP3 files", () => {
});
});

describe("should handle incomplete MP3 file", () => {

const filePath = path.join(__dirname, 'samples', "incomplete.mp3");

function checkFormat(format: mm.IFormat) {
t.deepEqual(format.tagTypes, ['ID3v2.3', 'ID3v1.1'], 'format.tagTypes');
t.strictEqual(format.duration, 4349.6751020408165, 'format.duration');
t.strictEqual(format.dataformat, 'mp3', 'format.dataformat');
t.strictEqual(format.lossless, false, 'format.lossless');
t.strictEqual(format.sampleRate, 22050, 'format.sampleRate = 44.1 kHz');
t.strictEqual(format.bitrate, 64000, 'format.bitrate = 128 kbit/sec');
t.strictEqual(format.numberOfChannels, 2, 'format.numberOfChannels 2 (stereo)');
}

it("should decode from a file", () => {

return mm.parseFile(filePath).then(metadata => {
for (const tagType in metadata.native)
throw new Error("Do not expect any native tag type, got: " + tagType);
checkFormat(metadata.format);
});
});
});

});

0 comments on commit cc9755d

Please sign in to comment.