Skip to content

Commit 8f44af9

Browse files
test: add comprehensive tests for formats, fetchConfig, and document types
- Add unit tests for all scrape formats (markdown, html, json, screenshot, summary, branding, links, images) - Add tests for fetchConfig options (mode, stealth, timeout, headers, cookies, country, scrolls) - Add tests for PDF/DOCX/image document scraping with OCR - Add extract tests for URL, HTML, and markdown inputs with schema - Add search tests with filters (location, timeRange, numResults) - Add crawl/monitor tests with full config options - Fix types to use z.input for request types (allows omitting fields with defaults) - Remove obsolete v1 integration_test.ts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 11b811c commit 8f44af9

4 files changed

Lines changed: 739 additions & 142 deletions

File tree

integration_test.ts

Lines changed: 0 additions & 130 deletions
This file was deleted.

src/types.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ import type {
1414
apiSearchRequestSchema,
1515
} from "./schemas.js";
1616

17-
export type ApiFetchConfig = z.infer<typeof apiFetchConfigSchema>;
17+
export type ApiFetchConfig = z.input<typeof apiFetchConfigSchema>;
1818
export type ApiFetchContentType = z.infer<typeof apiFetchContentTypeSchema>;
1919
export type ApiHtmlMode = z.infer<typeof apiHtmlModeSchema>;
20-
export type ApiScrapeFormatEntry = z.infer<typeof apiScrapeFormatEntrySchema>;
21-
22-
export type ApiScrapeRequest = z.infer<typeof apiScrapeRequestSchema>;
23-
export type ApiExtractRequest = z.infer<typeof apiExtractRequestBaseSchema>;
24-
export type ApiGenerateSchemaRequest = z.infer<typeof apiGenerateSchemaRequestSchema>;
25-
export type ApiSearchRequest = z.infer<typeof apiSearchRequestSchema>;
26-
export type ApiCrawlRequest = z.infer<typeof apiCrawlRequestSchema>;
27-
export type ApiMonitorCreateInput = z.infer<typeof apiMonitorCreateSchema>;
28-
export type ApiMonitorUpdateInput = z.infer<typeof apiMonitorUpdateSchema>;
29-
export type ApiHistoryFilter = z.infer<typeof apiHistoryFilterSchema>;
20+
export type ApiScrapeFormatEntry = z.input<typeof apiScrapeFormatEntrySchema>;
21+
22+
export type ApiScrapeRequest = z.input<typeof apiScrapeRequestSchema>;
23+
export type ApiExtractRequest = z.input<typeof apiExtractRequestBaseSchema>;
24+
export type ApiGenerateSchemaRequest = z.input<typeof apiGenerateSchemaRequestSchema>;
25+
export type ApiSearchRequest = z.input<typeof apiSearchRequestSchema>;
26+
export type ApiCrawlRequest = z.input<typeof apiCrawlRequestSchema>;
27+
export type ApiMonitorCreateInput = z.input<typeof apiMonitorCreateSchema>;
28+
export type ApiMonitorUpdateInput = z.input<typeof apiMonitorUpdateSchema>;
29+
export type ApiHistoryFilter = z.input<typeof apiHistoryFilterSchema>;
3030

3131
export type ApiScrapeFormat =
3232
| "markdown"

tests/integration.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from "bun:test";
2-
import { crawl, extract, getCredits, getHistory, monitor, scrape, search } from "../src/index.js";
2+
import { crawl, extract, getCredits, getHistory, scrape, search } from "../src/index.js";
33

44
const API_KEY = process.env.SGAI_API_KEY || "sgai-669918e5-55be-4752-a684-f6da788d1384";
55

@@ -22,6 +22,38 @@ describe("integration", () => {
2222
expect(res.data?.results.markdown).toBeDefined();
2323
});
2424

25+
test("scrape with multiple formats", async () => {
26+
const res = await scrape(API_KEY, {
27+
url: "https://example.com",
28+
formats: [{ type: "markdown", mode: "reader" }, { type: "links" }, { type: "images" }],
29+
});
30+
console.log("scrape multi:", res.status, res.error);
31+
expect(res.status).toBe("success");
32+
expect(res.data?.results.markdown).toBeDefined();
33+
expect(res.data?.results.links).toBeDefined();
34+
});
35+
36+
test("scrape PDF document", async () => {
37+
const res = await scrape(API_KEY, {
38+
url: "https://pdfobject.com/pdf/sample.pdf",
39+
contentType: "application/pdf",
40+
formats: [{ type: "markdown" }],
41+
});
42+
console.log("scrape PDF:", res.status, res.error);
43+
expect(res.status).toBe("success");
44+
expect(res.data?.metadata.contentType).toBe("application/pdf");
45+
});
46+
47+
test("scrape with fetchConfig", async () => {
48+
const res = await scrape(API_KEY, {
49+
url: "https://example.com",
50+
fetchConfig: { mode: "fast", timeout: 15000 },
51+
formats: [{ type: "markdown" }],
52+
});
53+
console.log("scrape fetchConfig:", res.status, res.error);
54+
expect(res.status).toBe("success");
55+
});
56+
2557
test("extract", async () => {
2658
const res = await extract(API_KEY, {
2759
url: "https://example.com",

0 commit comments

Comments
 (0)