Skip to content

Commit

Permalink
CI: Update Node.js version used in build to v22
Browse files Browse the repository at this point in the history
Updates syntax in unit tests to comply with updates TypeScript
  • Loading branch information
Borewit committed Jun 30, 2024
1 parent 76a1af2 commit af005a5
Show file tree
Hide file tree
Showing 8 changed files with 1,513 additions and 1,550 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 22.x

- name: Install production dependencies, check node engine compatibility
run: yarn install --production=true
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x, 22.x]

steps:

Expand Down
2 changes: 1 addition & 1 deletion lib/matroska/MatroskaParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class MatroskaParser extends BasicParser {

private async readString(e: IHeader): Promise<string> {
const rawString = await this.tokenizer.readToken(new StringType(e.len, 'utf-8'));
return rawString.replace(/\00.*$/g, '');
return rawString.replace(/\x00.*$/g, '');
}

private async readBuffer(e: IHeader): Promise<Buffer> {
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,36 @@
"token-types": "^5.0.1"
},
"devDependencies": {
"@types/chai": "^4.3.9",
"@types/chai": "^4.3.16",
"@types/chai-as-promised": "^7.1.8",
"@types/debug": "^4.1.12",
"@types/file-type": "^10.9.1",
"@types/mocha": "^10.0.3",
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"c8": "^9.1.0",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"del-cli": "5.1.0",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.9",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"c8": "^10.1.2",
"chai": "^5.1.1",
"chai-as-promised": "^8.0.0",
"del-cli": "^5.1.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^48.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-unicorn": "^49.0.0",
"eslint-plugin-unicorn": "^54.0.0",
"mime": "^4.0.3",
"mocha": "^10.2.0",
"mocha": "^10.5.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"remark-cli": "^12.0.0",
"remark-preset-lint-markdown-style-guide": "^5.1.3",
"ts-node": "^10.9.1",
"typescript": "^5.4.5"
"prettier": "^3.3.2",
"remark-cli": "^12.0.1",
"remark-preset-lint-markdown-style-guide": "^6.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.2"
},
"engines": {
"node": "^14.13.1 || >=16.0.0"
"node": ">=16.0.0"
},
"repository": {
"type": "git",
Expand Down
70 changes: 34 additions & 36 deletions test/test-file-mp4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import * as mm from '../lib/index.js';
import { Parsers } from './metadata-parsers.js';
import { samplePath } from './util.js';

const t = assert;

const mp4Samples = path.join(samplePath, 'mp4');

describe('Parse MPEG-4 files with iTunes metadata', () => {
Expand All @@ -28,45 +26,45 @@ describe('Parse MPEG-4 files with iTunes metadata', () => {
}

function checkCommon(common) {
t.strictEqual(common.title, 'Voodoo People (Pendulum Remix)', 'title');
t.strictEqual(common.artist, 'The Prodigy', 'artist');
t.strictEqual(common.albumartist, 'Pendulum', 'albumartist');
t.strictEqual(common.album, 'Voodoo People', 'album');
t.strictEqual(common.year, 2005, 'year');
t.strictEqual(common.track.no, 1, 'track no');
t.strictEqual(common.track.of, 12, 'track of');
t.strictEqual(common.disk.no, 1, 'disk no');
t.strictEqual(common.disk.of, 1, 'disk of');
t.strictEqual(common.genre[0], 'Electronic', 'genre');
t.strictEqual(common.picture[0].format, 'image/jpeg', 'picture 0 format');
t.strictEqual(common.picture[0].data.length, 196450, 'picture 0 length');
t.strictEqual(common.picture[1].format, 'image/jpeg', 'picture 1 format');
t.strictEqual(common.picture[1].data.length, 196450, 'picture 1 length');
assert.strictEqual(common.title, 'Voodoo People (Pendulum Remix)', 'title');
assert.strictEqual(common.artist, 'The Prodigy', 'artist');
assert.strictEqual(common.albumartist, 'Pendulum', 'albumartist');
assert.strictEqual(common.album, 'Voodoo People', 'album');
assert.strictEqual(common.year, 2005, 'year');
assert.strictEqual(common.track.no, 1, 'track no');
assert.strictEqual(common.track.of, 12, 'track of');
assert.strictEqual(common.disk.no, 1, 'disk no');
assert.strictEqual(common.disk.of, 1, 'disk of');
assert.strictEqual(common.genre[0], 'Electronic', 'genre');
assert.strictEqual(common.picture[0].format, 'image/jpeg', 'picture 0 format');
assert.strictEqual(common.picture[0].data.length, 196450, 'picture 0 length');
assert.strictEqual(common.picture[1].format, 'image/jpeg', 'picture 1 format');
assert.strictEqual(common.picture[1].data.length, 196450, 'picture 1 length');
}

function checkNativeTags(native) {

t.ok(native, 'Native m4a tags should be present');

t.deepEqual(native.trkn, ['1/12'], 'm4a.trkn');
t.deepEqual(native.disk, ['1/1'], 'm4a.disk');
t.deepEqual(native.tmpo, [0], 'm4a.tmpo');
t.deepEqual(native.gnre, ['Electronic'], 'm4a.gnre');
t.deepEqual(native.stik, [1], 'm4a.stik');
t.deepEqual(native['©alb'], ['Voodoo People'], 'm4a.©alb');
t.deepEqual(native.aART, ['Pendulum'], 'm4a.aART');
t.deepEqual(native['©ART'], ['The Prodigy'], 'm4a.©ART');
t.deepEqual(native['©cmt'], ['(Pendulum Remix)'], 'm4a.©cmt');
t.deepEqual(native['©wrt'], ['Liam Howlett'], 'm4a.©wrt');
t.deepEqual(native['----:com.apple.iTunes:iTunNORM'], [' 0000120A 00001299 00007365 0000712F 0002D88B 0002D88B 00007F2B 00007F2C 0003C770 0001F5C7'], 'm4a.----:com.apple.iTunes:iTunNORM');
t.deepEqual(native['©nam'], ['Voodoo People (Pendulum Remix)'], 'm4a.©nam');
t.deepEqual(native['©too'], ['Lavf52.36.0'], 'm4a.©too');
t.deepEqual(native['©day'], ['2005'], 'm4a.@day');
assert.ok(native, 'Native m4a tags should be present');

assert.deepEqual(native.trkn, ['1/12'], 'm4a.trkn');
assert.deepEqual(native.disk, ['1/1'], 'm4a.disk');
assert.deepEqual(native.tmpo, [0], 'm4a.tmpo');
assert.deepEqual(native.gnre, ['Electronic'], 'm4a.gnre');
assert.deepEqual(native.stik, [1], 'm4a.stik');
assert.deepEqual(native['©alb'], ['Voodoo People'], 'm4a.©alb');
assert.deepEqual(native.aART, ['Pendulum'], 'm4a.aART');
assert.deepEqual(native['©ART'], ['The Prodigy'], 'm4a.©ART');
assert.deepEqual(native['©cmt'], ['(Pendulum Remix)'], 'm4a.©cmt');
assert.deepEqual(native['©wrt'], ['Liam Howlett'], 'm4a.©wrt');
assert.deepEqual(native['----:com.apple.iTunes:iTunNORM'], [' 0000120A 00001299 00007365 0000712F 0002D88B 0002D88B 00007F2B 00007F2C 0003C770 0001F5C7'], 'm4a.----:com.apple.iTunes:iTunNORM');
assert.deepEqual(native['©nam'], ['Voodoo People (Pendulum Remix)'], 'm4a.©nam');
assert.deepEqual(native['©too'], ['Lavf52.36.0'], 'm4a.©too');
assert.deepEqual(native['©day'], ['2005'], 'm4a.@day');

// Check album art
t.isDefined(native.covr);
t.strictEqual(native.covr[0].format, 'image/jpeg', 'm4a.covr.format');
t.strictEqual(native.covr[0].data.length, 196450, 'm4a.covr.data.length');
assert.isDefined(native.covr);
assert.strictEqual(native.covr[0].format, 'image/jpeg', 'm4a.covr.format');
assert.strictEqual(native.covr[0].data.length, 196450, 'm4a.covr.data.length');
}

Parsers.forEach(parser => {
Expand All @@ -76,7 +74,7 @@ describe('Parse MPEG-4 files with iTunes metadata', () => {

const metadata = await parser.initParser(filePath, 'audio/mp4');
const native = metadata.native.iTunes;
t.ok(native, 'Native m4a tags should be present');
assert.ok(native, 'Native m4a tags should be present');

checkFormat(metadata.format);
checkCommon(metadata.common);
Expand Down
60 changes: 29 additions & 31 deletions test/test-id3v2.4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import path from 'node:path';
import * as mm from '../lib/index.js';
import { samplePath } from './util.js';

const t = assert;

describe("Decode MP3/ID3v2.4", () => {

it("should decode id3v2.4", () => {
Expand All @@ -14,29 +12,29 @@ describe("Decode MP3/ID3v2.4", () => {
const filePath = path.join(samplePath, filename);

return mm.parseFile(filePath, {duration: true}).then(metadata => {
t.deepEqual(metadata.format.tagTypes, ["ID3v2.4", "ID3v1"], 'format.tagTypes');
t.strictEqual(metadata.format.duration, 0.7836734693877551, 'format.format.duration');
t.strictEqual(metadata.format.sampleRate, 44100, 'format.sampleRate = 44.1 kHz');
t.strictEqual(metadata.format.bitrate, 128000, 'format.bitrate = 128 kbit/sec');
t.strictEqual(metadata.format.codecProfile, 'CBR', 'format.codecProfile = CBR');
t.strictEqual(metadata.format.container, 'MPEG', 'format.container');
t.strictEqual(metadata.format.codec, 'MPEG 1 Layer 3', 'format.codec');
t.strictEqual(metadata.format.tool, 'LAME 3.98r', 'format.tool');
t.strictEqual(metadata.format.numberOfChannels, 2, 'format.numberOfChannels = 2');

t.strictEqual(metadata.common.title, 'Home', 'title');
t.strictEqual(metadata.common.artist, 'Explo', 'common.artist');
t.deepEqual(metadata.common.artists, ['Explo', 'ions', 'nodejsftws'], 'common.artists');
t.strictEqual(metadata.common.albumartist, 'Soundtrack', 'albumartist');
t.strictEqual(metadata.common.album, 'Friday Night Lights [Original Movie Soundtrack]', 'album');
t.strictEqual(metadata.common.year, 2004, 'year');
t.deepEqual(metadata.common.track, {no: 5, of: null}, 'common.track');
t.deepEqual(metadata.common.disk, {no: 1, of: 1}, 'common.disk');
t.deepEqual(metadata.common.genre, ['Soundtrack', 'OST'], 'common.genres');
t.strictEqual(metadata.common.picture[0].format, 'image/jpeg', 'common.picture 0 format');
t.strictEqual(metadata.common.picture[0].data.length, 80938, 'common.picture 0 length');
t.strictEqual(metadata.common.picture[1].format, 'image/jpeg', 'common.picture 1 format');
t.strictEqual(metadata.common.picture[1].data.length, 80938, 'common.picture 1 length');
assert.deepEqual(metadata.format.tagTypes, ["ID3v2.4", "ID3v1"], 'format.tagTypes');
assert.strictEqual(metadata.format.duration, 0.7836734693877551, 'format.format.duration');
assert.strictEqual(metadata.format.sampleRate, 44100, 'format.sampleRate = 44.1 kHz');
assert.strictEqual(metadata.format.bitrate, 128000, 'format.bitrate = 128 kbit/sec');
assert.strictEqual(metadata.format.codecProfile, 'CBR', 'format.codecProfile = CBR');
assert.strictEqual(metadata.format.container, 'MPEG', 'format.container');
assert.strictEqual(metadata.format.codec, 'MPEG 1 Layer 3', 'format.codec');
assert.strictEqual(metadata.format.tool, 'LAME 3.98r', 'format.tool');
assert.strictEqual(metadata.format.numberOfChannels, 2, 'format.numberOfChannels = 2');

assert.strictEqual(metadata.common.title, 'Home', 'title');
assert.strictEqual(metadata.common.artist, 'Explo', 'common.artist');
assert.deepEqual(metadata.common.artists, ['Explo', 'ions', 'nodejsftws'], 'common.artists');
assert.strictEqual(metadata.common.albumartist, 'Soundtrack', 'albumartist');
assert.strictEqual(metadata.common.album, 'Friday Night Lights [Original Movie Soundtrack]', 'album');
assert.strictEqual(metadata.common.year, 2004, 'year');
assert.deepEqual(metadata.common.track, {no: 5, of: null}, 'common.track');
assert.deepEqual(metadata.common.disk, {no: 1, of: 1}, 'common.disk');
assert.deepEqual(metadata.common.genre, ['Soundtrack', 'OST'], 'common.genres');
assert.strictEqual(metadata.common.picture[0].format, 'image/jpeg', 'common.picture 0 format');
assert.strictEqual(metadata.common.picture[0].data.length, 80938, 'common.picture 0 length');
assert.strictEqual(metadata.common.picture[1].format, 'image/jpeg', 'common.picture 1 format');
assert.strictEqual(metadata.common.picture[1].data.length, 80938, 'common.picture 1 length');
});

});
Expand All @@ -46,7 +44,7 @@ describe("Decode MP3/ID3v2.4", () => {

const filePath = path.join(samplePath, 'mp3', 'issue-502.mp3');
const {common} = await mm.parseFile(filePath);
t.deepEqual(common.comment, ['CLEAN'], 'common.comment');
assert.deepEqual(common.comment, ['CLEAN'], 'common.comment');
});

it("should respect skipCovers-flag", () => {
Expand All @@ -55,7 +53,7 @@ describe("Decode MP3/ID3v2.4", () => {
const filePath = path.join(samplePath, filename);

return mm.parseFile(filePath, {duration: true, skipCovers: true}).then(result => {
t.isUndefined(result.common.picture, 'common.picture should be undefined');
assert.isUndefined(result.common.picture, 'common.picture should be undefined');
});

});
Expand All @@ -67,10 +65,10 @@ describe("Decode MP3/ID3v2.4", () => {

const {common, native} = await mm.parseFile(filePath);
const id3v24 = native['ID3v2.4'];
t.isDefined(id3v24, 'ID3v2.4 presence');
t.strictEqual(id3v24.filter(tag => { return tag.id === 'TSRC'; }).length, 0, 'ID3v2.4 tag TSRC not defined');
t.strictEqual(id3v24.filter(tag => { return tag.id === 'TXXX:ISRC'; }).length, 1, 'ID3v2.4 tag TXXX:ISRC to be defined');
t.includeDeepMembers(common.isrc, ['DEAE61300058'], 'ISRC');
assert.isDefined(id3v24, 'ID3v2.4 presence');
assert.strictEqual(id3v24.filter(tag => { return tag.id === 'TSRC'; }).length, 0, 'ID3v2.4 tag TSRC not defined');
assert.strictEqual(id3v24.filter(tag => { return tag.id === 'TXXX:ISRC'; }).length, 1, 'ID3v2.4 tag TXXX:ISRC to be defined');
assert.includeDeepMembers(common.isrc, ['DEAE61300058'], 'ISRC');
});

// https://id3.org/id3v2.4.0-frame
Expand Down
10 changes: 4 additions & 6 deletions test/test-mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import fs from 'node:fs';
import * as mm from '../lib/index.js';
import { SourceStream, samplePath } from './util.js';

const t = assert;

describe('MIME & extension mapping', () => {

const buf = Buffer.alloc(30).fill(0);
Expand All @@ -21,7 +19,7 @@ describe('MIME & extension mapping', () => {
case '.flac':
case '.wav':
case '.ogg':
t.ok(err.message.startsWith('FourCC'), `Only FourCC error allowed, got: ${err.message}`);
assert.ok(err.message.startsWith('FourCC'), `Only FourCC error allowed, got: ${err.message}`);
break;

default:
Expand All @@ -32,9 +30,9 @@ describe('MIME & extension mapping', () => {
it('should reject an unknown file', () => {

return mm.parseFile(path.join(samplePath, 'flac.flac.jpg'))
.then(() => t.fail('Should reject extension'))
.then(() => assert.fail('Should reject extension'))
.catch(err => {
t.strictEqual(err.message, 'Guessed MIME-type not supported: image/jpeg');
assert.strictEqual(err.message, 'Guessed MIME-type not supported: image/jpeg');
});

});
Expand All @@ -45,7 +43,7 @@ describe('MIME & extension mapping', () => {
const streamReader = new SourceStream(buf);
// Convert extension to MIME-Type
const mimeType = mime.getType(extension);
t.isNotNull(mimeType, 'extension: ' + extension);
assert.isNotNull(mimeType, 'extension: ' + extension);

return mm.parseStream(streamReader, mimeType)
.catch(err => {
Expand Down
Loading

0 comments on commit af005a5

Please sign in to comment.