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()、teardown 関数で動作せず、テストが成功した後に永久にハングすることです。私はウェブを検索して、たくさんのconsole.logs を追加しようとしましたが、すべて役に立ちませんでした。

Node.js 4.2.0 の Windows x64 ビルドを使用assert@1.3.0してvows@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 に答える