node-qunit的测试结果如何显示到浏览器中(4)

前面我把node-qunit的log.js修改了,把全局变量data公布出来了,但是每测试一次,发现测试报告一直累加,于是加上清空测试报告的代码:testrunner.log.reset();,如:

module.exports = function(req, res, sender) {  
    var testrunner = require("qunit");  
    testrunner.log.reset();  
    testrunner.run({  
        code : "./source/yjSecurity.js",  
        tests : "./test/Test_yjSecurity.js"  
    }, function(err, report) {  
        //console.dir(testrunner.log.data);  
        if (err)  
            sender.error(err);  
        else {  
            sender.success(testrunner.log.data);  
        }  
    });  
};  

但是,奇怪了,得不到测试报告了,结果为空。

最后把log.js中data公布形式改为:

exports.data=function() //add by wxh,2014/3/29
{
	return data;
}

model使用方法改为:

module.exports = function(req, res, sender) {  
    var testrunner = require("qunit");  
      
    testrunner.run({  
        code : "./source/yjSecurity.js",  
        tests : "./test/Test_yjSecurity.js"  
    }, function(err, report) {  
        //console.dir(testrunner.log.data());  
        if (err)  
            sender.error(err);  
        else {  
            sender.success(testrunner.log.data());  
        }  
    });  
};  

这才正常了。分析了很久没找到具体原因,有知道了请告之。

原创文章 159 获赞 11 访问量 36万+

猜你喜欢

转载自blog.csdn.net/acrodelphi/article/details/22847867