簡體   English   中英

如何使用Vows的run()方法使用不同的記者?

[英]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);
})

你需要一個記者的實例。 其中只有一個是公開的(點記者)作為vows.options.reporter

除此之外,您可以剔除誓言記者文件夾中的任何記者 並手動包含它。

替代方案是導出誓言套件( .export(module) )並調用$ vows --spec$ vows --json

誓言,是還提供了一個記者這是類似的“規范”的記者。

我想你可以在誓言上公布一個讓記者公開的問題。

暫無
暫無

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

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