簡體   English   中英

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

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

我正在嘗試為我的常規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()創建的常規Express.js應用程序。

問題是,每當我運行測試時, topic.close()在拆卸功能中均不起作用,並且測試成功后將永遠掛起。 我嘗試在網上搜索並添加很多console.log ,但都無濟於事。

我在Node.js 4.2.0的Windows x64構建上,並且正在使用assert@1.3.0vows@0.8.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中查看結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM