rest: prefer arrayBuffer over buffer (#7318)

This commit is contained in:
Khafra
2022-02-16 02:34:54 -05:00
committed by GitHub
parent c1b27f8eed
commit 868e2f3230
3 changed files with 13 additions and 10 deletions

View File

@@ -205,12 +205,14 @@ test('urlEncoded', async () => {
['code', 'very-invalid-code'], ['code', 'very-invalid-code'],
]); ]);
expect( expect(
await api.post('/urlEncoded', { new Uint8Array(
body, (await api.post('/urlEncoded', {
passThroughBody: true, body,
auth: false, passThroughBody: true,
}), auth: false,
).toStrictEqual(Buffer.from(body.toString())); })) as ArrayBuffer,
),
).toStrictEqual(new Uint8Array(Buffer.from(body.toString())));
}); });
test('postEcho', async () => { test('postEcho', async () => {

View File

@@ -259,12 +259,13 @@ test('Significant Invalid Requests', async () => {
test('Handle standard rate limits', async () => { test('Handle standard rate limits', async () => {
const [a, b, c] = [api.get('/standard'), api.get('/standard'), api.get('/standard')]; 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(); const previous1 = performance.now();
expect(await b).toStrictEqual(Buffer.alloc(0)); expect(new Uint8Array((await b) as ArrayBuffer)).toStrictEqual(uint8);
const previous2 = performance.now(); const previous2 = performance.now();
expect(await c).toStrictEqual(Buffer.alloc(0)); expect(new Uint8Array((await c) as ArrayBuffer)).toStrictEqual(uint8);
const now = performance.now(); const now = performance.now();
expect(previous2).toBeGreaterThanOrEqual(previous1 + 250); expect(previous2).toBeGreaterThanOrEqual(previous1 + 250);
expect(now).toBeGreaterThanOrEqual(previous2 + 250); expect(now).toBeGreaterThanOrEqual(previous2 + 250);

View File

@@ -11,7 +11,7 @@ export function parseResponse(res: Response): Promise<unknown> {
return res.json(); return res.json();
} }
return res.buffer(); return res.arrayBuffer();
} }
/** /**