Вопрос

Vows has a run() method that runs the test under node, without using the vows command.

At https://github.com/cloudhead/vows/blob/master/lib/vows/suite.js we can see that this method takes an option parameter which allows to specify a reporter other than the default:

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;

What value is supposed to be passed in the options object to select a different reporter, for instance the spec reporter?

Это было полезно?

Решение

Try:

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

This was the simplest way that worked for me.

Другие советы

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.

Actually, the require to reporter is already did at 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.');
      }
    }

Then, to use it, you should just:

vows.describe('Your suite').addBatch({
    // your batch in here
    }).run({reporter:'spec'}, function(testResults){
        log(testResults);
})
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top