Expressotesting在导航到静态文件时返回“错误:响应未完成”

我正在尝试使用Node.js和Express与Expresso来设置一个简单的项目进行testing。 我正在使用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); 

然后我写了一个简单的testing来检查静态文件。 这是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); } ); } }; 

当我运行testing(使用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) 

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

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

您不会从app.js文件导出app

把这加到最后

 module.exports = app;