Javascript 如何测试运行node fluent ffmpeg(异步模块)的自定义模块?

Javascript 如何测试运行node fluent ffmpeg(异步模块)的自定义模块?,javascript,node.js,testing,mocha.js,chai,Javascript,Node.js,Testing,Mocha.js,Chai,如何使用Mocha&Chai测试仅运行节点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) {

如何使用Mocha&Chai测试仅运行
节点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:预期未定义为函数

因为我从segment_Spicer.spice方法接收到
未定义的

谢谢大家!

这个测试应该通过了

只有当您在测试中断言或期望某些不正确的内容,或者被测试对象抛出未捕获的错误时,测试才会失败

您在测试中没有断言任何内容,并且您的主题将抛出的唯一错误是如果您传递的参数少于2个,而在您的测试中情况并非如此

ffmpeg
方法似乎也是异步的,这与您构建测试的方式不兼容

设置异步测试有许多示例,包括:


通过引用
done
参数,您已经在某种程度上做到了这一点。如果指定了此项,摩卡将等待,直到它被呼叫,然后再考虑测试是否完成。

谢谢您的回答。实际上,我的问题是“如何以测试异步内容的方式构造测试”?(是的,我忘记了预期的错误:)