-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8109dc0
commit d13ccd2
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
'use strict' | ||
|
||
var http = require('http') | ||
, request = require('../index') | ||
, tape = require('tape') | ||
|
||
var s = http.createServer(function(req, res) { | ||
res.statusCode = 200 | ||
res.setHeader('X-PATH', req.url) | ||
res.end('ok') | ||
}) | ||
|
||
tape('setup', function(t) { | ||
s.listen(6767, function() { | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl', function(t) { | ||
request('resource', { | ||
baseUrl: 'http://localhost:6767' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl defaults', function(t) { | ||
var withDefaults = request.defaults({ | ||
baseUrl: 'http://localhost:6767' | ||
}) | ||
withDefaults('resource', function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl without path', function(t) { | ||
request('resource', { | ||
baseUrl: 'http://localhost:6767' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.equal(resp.headers['x-path'], '/resource') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl without path, with trailing slash', function(t) { | ||
request('resource', { | ||
baseUrl: 'http://localhost:6767/' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.equal(resp.headers['x-path'], '/resource') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl with path', function(t) { | ||
request('resource', { | ||
baseUrl: 'http://localhost:6767/path/to' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.equal(resp.headers['x-path'], '/path/to/resource') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl with path and trailing slash', function(t) { | ||
request('resource', { | ||
baseUrl: 'http://localhost:6767/path/to/' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.equal(resp.headers['x-path'], '/path/to/resource') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl with empty uri', function(t) { | ||
request('', { | ||
baseUrl: 'http://localhost:6767/path/to' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.equal(resp.headers['x-path'], '/path/to/') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('baseUrl with trailing slash and empty uri', function(t) { | ||
request('', { | ||
baseUrl: 'http://localhost:6767/path/to/' | ||
}, function(err, resp, body) { | ||
t.equal(err, null) | ||
t.equal(body, 'ok') | ||
t.equal(resp.headers['x-path'], '/path/to/') | ||
t.end() | ||
}) | ||
}) | ||
|
||
tape('cleanup', function(t) { | ||
s.close(function() { | ||
t.end() | ||
}) | ||
}) |