index.test.ts•950 B
import { test, expect } from "bun:test";
import { readWebpageContent } from "./index";
// Test case for a successful fetch. We use a stable and simple page.
// We increase the timeout because network requests can be slow.
test("should read content from a valid URL", async () => {
const content = await readWebpageContent("https://example.com");
expect(content).toBeString();
// Jina reader API returns plain text. Let's check for a known string.
expect(content).toContain("Example Domain");
}, 20000); // 20-second timeout for the network request
// Test case for a URL that results in a fetch error (e.g., 404)
test("should throw an error for a non-existent page", async () => {
// This URL is syntactically valid but points to nothing.
// Jina's service should return an error.
const promise = readWebpageContent("https://domain.invalid/");
await expect(promise).rejects.toThrow();
}, 20000); // Also give this a longer timeout