【问题标题】:Output data from Vows testVows 测试的输出数据
【发布时间】:2014-10-15 16:45:31
【问题描述】:

我有一个如下的测试文件:

// 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 运行测试,在我的package.json 文件中有vows --spec --isolate

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

【问题讨论】:

    标签: node.js testing vows


    【解决方案1】:

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

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

    【讨论】:

    • 工作正常。但是是什么导致了这种奇怪的行为?您可以将此信息添加到您的答案中吗?
    • @IonicăBizău,我不确定我会称之为奇怪。这类东西输出到 stderr 而不是 stdout 是很典型的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2011-10-18
    相关资源
    最近更新 更多