Skip to content

Commit

Permalink
Added tests for missing parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bouiboui committed Feb 15, 2017
1 parent b1694a8 commit d24e665
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

const ffmpeg = require('fluent-ffmpeg');
const mime = require('mime');
const fs = require('fs');

module.exports = (filePathIn, filePathOut) => new Promise((resolve, reject) => {
if (!filePathIn || !filePathOut) {
throw new Error('You must specify a path for both input and output files.');
}
if (!fs.existsSync(filePathIn)) {
throw new Error('Input file must exist.');
}
if (mime.lookup(filePathIn).indexOf('audio') > -1) {
try {
ffmpeg()
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "1.0.0",
"description": "Converts an audio file to LINEAR16 Google-speech compatible file.",
"main": "index.js",
"scripts": {
"test": "mocha -c -R spec"
},
"repository": {
"type": "git",
"url": "git://[email protected]:bouiboui/linear16.git"
Expand All @@ -23,5 +26,8 @@
"dependencies": {
"fluent-ffmpeg": "^2.1.0",
"mime": "^1.3.4"
},
"devDependencies": {
"mocha": "^3.2.0"
}
}
40 changes: 40 additions & 0 deletions test/linear16test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const assert = require('assert');
const linear16 = require('../index');
const describe = require('mocha').describe;
const it = require('mocha').it;
const fs = require('fs');

describe('linear16', () => {
it('should fail if parameters are missing', () => {
linear16().then(() => {
throw new Error('should have rejected input');
}).catch(err => {
});
linear16('./test').then(() => {
throw new Error('should have rejected input');
}).catch(err => {
});
linear16(null, './test').then(() => {
throw new Error('should have rejected input');
}).catch(err => {
});
});
it('should fail for non-existing input file', () => {
linear16('./thisfiledoesnotexist', './out')
.then(() => {
throw new Error('Should have thrown an error');
})
.catch(() => {
});
});
it('should work normally', () =>
linear16(
'./test/test.m4a',
'./test/test.wav'
).then(outFile => {
assert.deepEqual(true, fs.existsSync(outFile));
fs.unlinkSync(outFile)
}))
});
Binary file added test/test.m4a
Binary file not shown.

0 comments on commit d24e665

Please sign in to comment.