简体   繁体   中英

Output data from Vows test

I have a test file like below:

// 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);

Somewhere this crashes, and I want to output some data. I tried to do console.log and process.stdout.write(...) . Both don't work as I expected.

I run the test using npm test , having vows --spec --isolate in my package.json file.

So, how can I output data when using Vows tests?

您应该能够使用stderr将其输出到誓言进度所在的位置:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM