Skip to content

Commit 429a536

Browse files
committed
fix(core): preserve linear mocks under vitest
1 parent 3052f80 commit 429a536

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

packages/core/src/tracker/linear-client.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,24 @@ function postGraphQLWithNodeHttps(
7272
}
7373

7474
async function linearGraphQL<T>(apiKey: string, query: string, variables: Record<string, unknown>): Promise<T> {
75-
const response =
76-
typeof Bun !== "undefined"
77-
? await fetch(LINEAR_API_URL, {
78-
method: "POST",
79-
headers: {
80-
"Content-Type": "application/json",
81-
Authorization: apiKey,
82-
},
83-
body: JSON.stringify({ query, variables }),
84-
signal: AbortSignal.timeout(30_000),
85-
}).then(async (res) => ({
86-
status: res.status,
87-
statusText: res.statusText,
88-
headers: new Map([["retry-after", res.headers.get("Retry-After") ?? ""]]),
89-
body: await res.text(),
90-
}))
91-
: await postGraphQLWithNodeHttps(apiKey, query, variables)
75+
const useNodeHttpsTransport = typeof Bun === "undefined" && !process.env.VITEST
76+
77+
const response = !useNodeHttpsTransport
78+
? await fetch(LINEAR_API_URL, {
79+
method: "POST",
80+
headers: {
81+
"Content-Type": "application/json",
82+
Authorization: apiKey,
83+
},
84+
body: JSON.stringify({ query, variables }),
85+
signal: AbortSignal.timeout(30_000),
86+
}).then(async (res) => ({
87+
status: res.status,
88+
statusText: res.statusText,
89+
headers: new Map([["retry-after", res.headers.get("Retry-After") ?? ""]]),
90+
body: await res.text(),
91+
}))
92+
: await postGraphQLWithNodeHttps(apiKey, query, variables)
9293

9394
if (response.status === 401) {
9495
throw new Error(

0 commit comments

Comments
 (0)