Skip to content

Commit

Permalink
Replace request with nipple in tests. Closes hapijs#1245
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Jan 19, 2014
1 parent 5850a0f commit ef7dbb3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 41 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"handlebars": "1.2.x",
"jade": "1.0.x",
"hapi-plugin-test": "2.x.x",
"dtrace-provider": "0.2.x"
"dtrace-provider": "0.2.x",
"form-data": "0.1.x"
},
"bin": {
"hapi": "./bin/hapi"
Expand Down
37 changes: 16 additions & 21 deletions test/integration/payload.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Load modules

var Lab = require('lab');
var Nipple = require('nipple');
var Fs = require('fs');
var Http = require('http');
var Path = require('path');
var Stream = require('stream');
var Zlib = require('zlib');
var FormData = require('form-data');
var Lab = require('lab');
var Nipple = require('nipple');
var Hapi = require('../..');


Expand Down Expand Up @@ -482,22 +483,18 @@ describe('Payload', function () {
it('sets the request payload with the streaming data', function (done) {

var options = {
uri: 'http://localhost:' + server.info.port + '/?x=1',
method: 'POST',
payload: new TestStream(),
headers: {
'Content-Type': 'application/json'
}
};

var req = Request(options, function (err, res, body) {
Nipple.post('http://localhost:' + server.info.port + '/?x=1', options, function (err, res, body) {

expect(res.statusCode).to.equal(200);
expect(body).to.equal('value');
done();
});

var s = new TestStream();
s.pipe(req);
});

it('times out when the request content-length is larger than payload', function (done) {
Expand Down Expand Up @@ -525,18 +522,16 @@ describe('Payload', function () {
it('resets connection when the request content-length is smaller than payload', function (done) {

var options = {
uri: 'http://localhost:' + server.info.port + '/?x=3',
body: '{ "key": "value" }',
method: 'POST',
payload: '{ "key": "value" }',
headers: {
'Content-Type': 'application/json',
'Content-Length': '1'
}
};

Request(options, function (err, res, body) {
Nipple.post('http://localhost:' + server.info.port + '/?x=3', options, function (err, res, body) {

expect(err.message).to.equal('socket hang up');
expect(err.message).to.equal('Client request error');
done();
});
});
Expand Down Expand Up @@ -970,9 +965,9 @@ describe('Payload', function () {
server.route({ method: 'POST', path: '/file', config: { handler: handler, payload: { output: 'file' } } });
server.start(function () {

var r = Request.post(server.info.uri + '/file');
var form = r.form();
var form = new FormData();
form.append('my_file', Fs.createReadStream(path));
Nipple.post(server.info.uri + '/file', { payload: form, headers: form.getHeaders() }, function (err, res, payload) { });
});
});

Expand All @@ -991,9 +986,9 @@ describe('Payload', function () {
server.route({ method: 'POST', path: '/file', config: { handler: handler, payload: { output: 'data' } } });
server.start(function () {

var r = Request.post(server.info.uri + '/file');
var form = r.form();
var form = new FormData();
form.append('my_file', Fs.createReadStream(path));
Nipple.post(server.info.uri + '/file', { payload: form, headers: form.getHeaders() }, function (err, res, payload) { });
});
});

Expand Down Expand Up @@ -1037,9 +1032,9 @@ describe('Payload', function () {
server.route({ method: 'POST', path: '/file', config: { handler: fileHandler, payload: { output: 'stream' } } });
server.start(function () {

var r = Request.post(server.info.uri + '/file');
var form = r.form();
var form = new FormData();
form.append('my_file', fileStream);
Nipple.post(server.info.uri + '/file', { payload: form, headers: form.getHeaders() }, function (err, res, payload) { });
});
});

Expand Down Expand Up @@ -1088,7 +1083,7 @@ describe('Payload', function () {
'Content-Disposition: form-data; name="a[c]"\r\n' +
'\r\n' +
'4\r\n' +
'--AaB03x--\r\n'
'--AaB03x--\r\n';

var handler = function (request, reply) {

Expand Down Expand Up @@ -1120,7 +1115,7 @@ describe('Payload', function () {
'Content-Type: plain/text\r\n' +
'\r\n' +
'and\r\n' +
'----WebKitFormBoundaryE19zNvXGzXaLvS5C\r\n'
'----WebKitFormBoundaryE19zNvXGzXaLvS5C\r\n';

var handler = function (request, reply) {

Expand Down
4 changes: 2 additions & 2 deletions test/integration/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var Lab = require('lab');
var Net = require('net');
var Stream = require('stream');
var Request = require('request');
var Nipple = require('nipple');
var Hapi = require('../..');

// Declare internals
Expand Down Expand Up @@ -323,7 +323,7 @@ describe('Request', function () {

server.start(function () {

Request('http://localhost:' + server.info.port + '/', function (err, res, body) {
Nipple.get('http://localhost:' + server.info.port, function (err, res, body) {

expect(body).to.equal('ok');
done();
Expand Down
20 changes: 3 additions & 17 deletions test/integration/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

var Fs = require('fs');
var Http = require('http');
var Lab = require('lab');
var Request = require('request');
var Stream = require('stream');
var Zlib = require('zlib');
var Lab = require('lab');
var Nipple = require('nipple');
var Hapi = require('../..');


Expand Down Expand Up @@ -1586,25 +1586,11 @@ describe('Response', function () {

streamServer.start(function () {

Request({ url: 'https://127.0.0.1:' + streamServer.info.port, rejectUnauthorized: false }, function (err, res, body) {
Nipple.get('https://127.0.0.1:' + streamServer.info.port, { rejectUnauthorized: false }, function (err, res, body) {

expect(body).to.equal(expectedBody);
done();
});

/*
Nipple.request('GET', 'https://localhost:' + streamServer.info.port, { rejectUnauthorized: false }, function (err, res) {
expect(err).to.not.exist;
Nipple.read(res, function (err, payload) {
expect(err).to.not.exist;
expect(payload).to.equal(expectedBody);
done();
});
});
*/
});
});
});
Expand Down

0 comments on commit ef7dbb3

Please sign in to comment.