Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Define unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Nov 11, 2019
1 parent da60a9e commit cce3ffd
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 33 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ install:
script:
- yarn run lint
- yarn build


- yarn run test
4 changes: 0 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Example chunked streaming audio track from S3 buckets into music-metadata parser
//

import * as S3 from 'aws-sdk/clients/s3';
import { parseFromTokenizer, parseStream } from 'music-metadata/lib/core';
import * as Type from 'music-metadata/lib/type';
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
],
"scripts": {
"clean": "del-cli lib/**/*.js lib/**/*.js.map lib/**/*.d.ts coverage",
"test": "npm run lint",
"mocha": "mocha",
"test": "npm run lint && npm run mocha",
"compile-lib": "tsc -p lib/tsconfig.json",
"compile": "npm run compile-lib",
"build": "npm run clean && yarn run compile",
Expand Down Expand Up @@ -46,7 +47,9 @@
},
"devDependencies": {
"aws-sdk": "^2.528.0",
"chai": "^4.2.0",
"del-cli": "^3.0.0",
"mocha": "^6.2.2",
"tslint": "^5.20.1",
"typescript": "^3.6.4"
}
Expand Down
74 changes: 57 additions & 17 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
//
// Example streaming audio track from S3 buckets into music-metadata parser
//

const { MusicMetadataS3Client } = require('../lib');
const {MMS3Client} = require('../lib');
const S3 = require('aws-sdk/clients/s3');
const {assert} = require('chai');

describe('Parse audio files from AWS S3 cloud', function() {

this.timeout(20000);

describe('Transfer mode: chunked', () => {

it('explicitly set', async () => {

const s3 = new S3();
const mmS3client = new MMS3Client(s3); // Pass s3 client to music-metadata-s3-client

(async () => {
const metadata = await mmS3client.parseS3Object({
Bucket: 'music-metadata',
Key: 'Various Artists - 2008 - netBloc Vol 13 (color in a world of monochrome) {BSCOMP0013} [MP3-V0]/01 - Nils Hoffmann - Sweet Man Like Me.mp3'
}, {
disableChunked: false
}
);
const {format} = metadata;
assert.equal(format.container, 'MPEG', 'format.container');
assert.equal(format.sampleRate, 44100, 'format.sampleRate');
assert.deepEqual(format.tagTypes, ['ID3v2.4'], 'format.tagTypes');
});

const s3 = new S3();
const mmS3client = new MusicMetadataS3Client(s3); // Pass s3 client to music-metadata-s3-client
it('default options', async () => {

console.log('Parsing...');
try {
const data = await mmS3client.parseS3Object({
const s3 = new S3();
const mmS3client = new MMS3Client(s3); // Pass s3 client to music-metadata-s3-client

const metadata = await mmS3client.parseS3Object({
Bucket: 'music-metadata',
Key: 'Various Artists - 2008 - netBloc Vol 13 (color in a world of monochrome) {BSCOMP0013} [MP3-V0]/01 - Nils Hoffmann - Sweet Man Like Me.mp3'
}
);
const {format} = metadata;
assert.equal(format.container, 'MPEG', 'format.container');
assert.equal(format.sampleRate, 44100, 'format.sampleRate');
assert.deepEqual(format.tagTypes, ['ID3v2.4'], 'format.tagTypes');
});

});

it('Transfer mode: conventional', async () => {

const s3 = new S3();
const mmS3client = new MMS3Client(s3); // Pass s3 client to music-metadata-s3-client

const metadata = await mmS3client.parseS3Object({
Bucket: 'music-metadata',
Key: 'Various Artists - 2008 - netBloc Vol 13 (color in a world of monochrome) {BSCOMP0013} [MP3-V0]/01 - Nils Hoffmann - Sweet Man Like Me.mp3'
}, {
disableChunked: false // If set to true, fall back to conventional stream
disableChunked: true
}
);
console.log('metadata:', data);
} catch (e) {
console.error(`Oops: ${e.message}`);
}
})();
const {format} = metadata;
assert.equal(format.container, 'MPEG', 'format.container');
assert.equal(format.sampleRate, 44100, 'format.sampleRate');
assert.deepEqual(format.tagTypes, ['ID3v2.4'], 'format.tagTypes');
});

})
;
Loading

0 comments on commit cce3ffd

Please sign in to comment.