从Vows测试输出数据

时间:2014-10-15 16:45:31

标签: node.js testing vows

我有一个如下测试文件:

// Dependencies
var Vows = require("vows")
  , Request = require("request")
  , Assert = require("assert")
  , MyLib = require("../../lib/")
  ;

// Globals
var sServer = new MyLib({
      root: __dirname + "/../fixtures"
    })
  , suite = Vows.describe("...")
  , TEST_PORT = 8080
  , TEST_SERVER = "http://localhost:" + TEST_PORT
  , server
  , callback
  ;

suite.addBatch({
    "once an http server is listening with a callback": {
        topic: function() {
            server = require("http").createServer(function (req, res) {
                // output some data
                sServer.serve(req, res);
            }).listen(TEST_PORT, this.callback)
        },
        "should be listening": function() {
            Assert.isTrue(true);
        }
    }
}).addBatch({
    "streaming a 404 page": {
        topic: function() {
            request.get(TEST_SERVER + "/not-found", this.callback);
        },
        "should respond with 404": function(error, response, body) {
            Assert.equal(response.statusCode, 404);
        },
        "should respond with the streamed content": function(error, response, body) {
            Assert.equal(body, "Custom 404 Stream.");
        }
    }
}).export(module);

某处崩溃了,我想输出一些数据。我尝试console.logprocess.stdout.write(...)。两者都不像我预期的那样工作。

我使用npm test运行测试,vows --spec --isolate文件中包含package.json

那么,在使用Vows测试时如何输出数据?

1 个答案:

答案 0 :(得分:3)

您应该能够使用stderr输出与誓言进度相同的位置:

process.stderr.write("something\n");