GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(site): type the models.dev test fakes without casts · developing-today-forks/opencode@e335cef

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • services/site
    • src/lib
      • models-dev.ts
    • test
      • console-models.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎services/site/src/lib/models-dev.ts‎

Copy file name to clipboardExpand all lines: services/site/src/lib/models-dev.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type ModelsDev = Record<string, { models?: Record<string, ModelsDevModel> }>
2020
export async function fetchFreeModels(options?: {
2121
timeoutMs?: number
2222
maxBytes?: number
23-
fetch?: typeof fetch
23+
fetch?: (input: string, init?: { signal?: AbortSignal }) => Promise<Response>
2424
}): Promise<ModelsDevModel[]> {
2525
const load = options?.fetch ?? fetch
2626
const response = await load("https://models.dev/api.json", {
Collapse file

‎services/site/test/console-models.test.ts‎

Copy file name to clipboardExpand all lines: services/site/test/console-models.test.ts
+26-18Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,45 @@ const valid = JSON.stringify({
1818

1919
describe("fetchFreeModels", () => {
2020
test("returns the non-deprecated zero-cost models from a valid response", async () => {
21-
const load = (async () => new Response(valid)) as typeof fetch
22-
const models = await fetchFreeModels({ fetch: load })
21+
const models = await fetchFreeModels({ fetch: async () => new Response(valid) })
2322
expect(models.map((model) => model.id)).toEqual(["free"])
2423
})
2524

2625
test("a stalled request settles within the deadline", async () => {
27-
const load = ((_input: RequestInfo | URL, init?: RequestInit) =>
28-
new Promise<Response>((_resolve, reject) => {
29-
init?.signal?.addEventListener("abort", () => reject(init.signal?.reason))
30-
})) as typeof fetch
3126
const start = Date.now()
32-
await expect(fetchFreeModels({ fetch: load, timeoutMs: 25 })).rejects.toThrow()
27+
await expect(
28+
fetchFreeModels({
29+
timeoutMs: 25,
30+
fetch: (_input, init) =>
31+
new Promise<Response>((_resolve, reject) => {
32+
init?.signal?.addEventListener("abort", () => reject(init.signal?.reason))
33+
}),
34+
}),
35+
).rejects.toThrow()
3336
expect(Date.now() - start).toBeLessThan(5_000)
3437
})
3538

3639
test("a never-ending response body settles within the deadline", async () => {
37-
const load = (async (_input: RequestInfo | URL, init?: RequestInit) => {
38-
const body = new ReadableStream<Uint8Array>({
39-
start(controller) {
40-
init?.signal?.addEventListener("abort", () => controller.error(init.signal?.reason))
41-
},
42-
})
43-
return new Response(body)
44-
}) as typeof fetch
4540
const start = Date.now()
46-
await expect(fetchFreeModels({ fetch: load, timeoutMs: 25 })).rejects.toThrow()
41+
await expect(
42+
fetchFreeModels({
43+
timeoutMs: 25,
44+
fetch: async (_input, init) =>
45+
new Response(
46+
new ReadableStream<Uint8Array>({
47+
start(controller) {
48+
init?.signal?.addEventListener("abort", () => controller.error(init.signal?.reason))
49+
},
50+
}),
51+
),
52+
}),
53+
).rejects.toThrow()
4754
expect(Date.now() - start).toBeLessThan(5_000)
4855
})
4956

5057
test("an over-limit body is rejected before full buffering", async () => {
51-
const load = (async () => new Response(valid)) as typeof fetch
52-
await expect(fetchFreeModels({ fetch: load, maxBytes: 16 })).rejects.toThrow("exceeded 16 bytes")
58+
await expect(fetchFreeModels({ fetch: async () => new Response(valid), maxBytes: 16 })).rejects.toThrow(
59+
"exceeded 16 bytes",
60+
)
5361
})
5462
})

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.