Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adopt undici as fetch polyfill #340

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"@commitlint/config-conventional": "^16.0.0",
"@open-draft/test-server": "^0.4.2",
"@ossjs/release": "^0.4.0",
"@remix-run/web-fetch": "^4.3.1",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express-rate-limit": "^6.0.0",
Expand Down Expand Up @@ -112,6 +111,7 @@
"ts-jest": "^27.1.1",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"undici": "^5.20.0",
"wait-for-expect": "^3.0.2",
"web-encoding": "^1.1.5"
},
Expand Down Expand Up @@ -141,4 +141,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
4 changes: 2 additions & 2 deletions src/RemoteHttpInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChildProcess } from 'child_process'
import { Request, Response } from '@remix-run/web-fetch'
import { Headers, HeadersObject, headersToObject } from 'headers-polyfill'
import { Request, Response, Headers } from 'undici'
import { HeadersObject, headersToObject } from 'headers-polyfill'
import { HttpRequestEventMap } from './glossary'
import { Interceptor } from './Interceptor'
import { BatchInterceptor } from './BatchInterceptor'
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/ClientRequest/NodeClientRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { debug } from 'debug'
import * as express from 'express'
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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,6 +1,6 @@
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { ClientRequestInterceptor } from '.'

const httpServer = new HttpServer((app) => {
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/ClientRequest/utils/createRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request } from '@remix-run/web-fetch'
import { Request } from 'undici'
import { Headers } from 'headers-polyfill'
import type { NodeClientRequest } from '../NodeClientRequest'

Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/ClientRequest/utils/createResponse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IncomingMessage } from 'http'
import { Response, ReadableStream } from '@remix-run/web-fetch'
import { Response, ReadableStream } from 'undici'
import { objectToHeaders } from 'headers-polyfill'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Debugger } from 'debug'
import { Headers, Request } from '@remix-run/web-fetch'
import { Headers, Request } from 'undici'
import { headersToString } from 'headers-polyfill'
import { concatArrayBuffer } from './utils/concatArrayBuffer'
import { createEvent } from './utils/createEvent'
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/XMLHttpRequest/utils/createResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { stringToHeaders } from 'headers-polyfill'

export function createResponse(
Expand Down
2 changes: 1 addition & 1 deletion src/interceptors/fetch/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invariant } from 'outvariant'
import type { Response as ResponsePolyfill } from '@remix-run/web-fetch'
import type { Response as ResponsePolyfill } from 'undici'
import { HttpRequestEventMap, IS_PATCHED_MODULE } from '../../glossary'
import { Interceptor } from '../../Interceptor'
import { uuidv4 } from '../../utils/uuid'
Expand Down
6 changes: 4 additions & 2 deletions src/utils/toInteractiveRequest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { format } from 'outvariant'
import { createLazyCallback, LazyCallback } from './createLazyCallback'

type LazyResponseCallback = (response: Response) => void
type LazyResponseCallback = (response: globalThis.Response) => void

export type InteractiveRequest = globalThis.Request & {
respondWith: LazyCallback<LazyResponseCallback>
}

export function toInteractiveRequest(request: Request): InteractiveRequest {
export function toInteractiveRequest(
request: globalThis.Request
): InteractiveRequest {
Object.defineProperty(request, 'respondWith', {
writable: false,
enumerable: true,
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 { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { HttpRequestEventMap } from '../../../src'
import { createXMLHttpRequest, waitForClientRequest } from '../../helpers'
Expand Down
2 changes: 1 addition & 1 deletion test/features/remote/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as path from 'path'
import { spawn } from 'child_process'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { RemoteHttpResolver } from '../../../src/RemoteHttpInterceptor'

const CHILD_PATH = path.resolve(__dirname, 'child.js')
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import https from 'https'
import http, { ClientRequest, IncomingMessage, RequestOptions } from 'http'
import nodeFetch, { Response, RequestInfo, RequestInit } from 'node-fetch'
import { objectToHeaders } from 'headers-polyfill'
import { Request } from '@remix-run/web-fetch'
import { Request } from 'undici'
import { Page, ScenarioApi } from 'page-with'
import { getRequestOptionsByUrl } from '../src/utils/getRequestOptionsByUrl'
import { getIncomingMessageBody } from '../src/interceptors/ClientRequest/utils/getIncomingMessageBody'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
* @see https://github.com/mswjs/msw/issues/273
*/
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @see https://xhr.spec.whatwg.org/#events
*/
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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 { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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 { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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 { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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 { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { encodeBuffer } from '../../../../src'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { toArrayBuffer } from '../../../../src/utils/bufferUtils'
Expand Down
2 changes: 1 addition & 1 deletion test/modules/XMLHttpRequest/compliance/xhr-status.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/281
*/
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

Expand Down
2 changes: 1 addition & 1 deletion test/modules/XMLHttpRequest/features/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { HttpServer } from '@open-draft/test-server/http'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'
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
Expand Up @@ -2,7 +2,7 @@
* @jest-environment jsdom
*/
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
import { createXMLHttpRequest } from '../../../helpers'

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 @@ -4,7 +4,7 @@
import fetch from 'node-fetch'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'

const httpServer = new HttpServer((app) => {
app.get('/', (req, res) => {
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,7 +1,7 @@
import * as http from 'http'
import rateLimit from 'express-rate-limit'
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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 @@ -4,7 +4,7 @@
import { IncomingMessage } from 'http'
import * as https from 'https'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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-res-set-encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

const httpServer = new HttpServer((app) => {
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
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { ClientRequestInterceptor } from '../../../src/interceptors/ClientRequest'
import { httpGet, PromisifiedResponse } from '../../helpers'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { httpGet } from '../../../helpers'
import { sleep } from '../../../../test/helpers'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @see https://github.com/mswjs/interceptors/issues/2
*/
import * as http from 'http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'

let requests: Array<Request> = []
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 @@ -6,7 +6,7 @@
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
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 { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { HttpServer, httpsAgent } from '@open-draft/test-server/http'
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 @@ -3,7 +3,7 @@
*/
import * as http from 'http'
import { HttpServer } from '@open-draft/test-server/http'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'
import { BatchInterceptor } from '../../../../src'
import { ClientRequestInterceptor } from '../../../../src/interceptors/ClientRequest'
import { XMLHttpRequestInterceptor } from '../../../../src/interceptors/XMLHttpRequest'
Expand Down
2 changes: 1 addition & 1 deletion test/third-party/axios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import axios from 'axios'
import { HttpServer } from '@open-draft/test-server/http'
import { ClientRequestInterceptor } from '../../src/interceptors/ClientRequest'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'

const httpServer = new HttpServer((app) => {
app.get('/books', (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/third-party/got.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import got from 'got'
import { HttpServer } from '@open-draft/test-server/http'
import { ClientRequestInterceptor } from '../../src/interceptors/ClientRequest'
import { Response } from '@remix-run/web-fetch'
import { Response } from 'undici'

const httpServer = new HttpServer((app) => {
app.get('/user', (req, res) => {
Expand Down
Loading