Spaces:
Running
Running
Download tests/read-pages.test.ts from Shoraky/Sporalize-api: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/tests/read-pages.test.ts
- Command line
-
hf download hf://spaces/Shoraky/Sporalize-api/tests/read-pages.test.ts
-
curl -L -o read-pages.test.ts https://huggingface.co/spaces/Shoraky/Sporalize-api/resolve/main/tests/read-pages.test.ts
1 kB
| import assert from "node:assert/strict"; | |
| import { test } from "node:test"; | |
| import { readPages } from "../src/read-pages.js"; | |
| test("reads beyond the upstream row cap with inclusive, ordered ranges", async () => { | |
| const input = Array.from({ length: 1203 }, (_, index) => index); | |
| const ranges: number[][] = []; | |
| const rows = await readPages(async (from, to) => { | |
| ranges.push([from, to]); | |
| return input.slice(from, to + 1); | |
| }); | |
| assert.deepEqual(rows, input); | |
| assert.deepEqual(ranges, [[0, 499], [500, 999], [1000, 1499]]); | |
| }); | |
| test("handles empty and exact page boundaries, and propagates failure", async () => { | |
| assert.deepEqual(await readPages(async () => []), []); | |
| let calls = 0; | |
| assert.deepEqual(await readPages(async (from) => { calls++; return from ? [] : [1, 2]; }, 2), [1, 2]); | |
| assert.equal(calls, 2); | |
| await assert.rejects(readPages(async () => { throw new Error("offline"); }), /offline/); | |
| await assert.rejects(readPages(async () => [], 0), /Invalid page size/); | |
| }); | |