Skip to content
Merged
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 types/k6/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,15 +620,15 @@ export interface RefinedResponse<RT extends ResponseType | undefined> extends Re
/**
* Response body.
*/
export type ResponseBody = string | bytes | null;
export type ResponseBody = string | ArrayBuffer | null;

/**
* Refined response body.
* Best possible type given `responseType` from request parameters.
* @template RT - `Params.responseType` value.
* @privateRemarks Default type is a union due to depending on program options.
*/
export type RefinedResponseBody<RT extends ResponseType | undefined> = RT extends "binary" ? bytes
export type RefinedResponseBody<RT extends ResponseType | undefined> = RT extends "binary" ? ArrayBuffer
: RT extends "none" ? null
: RT extends "text" ? string
: RT extends undefined ? string | null
Expand Down
8 changes: 8 additions & 0 deletions types/k6/k6-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ function test6() {
http.get("https://loadimpact.com/features");
}

function test7() {
const res = http.get("https://httpbin.test.k6.io/bytes/10", { responseType: "binary" });
check(res, {
"response code was 200": res => res.status === 200,
"body size was 1234 bytes": res => res.body.byteLength === 1234,
});
}

function httpTest1() {
const responses = http.batch([
"http://test.loadimpact.com",
Expand Down
7 changes: 7 additions & 0 deletions types/k6/test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ asyncRequest("get", addressFromHttpURL);
asyncRequest("get", address).then(res => {
responseDefault = res;
});
asyncRequest("get", address, null, { responseType: "binary" }).then(res => {
responseBinary = res;
});
asyncRequest("get", address, null, { responseType: "binary" }).then(res => {
// @ts-expect-error
responseDefault = res;
});
// @ts-expect-error
asyncRequest("post", address, 5);
asyncRequest("post", address, "welcome to the internet").then(res => {
Expand Down