|
|
@ -85,3 +85,35 @@ test('cancel immediately', async t => { |
|
|
|
await t.throws(p); |
|
|
|
await t.notThrows(aborted, 'Request finished instead of aborting.'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('recover from cancelation using cancelable promise attribute', async t => { |
|
|
|
// Canceled before connection started
|
|
|
|
const p = got('http://example.com'); |
|
|
|
const recover = p.catch(err => { |
|
|
|
if (p.canceled) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
throw err; |
|
|
|
}); |
|
|
|
|
|
|
|
p.cancel(); |
|
|
|
|
|
|
|
await t.notThrows(recover); |
|
|
|
}); |
|
|
|
|
|
|
|
test('recover from cancellation using error instance', async t => { |
|
|
|
// Canceled before connection started
|
|
|
|
const p = got('http://example.com'); |
|
|
|
const recover = p.catch(err => { |
|
|
|
if (err instanceof got.CancelError) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
throw err; |
|
|
|
}); |
|
|
|
|
|
|
|
p.cancel(); |
|
|
|
|
|
|
|
await t.notThrows(recover); |
|
|
|
}); |
|
|
|