[英]How to use a different reporter with Vows' run() method?
Vows有一個run()方法,它在節點下運行測試,而不使用vows
命令。
在https://github.com/cloudhead/vows/blob/master/lib/vows/suite.js,我們可以看到此方法采用了一個選項參數,該參數允許指定除默認值以外的報告者:
this.run = function (options, callback) {
var that = this, start;
options = options || {};
for (var k in options) { this.options[k] = options[k] }
this.matcher = this.options.matcher || this.matcher;
this.reporter = this.options.reporter || this.reporter;
應該在options對象中傳遞什么值以選擇不同的報告者,例如spec
報告者?
嘗試:
var spec = require("vows/lib/vows/reporters/spec");
// ...
vows.describe("My Tests").addBatch({ /* some batch */ }).run({reporter:spec});
這是對我有用的最簡單的方法。
實際上,記者的要求已經在vows / lib / vows / suite.js中完成了
if (options.reporter) {
try {
this.reporter = typeof options.reporter === 'string'
? require('./reporters/' + options.reporter)
: options.reporter;
} catch (e) {
console.log('Reporter was not found, defaulting to dot-matrix.');
}
}
然后,要使用它,你應該:
vows.describe('Your suite').addBatch({
// your batch in here
}).run({reporter:'spec'}, function(testResults){
log(testResults);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.