1

我正在尝试为我的普通 Express 应用程序编写一些基于 Vows 的测试。

这是测试源:

var vows = require('vows');
var assert = require('assert');
var startApp = require('./lib/start-app.js');

var suite = vows.describe('tournaments');

suite.addBatch({
    "When we setup the app": {
        topic: function() {
            return startApp();
        },
        teardown: function(topic) {
            if (topic && topic.close) {
                topic.close();
            }
        },
        "it works": function(topic) {
            assert.isObject(topic);
        }
    }
});

suite.run();

这是start-app.js

var app = require('../../app.js');

function start() {
    var server = app.listen(56971, 'localhost');
    return server;
}

module.exports = start;

app.js导出一个常规的 Express.js 应用程序,使用express().

问题是,每当我运行测试时,topic.close()在拆卸功能中不起作用,并且测试在成功后永远挂起。我试过在网上搜索并添加很多很多console.logs,但都无济于事。

我在 Node.js 4.2.0 的 Windows x64 版本上,我正在使用assert@1.3.0vows@0.8.1.

知道如何让我的测试停止挂起吗?

4

1 回答 1

1

这是我为解决我正在贡献的项目中的问题所做的工作:最后一批只是为了关闭服务器。

suite.addBatch({
  'terminate server': {
    topic: function() {
      server.close(this.callback); // this is a regular node require(`http`) server, reused in several batches
    },
    'should be listening': function() {
      /* This test is necessary to ensure the topic execution.
       * A topic without tests will be not executed */
      assert.isTrue(true);
    }
  }
}).export(module);

在添加这个测试之前,套件永远不会结束执行。您可以在https://travis-ci.org/fmalk/node-static/builds/90381188查看结果

于 2015-11-11T20:14:47.090 回答