-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abort request with reason if one is provided (#2592)
- Loading branch information
Showing
5 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { request } = require('..') | ||
const { createServer } = require('http') | ||
const { once } = require('events') | ||
|
||
test('aborting request with custom reason', async (t) => { | ||
const server = createServer(() => {}).listen(0) | ||
|
||
t.teardown(server.close.bind(server)) | ||
await once(server, 'listening') | ||
|
||
const timeout = AbortSignal.timeout(0) | ||
const ac = new AbortController() | ||
ac.abort(new Error('aborted')) | ||
|
||
const ac2 = new AbortController() | ||
ac2.abort() // no reason | ||
|
||
await t.rejects( | ||
request(`http://localhost:${server.address().port}`, { signal: timeout }), | ||
timeout.reason | ||
) | ||
|
||
await t.rejects( | ||
request(`http://localhost:${server.address().port}`, { signal: ac.signal }), | ||
ac.signal.reason | ||
) | ||
|
||
await t.rejects( | ||
request(`http://localhost:${server.address().port}`, { signal: ac2.signal }), | ||
{ code: 'UND_ERR_ABORTED' } | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters