簡體   English   中英

如何測試運行node-fluent-ffmpeg的自定義模塊(異步模塊)?

[英]How to test a custom module running node-fluent-ffmpeg (an async module)?

如何測試僅通過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:預期未定義是一個函數

因為我收到來自segment_splicer.spice方法的undefined

謝謝!

該測試應該通過。

僅當您斷言或期望測試中的某些內容不正確,或者被測對象拋出未捕獲的錯誤時,測試才會失敗。

您沒有在測試中聲明任何內容,並且您的主題將拋出的唯一錯誤是,如果您傳遞的參數少於2個,那么測試中就不會出現這種情況。

ffmpeg方法似乎也是異步的,這與您構建測試的方式不兼容。

關於設置異步測試,有很多示例,包括:

通過引用done參數,您已經做了一些事情來做到這done 如果指定了此選項,則Mocha將等到被調用之前再考慮測試已完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM