-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(xhr): support original responses without any headers (#216)
- Loading branch information
1 parent
4563ce7
commit ef653c6
Showing
3 changed files
with
62 additions
and
4 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
53 changes: 53 additions & 0 deletions
53
test/modules/XMLHttpRequest/compliance/xhr-no-response-headers.test.ts
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,53 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { ServerApi, createServer } from '@open-draft/test-server' | ||
import { createInterceptor } from '../../../../src' | ||
import { interceptXMLHttpRequest } from '../../../../src/interceptors/XMLHttpRequest' | ||
import { createXMLHttpRequest } from '../../../helpers' | ||
|
||
let httpServer: ServerApi | ||
|
||
const interceptor = createInterceptor({ | ||
modules: [interceptXMLHttpRequest], | ||
resolver() {}, | ||
}) | ||
|
||
beforeAll(async () => { | ||
httpServer = await createServer((app) => { | ||
app.get('/user', (_req, res) => { | ||
// Respond with a message that has no headers. | ||
res.socket?.end(`\ | ||
HTTP/1.1 200 OK | ||
hello world`) | ||
}) | ||
}) | ||
|
||
interceptor.apply() | ||
|
||
/** | ||
* @note Stub the internal JSDOM property to prevent the following error: | ||
* Error: Cross origin http://127.0.0.1:XXXXX/ forbidden | ||
*/ | ||
const { protocol, host, port } = httpServer.http.getAddress() | ||
// @ts-expect-error | ||
window._origin = `${protocol}//${host}:${port}` | ||
}) | ||
|
||
afterAll(async () => { | ||
interceptor.restore() | ||
await httpServer.close() | ||
}) | ||
|
||
test('handles an original response without any headers', async () => { | ||
const req = await createXMLHttpRequest((req) => { | ||
req.open('GET', httpServer.http.makeUrl('/user')) | ||
req.send() | ||
}) | ||
|
||
expect(req.status).toEqual(200) | ||
expect(req.statusText).toEqual('OK') | ||
expect(req.responseText).toEqual('hello world') | ||
expect(req.getAllResponseHeaders()).toEqual('') | ||
}) |
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