(
request: typeof requestHTTP | typeof requestHTTPS,
expectEmptyBody: boolean = false
)
| 42 | let resClose: () => void |
| 43 | |
| 44 | const runner = ( |
| 45 | request: typeof requestHTTP | typeof requestHTTPS, |
| 46 | expectEmptyBody: boolean = false |
| 47 | ) => { |
| 48 | it('Should return 200 response - GET /', async () => { |
| 49 | let responseBody = '' |
| 50 | const req = request( |
| 51 | { |
| 52 | hostname: address.address, |
| 53 | port: address.port, |
| 54 | method: 'GET', |
| 55 | path: '/', |
| 56 | rejectUnauthorized: false, |
| 57 | }, |
| 58 | (res) => { |
| 59 | res.on('data', (chunk) => { |
| 60 | responseBody += chunk.toString() |
| 61 | }) |
| 62 | res.on('close', resClose) |
| 63 | } |
| 64 | ) |
| 65 | |
| 66 | req.on('close', reqClose) |
| 67 | req.end() |
| 68 | |
| 69 | await Promise.all([reqPromise, resPromise]) |
| 70 | expect(responseBody).toBe('Hello! Node!') |
| 71 | }) |
| 72 | |
| 73 | it('Should return 200 response - POST /posts', async () => { |
| 74 | let responseBody = '' |
| 75 | |
| 76 | const req = request( |
| 77 | { |
| 78 | hostname: address.address, |
| 79 | port: address.port, |
| 80 | method: 'POST', |
| 81 | path: '/posts', |
| 82 | rejectUnauthorized: false, |
| 83 | }, |
| 84 | (res) => { |
| 85 | res.on('data', (chunk) => { |
| 86 | responseBody += chunk.toString() |
| 87 | }) |
| 88 | res.on('close', resClose) |
| 89 | } |
| 90 | ) |
| 91 | |
| 92 | req.on('close', reqClose) |
| 93 | |
| 94 | req.write('') |
| 95 | // no explicit end |
| 96 | |
| 97 | await Promise.all([reqPromise, resPromise]) |
| 98 | expect(responseBody).toBe('') |
| 99 | }) |
| 100 | |
| 101 | it('Should return 200 response - POST /body-consumed', async () => { |
no test coverage detected
searching dependent graphs…