在导航到静态文件时,Expresso测试返回'错误:响应未完成'

时间:2012-01-04 19:02:58

标签: node.js express

我正在尝试使用Node.js设置一个简单的项目,使用Express和Express来进行测试。我正在使用express.static中间件来提供位于我的公共目录中的静态html文件(index.html)。这是app.js的代码:

var express = require('express');
var app = express.createServer();

// Configuration
app.configure(function() {
    app.use(express.staticCache());
    app.use(express.static(__dirname + '/public'));
    app.use(express.bodyParser());
});

app.listen(3000);
然后我写了一个简单的测试来检查静态文件。这是app.test.js的代码:

var app = require('../app')
  , assert = require('assert');

module.exports = {

    'Navigate to root': function() {
        assert.response( 
            app,
            {
                url: '/'
            },
            {
                status: 200,
                headers: { 'Content-Type': 'text/html; charset=utf8'}
            },

            function(res) {
                assert.includes(res.body, 'index');
                assert.ok(res);
            }
        );
    }
};

当我运行测试时(使用expresso或expresso -s),我收到以下错误:

app.test.js Navigate to root: TypeError: Object #<Object> has no method 'listen'
    at Function.response (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:424:16)
    at Test.fn (/home/bill/projects/bidkat.app/test/app.test.js:13:11)
    at Test.runParallel (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:959:10)
    at Test.run (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:924:18)
    at next (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:867:22)
    at runSuite (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:875:6)
    at check (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:814:12)
    at runFile (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:819:6)
    at Array.forEach (native)
    at runFiles (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:796:15)

app.test.js Navigate to root: Error: Response not completed: Navigate to root. 
    at Function.response (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:400:17)
    at Test.fn (/home/bill/projects/bidkat.app/test/app.test.js:13:11)
    at Test.runParallel (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:959:10)
    at Test.run (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:924:18)
    at next (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:867:22)
    at runSuite (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:875:6)
    at check (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:814:12)
    at runFile (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:819:6)
    at Array.forEach (native)
    at runFiles (/home/bill/local/node/lib/node_modules/expresso/bin/expresso:796:15)

我显然做了些傻事,但我似乎无法弄清楚它是什么。我认为这可能是因为我的服务器在测试之前已经启动,但看起来像Expresso处理这种情况。我还使用json测试了一个REST端点,看看它是否是导致问题的静态文件,但它给了我同样的错误。

我正在使用Node.js v0.6.6,Express v2.5.4和Expresso v0.9.2。谢谢!

1 个答案:

答案 0 :(得分:2)

您未从app文件中导出app.js

将其添加到最后

module.exports = app;