Skip to content

Commit

Permalink
test(integration): patch over IPv6 bug in upstream `@open-draft/test-…
Browse files Browse the repository at this point in the history
…server`

* Patch a bug in `@open-draft/test-server` which improperly serializes
the host in IPv6 URLs
* Fix the bug by patching the prototype and re-exporting it in a new file
* Unfortunately, update every import of `@open-draft/test-server` to
import the patched/re-exported version.

Note: This commit is an atomic patch, so when the upstream bug is fixed,
you can revert this commit to restore the imports and delete the patch.
  • Loading branch information
milesrichardson committed Sep 28, 2022
1 parent 0a3e56b commit 09198d9
Show file tree
Hide file tree
Showing 42 changed files with 156 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/interceptors/ClientRequest/NodeClientRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { debug } from 'debug'
import * as express from 'express'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../test/patched/OpenDraftTestServer'
import { NodeClientRequest } from './NodeClientRequest'
import { getIncomingMessageBody } from './utils/getIncomingMessageBody'
import { normalizeClientRequestArgs } from './utils/normalizeClientRequestArgs'
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/ClientRequest/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../test/patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '.'

const httpServer = new HttpServer((app) => {
Expand Down
2 changes: 1 addition & 1 deletion test/features/events/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../patched/OpenDraftTestServer'
import { HttpRequestEventMap } from '../../../src'
import { createXMLHttpRequest, waitForClientRequest } from '../../helpers'
import { anyUuid, headersContaining } from '../../jest.expect'
Expand Down
2 changes: 1 addition & 1 deletion test/features/events/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as https from 'https'
import fetch from 'node-fetch'
import waitForExpect from 'wait-for-expect'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../patched/OpenDraftTestServer'
import {
HttpRequestEventMap,
IsomorphicRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { createXMLHttpRequest } from '../../../helpers'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/XMLHttpRequest/compliance/xhr-timeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
* @see https://github.com/mswjs/interceptors/issues/7
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { sleep } from '../../../../test/helpers'
import { createXMLHttpRequest } from '../../../helpers'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { RequestHandler } from 'express-serve-static-core'
import { createBrowserXMLHttpRequest } from '../../../helpers'
import { IsomorphicRequest, IsomorphicResponse } from '../../../../src'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import type { RequestHandler } from 'express'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { IsomorphicRequest } from '../../../../src'
import {
XMLHttpRequestEventListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { createBrowserXMLHttpRequest } from '../../../helpers'

declare namespace window {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/XMLHttpRequest/response/xhr.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import {
createBrowserXMLHttpRequest,
createRawBrowserXMLHttpRequest,
Expand Down
2 changes: 1 addition & 1 deletion test/modules/XMLHttpRequest/response/xhr.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/intercept/fetch.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { RequestHandler } from 'express'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { Response, pageWith, ScenarioApi } from 'page-with'
import { extractRequestFromPage } from '../../../helpers'
import { IsomorphicRequest } from '../../../../src'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/intercept/fetch.clone.browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'

declare namespace window {
export const fetchData: (url: RequestInfo) => Promise<void>
Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/intercept/fetch.request.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { extractRequestFromPage } from '../../../helpers'
import { anyUuid, headersContaining } from '../../../jest.expect'
import { encodeBuffer } from '../../../../src/utils/bufferUtils'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/intercept/fetch.request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import { Request } from 'node-fetch'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { HttpRequestEventMap } from '../../../../src'
import { fetch } from '../../../helpers'
import { anyUuid, headersContaining } from '../../../jest.expect'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/intercept/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import fetch from 'node-fetch'
import { RequestHandler } from 'express'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { HttpRequestEventMap } from '../../../../src'
import { anyUuid, headersContaining } from '../../../jest.expect'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { FetchInterceptor } from '../../../../src/interceptors/fetch'
import { listToHeaders } from 'headers-polyfill'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/response/fetch.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { pageWith } from 'page-with'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { listToHeaders } from 'headers-polyfill'
import { FetchInterceptor } from '../../../../src/interceptors/fetch'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/fetch/response/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import fetch from 'node-fetch'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

const httpServer = new HttpServer((app) => {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/compliance/http-rate-limit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as http from 'http'
import rateLimit from 'express-rate-limit'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

const httpServer = new HttpServer((app) => {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/compliance/http-req-callback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { IncomingMessage } from 'http'
import * as https from 'https'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { getRequestOptionsByUrl } from '../../../../src/utils/getRequestOptionsByUrl'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/compliance/http-req-write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as http from 'http'
import * as express from 'express'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { NodeClientRequest } from '../../../../src/interceptors/ClientRequest/NodeClientRequest'
import { waitForClientRequest } from '../../../helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @see https://github.com/mswjs/interceptors/issues/161
*/
import http, { IncomingMessage } from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { HttpRequestEventMap, IsomorphicResponse } from '../../../../src'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/compliance/http-res-set-encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

const httpServer = new HttpServer((app) => {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/compliance/https-constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import * as https from 'https'
import { URL } from 'url'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { getIncomingMessageBody } from '../../../../src/interceptors/ClientRequest/utils/getIncomingMessageBody'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/http-performance.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment node
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '../../../src/interceptors/ClientRequest'
import { httpGet, PromisifiedResponse } from '../../helpers'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/intercept/http.get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
import { anyUuid, headersContaining } from '../../../jest.expect'
import { waitForClientRequest } from '../../../helpers'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/intercept/http.request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as http from 'http'
import { RequestHandler } from 'express-serve-static-core'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { anyUuid, headersContaining } from '../../../jest.expect'
import { waitForClientRequest } from '../../../helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/intercept/https.get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import * as https from 'https'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { anyUuid, headersContaining } from '../../../jest.expect'
import { waitForClientRequest } from '../../../helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/intercept/https.request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as https from 'https'
import { RequestHandler } from 'express'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { waitForClientRequest } from '../../../helpers'
import { anyUuid, headersContaining } from '../../../jest.expect'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment node
*/
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { httpGet } from '../../../helpers'
import { sleep } from '../../../../test/helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/regressions/http-socket-timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* due to the unterminated socket.
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

jest.setTimeout(5000)
Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/response/http-https.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as http from 'http'
import * as https from 'https'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpServer, httpsAgent } from '../../../patched/OpenDraftTestServer'
import { waitForClientRequest } from '../../../helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/http/response/http-response-patching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { HttpServer } from '../../../patched/OpenDraftTestServer'
import { BatchInterceptor, MockedResponse } from '../../../../src'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
Expand Down
Loading

0 comments on commit 09198d9

Please sign in to comment.