3

Vows 有一个 run() 方法,可以在 node 下运行测试,无需使用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;

应该在选项对象中传递什么值来选择不同的报告者,例如spec报告者?

4

3 回答 3

6

尝试:

var spec = require("vows/lib/vows/reporters/spec");
// ...
vows.describe("My Tests").addBatch({ /* some batch */ }).run({reporter:spec});

这是对我有用的最简单的方法。

于 2011-09-01T20:50:02.683 回答
2

You need an instance of a reporter. Only one of them is public (the dot reporter) as vows.options.reporter

Other then that you can rip out any of the reporters in the vows reporter folder. and include it manually.

The alternatives would be to export the vows suite (.export(module)) and call $ vows --spec or $ vows --json.

vows-is also offers a reporter that's similar to the "spec" reporter.

I guess you could open an issue on vows for making the reporters public.

于 2011-08-31T20:32:37.873 回答
2

实际上,对记者的要求已经在 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);
})
于 2015-06-19T21:04:56.803 回答