pipe
remoteAddress
set. Why would that be? From the little snooping of the code that I did, I saw that the audit plugin uses req.connection.remoteAddress
- should I manually patch it and use the request-ip
module instead?
@avimar i’m using supertest and tape for functional testing. I’m new to both. I’m running into an issue where the test script will not complete. The actual test runs, but the test script does not conclude. Could restify be holding a connection open?
The Test:
var supertest = require('supertest');
var test = require('tape');
var app = require('../app');
var request = supertest.agent('http://localhost:8080');
test('that fantasy player predictions are returned', function(t){
'use strict';
request
.get(‘/users')
.expect(200)
.expect('Content-type',/json/)
.expect('Content-Encoding', 'gzip')
.end(function(err, res){
t.equal(2 + 3, 5);
t.error(err, 'No error');
t.end(err);
});
});
You can see the tests are evaluating, but then the test stoip and i have to control+c out of the script. Any thoughts?
The output:
ubuntu@ip-123-34-56-567:~/apps/sapiv0$ npm test
> sapi@1.0.0 test /home/ubuntu/apps/sapiv0
> node test | tap-spec
SAPI listening at http://0.0.0.0:8080
that fantasy player predictions are returned
✔ should be equal
✔ No error
I'd like to take a URL pathname and match it to an existing restify route handler and get the params from it. basically URL path matching.
Inputs:
/some/random/value
server.get('/some/random/:path', function() { / / });
Output:
{path: 'value'}
Maybe via some method I don't know that works like:
server.router.match('/some/random/value')
.close()
method available on the server object, docs here, under Other Methods
@forstermatth exactly. I ended up using supertests.agent() method, which doesn't pull the whole server instance into your test. You must end the server after your tests then though.
@CoreySwish I reckon this is feasible. I will end up doing something like this for more complex queries:
var test = require('tape')
var supertest = require('supertest');
var server = supertest.agent("http://localhost:8080");
test('Proximity API test', function(t) {
t.plan(1)
function proximityTest(latAndLong,cb) {
server
.post('/users/positions')
.send({
lat_and_long: latAndLong
})
.expect(200)
.end(function(err,res){
if (err) {
return t.fail('Route does not reply correctly')
}
return cb()
})
}
proximityTest([52.487395, 13.394405], function() {
proximityTest([52.488258, 13.394448], function() {
proximityTest([52.489029, 13.394501], function() {
t.pass('Request came through as expected')
})
})
})
})
Unfortunately you can't chain supertest
, but it looks okay an node-y to me.