Skip to content

Commit 62ff55b

Browse files
committed
Fix internal TS issues with latest Node Buffer types
1 parent b19499f commit 62ff55b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/rules/matchers.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,10 @@ export class MultipartFormDataMatcher extends Serializable implements RequestMat
403403
const parsedBody = multipart.parse(await request.body.asDecodedBuffer(), boundary[1]);
404404

405405
return this.matchConditions.every((condition) => {
406-
const expectedContent = condition.content
407-
? Buffer.from(condition.content)
406+
const expectedContent = typeof condition.content === 'string'
407+
? Buffer.from(condition.content, "utf8")
408+
: condition.content
409+
? Buffer.from(condition.content)
408410
: undefined;
409411

410412
return parsedBody.some((part) =>

src/rules/requests/request-handlers.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ async function writeResponseFromCallback(
193193
// RawBody takes priority if both are set (useful for backward compat) but if not then
194194
// the body is automatically encoded to match the content-encoding header.
195195
result.rawBody = await encodeBodyBuffer(
196-
Buffer.from(result.body),
196+
// Separate string case mostly required due to TS type issues:
197+
typeof result.body === 'string'
198+
? Buffer.from(result.body, "utf8")
199+
: Buffer.from(result.body),
197200
result.headers ?? {}
198201
);
199202
}

test/test-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export function getHttp2Body(req: http2.ClientHttp2Stream) {
296296

297297
const body: Buffer[] = [];
298298
req.on('data', (d: Buffer | string) => {
299-
body.push(Buffer.from(d));
299+
body.push(Buffer.from(d as Buffer));
300300
});
301301
req.on('end', () => req.close());
302302
req.on('close', () => resolve(Buffer.concat(body)));

0 commit comments

Comments
 (0)