【发布时间】:2015-03-19 06:06:52
【问题描述】:
如何测试一个自定义模块,该模块只是使用 Mocha&Chai 运行 node-fluent-ffmpeg 命令?
// segment_splicer.js
var config = require('./../config');
var utilities = require('./../utilities');
var ffmpeg = require('fluent-ffmpeg');
module.exports = {
splice: function(raw_ad_time, crop) {
if (!raw_ad_time || !crop) throw new Error("!!!!!!!!!! Missing argument");
console.log("@@@@@ LAST SEGMENT IS BEING SPLITTED.");
var segment_time = utilities.ten_seconds(raw_ad_time);
var last_segment_path = config.akamai_user_base + 'segment' + (segment_time + 1) + "_" + config.default_bitrate + "_av-p.ts?sd=10&rebase=on";
var command = ffmpeg(last_segment_path)
.on('start', function(commandLine) {
console.log('@@@@@ COMMAND: ' + commandLine);
})
.seekInput('0.000')
.outputOptions(['-c copy', '-map_metadata 0:s'])
.duration(crop)
.on('error', function(err, stdout, stderr) {
throw new Error('@@@@@ VIDEO COULD NOT BE PROCESSED: ' + err.message);
console.log('@@@@@ VIDEO COULD NOT BE PROCESSED: ' + err.message);
})
.output('public/' + 'segment' + (segment_time + 1) + "_" + config.default_bitrate + "_av-p.ts").run();
}
}
这是我尝试过的:
// test/segment_splicer.js
var expect = require('chai').expect;
var segment_splicer = require('../lib/segment_splicer');
describe('Segment Splicer', function() {
it('should work', function(done) {
expect(segment_splicer.splice(1111111, 20)).to.throw(Error);
done();
});
});
我明白了:
1) 段拼接器应该可以工作: AssertionError: 期望 undefined 是一个函数
因为我从 segment_splicer.spice 方法收到undefined。
谢谢!
【问题讨论】:
标签: javascript node.js testing mocha.js chai