Skip to content

Commit

Permalink
Add test related with propagating http.ClientRequest events
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrtribeiro committed Apr 9, 2019
1 parent 2031dc6 commit a245e29
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var test = require('tap').test;
var EventEmitter = require('events').EventEmitter;
var http = require('http');
var propagate = require('..');

test('propagates events', function(t) {
Expand Down Expand Up @@ -138,3 +139,33 @@ test('is able to propagate and map certain events', function(t) {

ee1.emit('event-1');
});

test('is able to propagate response from http.ClientRequest', function (t) {
t.plan(1);

var request = http.request({
hostname: 'google.com',
path: '/',
method: 'GET'
});

var ee1 = new EventEmitter();

propagate(request, ee1);

var retrievedData = "";
ee1.on('response', (response) => {

response.on('data', (data) => {
retrievedData = data.toString('utf8');
});

response.on('close', () => {
t.notEqual(retrievedData, "");
});

});

request.end();

});

0 comments on commit a245e29

Please sign in to comment.