-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
11 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
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,44 @@ | ||
'use strict' | ||
|
||
const { createServer } = require('http') | ||
const { once } = require('events') | ||
|
||
/* global expect, it, jest, AbortController */ | ||
|
||
// https://github.com/facebook/jest/issues/11607#issuecomment-899068995 | ||
jest.useRealTimers() | ||
|
||
const runIf = (condition) => condition ? it : it.skip | ||
const nodeMajor = Number(process.versions.node.split('.', 1)[0]) | ||
|
||
runIf(nodeMajor >= 16)('isErrorLike sanity check', () => { | ||
const { isErrorLike } = require('../../lib/fetch/util') | ||
const { DOMException } = require('../../lib/fetch/constants') | ||
const error = new DOMException('') | ||
|
||
// https://github.com/facebook/jest/issues/2549 | ||
expect(error instanceof Error).toBeFalsy() | ||
expect(isErrorLike(error)).toBeTruthy() | ||
}) | ||
|
||
runIf(nodeMajor >= 16)('Real use-case', async () => { | ||
const { fetch } = require('../..') | ||
|
||
const ac = new AbortController() | ||
ac.abort() | ||
|
||
const server = createServer((req, res) => { | ||
res.end() | ||
}).listen(0) | ||
|
||
await once(server, 'listening') | ||
|
||
const promise = fetch(`https://localhost:${server.address().port}`, { | ||
signal: ac.signal | ||
}) | ||
|
||
await expect(promise).rejects.toThrowError('The operation was aborted.') | ||
|
||
server.close() | ||
await once(server, 'close') | ||
}) |