Skip to content

Commit

Permalink
rest: prefer arrayBuffer over buffer (#7318)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Feb 16, 2022
1 parent c1b27f8 commit 868e2f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
14 changes: 8 additions & 6 deletions packages/rest/__tests__/REST.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,14 @@ test('urlEncoded', async () => {
['code', 'very-invalid-code'],
]);
expect(
await api.post('/urlEncoded', {
body,
passThroughBody: true,
auth: false,
}),
).toStrictEqual(Buffer.from(body.toString()));
new Uint8Array(
(await api.post('/urlEncoded', {
body,
passThroughBody: true,
auth: false,
})) as ArrayBuffer,
),
).toStrictEqual(new Uint8Array(Buffer.from(body.toString())));
});

test('postEcho', async () => {
Expand Down
7 changes: 4 additions & 3 deletions packages/rest/__tests__/RequestHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,13 @@ test('Significant Invalid Requests', async () => {

test('Handle standard rate limits', async () => {
const [a, b, c] = [api.get('/standard'), api.get('/standard'), api.get('/standard')];
const uint8 = new Uint8Array();

expect(await a).toStrictEqual(Buffer.alloc(0));
expect(new Uint8Array((await a) as ArrayBuffer)).toStrictEqual(uint8);
const previous1 = performance.now();
expect(await b).toStrictEqual(Buffer.alloc(0));
expect(new Uint8Array((await b) as ArrayBuffer)).toStrictEqual(uint8);
const previous2 = performance.now();
expect(await c).toStrictEqual(Buffer.alloc(0));
expect(new Uint8Array((await c) as ArrayBuffer)).toStrictEqual(uint8);
const now = performance.now();
expect(previous2).toBeGreaterThanOrEqual(previous1 + 250);
expect(now).toBeGreaterThanOrEqual(previous2 + 250);
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function parseResponse(res: Response): Promise<unknown> {
return res.json();
}

return res.buffer();
return res.arrayBuffer();
}

/**
Expand Down

0 comments on commit 868e2f3

Please sign in to comment.