-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(streaming): add js client crawl streaming callback
- Loading branch information
Showing
11 changed files
with
631 additions
and
3,830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,84 @@ | ||
import { describe, test, expect, jest } from "@jest/globals"; | ||
import { describe, test } from "node:test"; | ||
import assert from "node:assert"; | ||
import { Spider } from "../src"; | ||
|
||
jest.setTimeout(1000 * 60); | ||
import "dotenv/config"; | ||
|
||
describe("Spider JS SDK", () => { | ||
test("should throw error if API key is not provided", () => { | ||
expect(() => new Spider({ apiKey: undefined })).toThrow( | ||
"No API key provided" | ||
); | ||
if (!process.env.SPIDER_API_KEY) { | ||
assert.throws(() => new Spider({ apiKey: null })); | ||
} else { | ||
assert.doesNotThrow(() => new Spider({ apiKey: null })); | ||
} | ||
}); | ||
test("should scrape url with data", async () => { | ||
await import("dotenv/config"); | ||
|
||
if (process.env.SPIDER_API_KEY) { | ||
const spiderClient = new Spider({ apiKey: process.env.SPIDER_API_KEY }); | ||
const spiderData = await spiderClient.scrapeUrl("https://spider.cloud", { | ||
test("should crawl url with data", async () => { | ||
const spiderClient = new Spider(); | ||
const spiderData = await spiderClient.crawlUrl("https://spider.cloud", { | ||
store_data: true, | ||
limit: 2, | ||
}); | ||
|
||
assert(Array.isArray(spiderData)); | ||
assert(spiderData && spiderData.length === 2); | ||
}); | ||
|
||
test("should crawl url streaming with data", async () => { | ||
const stream = true; | ||
|
||
const spiderClient = new Spider(); | ||
const spiderData = await spiderClient.crawlUrl( | ||
"https://spider.cloud", | ||
{ | ||
store_data: true, | ||
}); | ||
limit: 4, | ||
}, | ||
stream, | ||
(data) => { | ||
assert(data["url"]); | ||
} | ||
); | ||
|
||
expect(Array.isArray(spiderData)); | ||
} | ||
assert(typeof spiderData === "undefined"); | ||
}); | ||
test("should get data from the api", async () => { | ||
await import("dotenv/config"); | ||
|
||
if (process.env.SPIDER_API_KEY) { | ||
const spiderClient = new Spider({ apiKey: process.env.SPIDER_API_KEY }); | ||
const spiderData = await spiderClient.getData("websites", { limit: 1 }); | ||
test("should scrape url with data", async () => { | ||
const spiderClient = new Spider(); | ||
const spiderData = await spiderClient.scrapeUrl("https://spider.cloud", { | ||
store_data: true, | ||
}); | ||
|
||
expect(Array.isArray(spiderData)); | ||
} | ||
assert(Array.isArray(spiderData)); | ||
}); | ||
test("should download data from the api", async () => { | ||
await import("dotenv/config"); | ||
|
||
if (process.env.SPIDER_API_KEY) { | ||
const spiderClient = new Spider({ apiKey: process.env.SPIDER_API_KEY }); | ||
const spiderData = await spiderClient.createSignedUrl("spider.cloud", { | ||
limit: 1, | ||
page: 0, | ||
}); | ||
test("should get data from the api", async () => { | ||
const spiderClient = new Spider(); | ||
const { data } = await spiderClient.getData("websites", { limit: 1 }); | ||
|
||
expect(spiderData); | ||
} | ||
assert(Array.isArray(data)); | ||
}); | ||
|
||
test("should connect with supabase", async () => { | ||
await import("dotenv/config"); | ||
// test.skip("should download data from the api", async () => { | ||
// await import("dotenv/config"); | ||
|
||
if (process.env.SPIDER_API_KEY) { | ||
const spiderClient = new Spider({ apiKey: process.env.SPIDER_API_KEY }); | ||
await spiderClient.init_supabase(); | ||
// const spiderClient = new Spider(); | ||
// const spiderData = await spiderClient.createSignedUrl("spider.cloud", { | ||
// limit: 1, | ||
// page: 0, | ||
// }); | ||
|
||
const auth = await spiderClient.supabase?.auth.signInWithPassword({ | ||
email: process.env.SPIDER_EMAIL || "", | ||
password: process.env.SPIDER_PASSWORD || "", | ||
}); | ||
// assert(spiderData); | ||
// }); | ||
|
||
expect(auth); | ||
} | ||
test("should connect with supabase", async () => { | ||
const spiderClient = new Spider(); | ||
await spiderClient.init_supabase(); | ||
|
||
const auth = await spiderClient.supabase?.auth.signInWithPassword({ | ||
email: process.env.SPIDER_EMAIL || "", | ||
password: process.env.SPIDER_PASSWORD || "", | ||
}); | ||
|
||
assert(auth); | ||
}); | ||
}); |
Oops, something went wrong.