|
|
@ -35,7 +35,6 @@ test('option.json can not be used', t => { |
|
|
|
t.throws(() => { |
|
|
|
got.stream(s.url, {json: true}); |
|
|
|
}, 'got can not be used as stream when options.json is used'); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
|
|
|
|
test('callback can not be used', t => { |
|
|
@ -46,11 +45,9 @@ test('callback can not be used', t => { |
|
|
|
t.throws(() => { |
|
|
|
got.stream(s.url, () => {}); |
|
|
|
}, 'callback can not be used with stream mode'); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
|
|
|
|
test('returns readable stream', t => { |
|
|
|
test.cb('returns readable stream', t => { |
|
|
|
got.stream(s.url) |
|
|
|
.on('data', data => { |
|
|
|
t.is(data.toString(), 'ok'); |
|
|
@ -58,25 +55,25 @@ test('returns readable stream', t => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('returns writeable stream', t => { |
|
|
|
t.plan(1); |
|
|
|
test.cb('returns writeable stream', t => { |
|
|
|
got.stream.post(`${s.url}/post`) |
|
|
|
.on('data', data => { |
|
|
|
t.is(data.toString(), 'wow'); |
|
|
|
t.end(); |
|
|
|
}) |
|
|
|
.end('wow'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('throws on write to stream with body specified', t => { |
|
|
|
test.cb('throws on write to stream with body specified', t => { |
|
|
|
t.throws(() => { |
|
|
|
got.stream(s.url, {body: 'wow'}).write('wow'); |
|
|
|
}, 'got\'s stream is not writable when options.body is used'); |
|
|
|
|
|
|
|
// wait for request to end
|
|
|
|
setTimeout(t.end.bind(t), 10); |
|
|
|
setTimeout(t.end, 10); |
|
|
|
}); |
|
|
|
|
|
|
|
test('have request event', t => { |
|
|
|
test.cb('have request event', t => { |
|
|
|
got.stream(s.url) |
|
|
|
.on('request', req => { |
|
|
|
t.ok(req); |
|
|
@ -84,7 +81,7 @@ test('have request event', t => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('have redirect event', t => { |
|
|
|
test.cb('have redirect event', t => { |
|
|
|
got.stream(`${s.url}/redirect`) |
|
|
|
.on('redirect', res => { |
|
|
|
t.is(res.headers.location, s.url); |
|
|
@ -92,7 +89,7 @@ test('have redirect event', t => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('have response event', t => { |
|
|
|
test.cb('have response event', t => { |
|
|
|
got.stream(s.url) |
|
|
|
.on('response', res => { |
|
|
|
t.is(res.statusCode, 200); |
|
|
@ -100,7 +97,7 @@ test('have response event', t => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('have error event', t => { |
|
|
|
test.cb('have error event', t => { |
|
|
|
got.stream(`${s.url}/error`, {retries: 0}) |
|
|
|
.on('response', () => { |
|
|
|
t.fail('response event should not be emitted'); |
|
|
@ -113,7 +110,7 @@ test('have error event', t => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('have error event', t => { |
|
|
|
test.cb('have error event', t => { |
|
|
|
got.stream('.com', {retries: 0}) |
|
|
|
.on('response', () => { |
|
|
|
t.fail('response event should not be emitted'); |
|
|
@ -124,7 +121,7 @@ test('have error event', t => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
test('accepts option.body as Stream', t => { |
|
|
|
test.cb('accepts option.body as Stream', t => { |
|
|
|
got.stream(`${s.url}/post`, {body: intoStream(['wow'])}) |
|
|
|
.on('data', chunk => { |
|
|
|
t.is(chunk.toString(), 'wow'); |
|
|
|