简体   繁体   English

server.close()在Vow拆解中不起作用

[英]server.close() doesn't work in a Vow teardown

I'm trying to write some Vows-based tests for my run-of-the-mill Express app. 我正在尝试为我的常规Express应用程序编写一些基于Vows的测试。

Here's the test source: 这是测试源:

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

And here's start-app.js : 这是start-app.js

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

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

module.exports = start;

app.js exports a regular Express.js app, created with express() . app.js导出使用express()创建的常规Express.js应用程序。

The problem is that whenever I run the test, topic.close() doesn't work in the teardown function, and the test hangs forever after succeeding. 问题是,每当我运行测试时, topic.close()在拆卸功能中均不起作用,并且测试成功后将永远挂起。 I've tried searching the web and adding lots and lots of console.log s, all to no avail. 我尝试在网上搜索并添加很多console.log ,但都无济于事。

I'm on the Windows x64 build of Node.js 4.2.0, and I'm using assert@1.3.0 and vows@0.8.1 . 我在Node.js 4.2.0的Windows x64构建上,并且正在使用assert@1.3.0vows@0.8.1

Any idea how I can make my test stop hanging? 知道如何使测试停止挂起吗?

Here's what I did to solve the issue in a project I was contributing: a final batch just to close the server. 在解决我正在做的项目中的问题时,我做了以下工作:最后一批只是为了关闭服务器。

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

Before adding this test, suite would never end executing. 在添加此测试之前,套件将永远不会结束执行。 You can check the results at https://travis-ci.org/fmalk/node-static/builds/90381188 您可以在https://travis-ci.org/fmalk/node-static/builds/90381188中查看结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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