Skip to content

Commit

Permalink
test: add test for unsupported frames
Browse files Browse the repository at this point in the history
  • Loading branch information
eidoriantan committed Jun 9, 2024
1 parent 3eab0c1 commit f1b0030
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
17 changes: 16 additions & 1 deletion test/globals.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports.bytes = new Uint8Array([
67, 79, 77, 77, 69, 78, 84, ...new Array(22).fill(0), 1, 12
])

exports.bytesUnsupported = new Uint8Array([
exports.bytesInvalid = new Uint8Array([
73, 68, 51, 3, 0, 0, 0, 0, 0, 57,
84, 73, 84, 50, 0, 0, 0, 15, 0, 0,
1, 255, 254, 116, 0, 105, 0, 116, 0, 108, 0, 101, 0, 0, 0,
Expand All @@ -29,6 +29,21 @@ exports.bytesUnsupported = new Uint8Array([
67, 79, 77, 77, 69, 78, 84, ...new Array(22).fill(0), 1, 12
])

exports.bytesUnsupported = new Uint8Array([
73, 68, 51, 3, 0, 0, 0, 0, 0, 40,
84, 73, 84, 50, 0, 0, 0, 15, 0, 0,
1, 255, 254, 116, 0, 105, 0, 116, 0, 108, 0, 101, 0, 0, 0,
85, 78, 83, 85, 0, 0, 0, 5, 0, 0,
1, 2, 3, 4, 5,
255, 251, 224, 0, 0, 0, 0, 0, 170, 170, 170, 170, 170, 170,
84, 65, 71,
84, 73, 84, 76, 69, ...new Array(25).fill(0),
65, 82, 84, 73, 83, 84, ...new Array(24).fill(0),
65, 76, 66, 85, 77, ...new Array(25).fill(0),
50, 48, 50, 48,
67, 79, 77, 77, 69, 78, 84, ...new Array(22).fill(0), 1, 12
])

exports.bytesv2 = new Uint8Array([
73, 68, 51, 2, 0, 0, 0, 0, 0, 43,
84, 84, 50, 0, 0, 15,
Expand Down
45 changes: 38 additions & 7 deletions test/id3v2/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert')

const MP3Tag = require('../../dist/mp3tag.js')
const { bytes, bytesUnsupported, bytesv2 } = require('../globals.cjs')
const { bytes, bytesInvalid, bytesUnsupported, bytesv2 } = require('../globals.cjs')

describe('ID3v2', function () {
describe('ID3v2.2', function () {
Expand Down Expand Up @@ -238,21 +238,23 @@ describe('ID3v2', function () {
})
})

describe('MP3 with unsupported frames', function () {
describe('MP3 with invalid frames', function () {
beforeEach(function () {
this.mp3tag = new MP3Tag(bytesUnsupported.buffer)
this.mp3tag = new MP3Tag(bytesInvalid.buffer)
this.mp3tag.read({ id3v1: false })
if (this.mp3tag.error) throw new Error(this.mp3tag.error)
})

it('Throws error with unsupported frames', function () {
it('Throws error with invalid frames', function () {
this.mp3tag.save({
strict: true,
id3v1: { include: false },
id3v2: {
include: true,
version: 4,
skipUnsupported: false
// TODO: `skipUnsupported` is deprecated
skipUnsupported: false,
unsupported: true
}
})

Expand All @@ -265,13 +267,14 @@ describe('ID3v2', function () {
})
})

it('Skips unsupported frames', function () {
it('Skips invalid frames', function () {
this.mp3tag.save({
strict: true,
id3v1: { include: false },
id3v2: {
include: true,
version: 4
version: 4,
unsupported: false
}
})

Expand All @@ -282,4 +285,32 @@ describe('ID3v2', function () {
assert.strictEqual(this.mp3tag.tags.v2.TYER, undefined)
})
})

describe('MP3 with unsupported frames', function () {
beforeEach(function () {
this.mp3tag = new MP3Tag(bytesUnsupported.buffer)
})

it('Read unsupported frames as an array', function () {
this.mp3tag.read({
id3v1: false,
unsupported: true
})

if (this.mp3tag.error) throw new Error(this.mp3tag.error)

assert.deepStrictEqual(this.mp3tag.tags.v2Details.version, [3, 0])
assert.deepStrictEqual(this.mp3tag.tags.v2.TIT2, 'title')
assert.deepStrictEqual(this.mp3tag.tags.v2.UNSU, [
[1, 2, 3, 4, 5]
])
})

it('Skip unsupported frames', function () {
this.mp3tag.read({ id3v1: false })
if (this.mp3tag.error) throw new Error(this.mp3tag.error)

assert.deepStrictEqual(this.mp3tag.tags.v2.UNSU, undefined)
})
})
})

0 comments on commit f1b0030

Please sign in to comment.