在远程URL上重复使用Supertesttesting

我正在使用MochaJS和SuperTest在开发过程中testing我的API,绝对喜欢它。

不过,我也想把这些相同的testing变成远程testing我的登台服务器,然后把代码推到生产。

有没有办法通过远程URL或代理向远程URL提供请求?

这是我使用的一个testing样本

request(app) .get('/api/photo/' + photo._id) .set(apiKeyName, apiKey) .end(function(err, res) { if (err) throw err; if (res.body._id !== photo._id) throw Error('No _id found'); done(); }); 

我不确定你是否可以用超级特技做到这一点。 你绝对可以用superagent做。 Supertestbuild立在superagent上。 一个例子是:

 var request = require('superagent'); var should = require('should'); var agent = request.agent(); var host = 'http://www.yourdomain.com' describe('GET /', function() { it('should render the index page', function(done) { agent .get(host + '/') .end(function(err, res) { should.not.exist(err); res.should.have.status(200); done(); }) }) }) 

所以你不能直接使用你现有的testing。 但是他们很相似。 如果你添加

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

到testing的顶部,您可以通过更改hostvariables轻松切换testing本地应用程序和远程服务器上的部署

 var host = 'http://localhost:3000'; 

编辑:

刚刚在文档#例子中find了一个超类的例子

 request = request.bind(request, 'http://localhost:5555'); // add your url here request.get('/').expect(200, function(err){ console.log(err); }); request.get('/').expect('heya', function(err){ console.log(err); });