-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
http.js
38 lines (29 loc) · 919 Bytes
/
http.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// I checked this in by accident. I'm ambivalent about whether we ought to
// include it. It's a reproduction of the bug from https://github.com/nock/propagate/pull/17
// though it doesn't elucidate the fix as well as directly testing the return
// values from .emit()
'use strict'
const { test } = require('tap')
const { EventEmitter } = require('events')
const propagate = require('..')
const http = require('http')
test('is able to propagate response from http.ClientRequest', function(t) {
t.plan(1)
const request = http.request({
hostname: 'google.com',
path: '/',
method: 'GET',
})
const ee1 = new EventEmitter()
propagate(request, ee1)
let retrievedData = ''
ee1.on('response', response => {
response.on('data', data => {
retrievedData = data.toString('utf8')
})
response.on('close', () => {
t.notEqual(retrievedData, '')
})
})
request.end()
})