diff --git a/packages/testserver/src/index.ts b/packages/testserver/src/index.ts index 153e4d19dbd..a4194d41cbe 100644 --- a/packages/testserver/src/index.ts +++ b/packages/testserver/src/index.ts @@ -66,6 +66,7 @@ export class TestServer { #csp = new Map(); #gzipRoutes = new Set(); #requestSubscribers = new Map(); + #requests = new Set(); static async create(dirPath: string): Promise { let res!: (value: unknown) => void; @@ -192,12 +193,20 @@ export class TestServer { subscriber.reject.call(undefined, error); } this.#requestSubscribers.clear(); + for (const request of this.#requests.values()) { + if (!request.writableEnded) { + request.end(); + } + } + this.#requests.clear(); } #onRequest: RequestListener = ( request: TestIncomingMessage, response ): void => { + this.#requests.add(response); + request.on('error', (error: {code: string}) => { if (error.code === 'ECONNRESET') { response.end();