Throw error when corePath is not a string

This commit is contained in:
Jerome Wu 2020-11-20 12:55:22 +08:00
parent 24e7430daf
commit c51cb50b7a
2 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,9 @@ const resolveURL = require('resolve-url');
const { log } = require('../utils/log'); const { log } = require('../utils/log');
module.exports = async ({ corePath: _corePath }) => { module.exports = async ({ corePath: _corePath }) => {
if (typeof _corePath !== 'string') {
throw Error('corePath should be a string!');
}
if (typeof window.createFFmpegCore === 'undefined') { if (typeof window.createFFmpegCore === 'undefined') {
log('info', 'fetch ffmpeg-core.worker.js script'); log('info', 'fetch ffmpeg-core.worker.js script');
const corePath = resolveURL(_corePath); const corePath = resolveURL(_corePath);

View File

@ -1,6 +1,15 @@
const { createFFmpeg } = FFmpeg; const { createFFmpeg } = FFmpeg;
describe('load()', () => { describe('load()', () => {
it('should throw error when corePath is not a string', async () => {
const ffmpeg = createFFmpeg({ ...OPTIONS, corePath: null });
try {
await ffmpeg.load();
} catch (e) {
expect(e).to.be.an('Error');
}
});
it('should throw error when not called before FS() and run()', () => { it('should throw error when not called before FS() and run()', () => {
const ffmpeg = createFFmpeg(OPTIONS); const ffmpeg = createFFmpeg(OPTIONS);
expect(() => ffmpeg.FS('readdir', 'dummy')).to.throw(); expect(() => ffmpeg.FS('readdir', 'dummy')).to.throw();