Skip to content

Commit fc4dd90

Browse files
committed
Update tests
1 parent 28f03f1 commit fc4dd90

8 files changed

Lines changed: 126 additions & 140 deletions

tests/engines/apple_reviews_test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("apple_reviews", {
6060
await t.step("async/await", async () => {
6161
const ids: number[] = [];
6262
let page;
63-
page = await getJson(engine, { product_id: productId });
63+
page = await getJson({ engine, product_id: productId });
6464
while (page) {
6565
ids.push(...page.reviews.map((r: any) => r.id));
6666
if (ids.length >= 50) break;
@@ -72,7 +72,7 @@ describe("apple_reviews", {
7272
await t.step("callback", async () => {
7373
const ids: number[] = [];
7474
await new Promise<void>((done) => {
75-
getJson(engine, { product_id: productId }, (page) => {
75+
getJson({ engine, product_id: productId }, (page) => {
7676
ids.push(...page.reviews.map((r: any) => r.id));
7777
if (ids.length < 50 && page.next) {
7878
page.next();
@@ -92,7 +92,8 @@ describe("apple_reviews", {
9292
config.api_key = null;
9393

9494
await t.step("async/await", async () => {
95-
const page1 = await getJson(engine, {
95+
const page1 = await getJson({
96+
engine,
9697
api_key: SERPAPI_TEST_KEY,
9798
no_cache: false,
9899
product_id: productId,
@@ -109,7 +110,8 @@ describe("apple_reviews", {
109110
await t.step("callback", async () => {
110111
const page1 = await new Promise<Awaited<ReturnType<typeof getJson>>>(
111112
(res) =>
112-
getJson(engine, {
113+
getJson({
114+
engine,
113115
api_key: SERPAPI_TEST_KEY,
114116
no_cache: false,
115117
product_id: productId,
@@ -130,13 +132,13 @@ describe("apple_reviews", {
130132
it("getJson pagination with page", {
131133
ignore: !HAS_API_KEY,
132134
}, async (t) => {
133-
const firstPage = await getJson(engine, { product_id: productId });
135+
const firstPage = await getJson({ engine, product_id: productId });
134136
const idsOnFirstPage = firstPage.reviews.map((r: any) => r.id);
135137

136138
await t.step("async/await", async () => {
137139
const ids: number[] = [];
138140
let page;
139-
page = await getJson(engine, { product_id: productId, page: "2" });
141+
page = await getJson({ engine, product_id: productId, page: "2" });
140142
while (page) {
141143
ids.push(...page.reviews.map((r: any) => r.id));
142144
if (ids.length >= 50) break;
@@ -153,7 +155,7 @@ describe("apple_reviews", {
153155
await t.step("callback", async () => {
154156
const ids: number[] = [];
155157
await new Promise<void>((done) => {
156-
getJson(engine, { product_id: productId, page: "2" }, (page) => {
158+
getJson({ engine, product_id: productId, page: "2" }, (page) => {
157159
ids.push(...page.reviews.map((r: any) => r.id));
158160
if (ids.length < 50 && page.next) {
159161
page.next();
@@ -176,7 +178,7 @@ describe("apple_reviews", {
176178
await t.step("async/await", async () => {
177179
let page;
178180
let pageNum = 0;
179-
page = await getJson(engine, { product_id: productId, page: "99" });
181+
page = await getJson({ engine, product_id: productId, page: "99" });
180182
while (page && pageNum < 5) {
181183
pageNum++;
182184
page = await page.next?.();
@@ -187,7 +189,7 @@ describe("apple_reviews", {
187189
await t.step("callback", async () => {
188190
let pageNum = 0;
189191
await new Promise<void>((done) => {
190-
getJson(engine, { product_id: productId, page: "99" }, (page) => {
192+
getJson({ engine, product_id: productId, page: "99" }, (page) => {
191193
pageNum++;
192194
if (pageNum < 5 && page.next) {
193195
page.next();

tests/engines/baidu_test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("baidu", {
6060
await t.step("async/await", async () => {
6161
const links: string[] = [];
6262
let page;
63-
page = await getJson(engine, { q });
63+
page = await getJson({ engine, q });
6464
while (page) {
6565
links.push(...page.organic_results.map((r: any) => r.link));
6666
if (links.length >= 20) break;
@@ -72,7 +72,7 @@ describe("baidu", {
7272
await t.step("callback", async () => {
7373
const links: string[] = [];
7474
await new Promise<void>((done) => {
75-
getJson(engine, { q }, (page) => {
75+
getJson({ engine, q }, (page) => {
7676
links.push(...page.organic_results.map((r: any) => r.link));
7777
if (links.length < 20 && page.next) {
7878
page.next();
@@ -92,7 +92,8 @@ describe("baidu", {
9292
config.api_key = null;
9393

9494
await t.step("async/await", async () => {
95-
const page1 = await getJson(engine, {
95+
const page1 = await getJson({
96+
engine,
9697
api_key: SERPAPI_TEST_KEY,
9798
no_cache: false,
9899
q,
@@ -109,11 +110,10 @@ describe("baidu", {
109110
await t.step("callback", async () => {
110111
const page1 = await new Promise<Awaited<ReturnType<typeof getJson>>>(
111112
(res) =>
112-
getJson(engine, {
113-
api_key: SERPAPI_TEST_KEY,
114-
no_cache: false,
115-
q,
116-
}, res),
113+
getJson(
114+
{ engine, api_key: SERPAPI_TEST_KEY, no_cache: false, q },
115+
res,
116+
),
117117
);
118118
assertMatch(executeSpy.calls[0].args[1].api_key as string, /[a-z0-9]+/);
119119
assertEquals(executeSpy.calls[0].args[1].no_cache, false);
@@ -130,13 +130,13 @@ describe("baidu", {
130130
it("getJson pagination with offset + size", {
131131
ignore: !HAS_API_KEY,
132132
}, async (t) => {
133-
const firstPage = await getJson(engine, { q });
133+
const firstPage = await getJson({ engine, q });
134134
const linksOnFirstPage = firstPage.organic_results.map((r: any) => r.link);
135135

136136
await t.step("async/await", async () => {
137137
const links: string[] = [];
138138
let page;
139-
page = await getJson(engine, { q, pn: "30", rn: "30" });
139+
page = await getJson({ engine, q, pn: "30", rn: "30" });
140140
while (page) {
141141
links.push(...page.organic_results.map((r: any) => r.link));
142142
if (links.length >= 60) break;
@@ -152,7 +152,7 @@ describe("baidu", {
152152
await t.step("callback", async () => {
153153
const links: string[] = [];
154154
await new Promise<void>((done) => {
155-
getJson(engine, { q, pn: "30", rn: "30" }, (page) => {
155+
getJson({ engine, q, pn: "30", rn: "30" }, (page) => {
156156
links.push(...page.organic_results.map((r: any) => r.link));
157157
if (links.length < 60 && page.next) {
158158
page.next();
@@ -175,7 +175,7 @@ describe("baidu", {
175175
await t.step("async/await", async () => {
176176
let page;
177177
let pageNum = 0;
178-
page = await getJson(engine, { q, pn: "750" });
178+
page = await getJson({ engine, q, pn: "750" });
179179
while (page && pageNum < 5) {
180180
pageNum++;
181181
page = await page.next?.();
@@ -186,7 +186,7 @@ describe("baidu", {
186186
await t.step("callback", async () => {
187187
let pageNum = 0;
188188
await new Promise<void>((done) => {
189-
getJson(engine, { q, pn: "750" }, (page) => {
189+
getJson({ engine, q, pn: "750" }, (page) => {
190190
pageNum++;
191191
if (pageNum < 5 && page.next) {
192192
page.next();

tests/engines/duckduckgo_test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("duckduckgo", {
6060
await t.step("async/await", async () => {
6161
const links: string[] = [];
6262
let page;
63-
page = await getJson(engine, { q });
63+
page = await getJson({ engine, q });
6464
while (page) {
6565
links.push(...page.organic_results.map((r: any) => r.link));
6666
if (links.length >= 50) break;
@@ -72,7 +72,7 @@ describe("duckduckgo", {
7272
await t.step("callback", async () => {
7373
const links: string[] = [];
7474
await new Promise<void>((done) => {
75-
getJson(engine, { q }, (page) => {
75+
getJson({ engine, q }, (page) => {
7676
links.push(...page.organic_results.map((r: any) => r.link));
7777
if (links.length < 50 && page.next) {
7878
page.next();
@@ -92,7 +92,8 @@ describe("duckduckgo", {
9292
config.api_key = null;
9393

9494
await t.step("async/await", async () => {
95-
const page1 = await getJson(engine, {
95+
const page1 = await getJson({
96+
engine,
9697
api_key: SERPAPI_TEST_KEY,
9798
no_cache: false,
9899
q,
@@ -109,11 +110,10 @@ describe("duckduckgo", {
109110
await t.step("callback", async () => {
110111
const page1 = await new Promise<Awaited<ReturnType<typeof getJson>>>(
111112
(res) =>
112-
getJson(engine, {
113-
api_key: SERPAPI_TEST_KEY,
114-
no_cache: false,
115-
q,
116-
}, res),
113+
getJson(
114+
{ engine, api_key: SERPAPI_TEST_KEY, no_cache: false, q },
115+
res,
116+
),
117117
);
118118
assertMatch(executeSpy.calls[0].args[1].api_key as string, /[a-z0-9]+/);
119119
assertEquals(executeSpy.calls[0].args[1].no_cache, false);
@@ -130,15 +130,15 @@ describe("duckduckgo", {
130130
it("getJson pagination with offset", {
131131
ignore: !HAS_API_KEY,
132132
}, async (t) => {
133-
const firstPage = await getJson(engine, { q });
133+
const firstPage = await getJson({ engine, q });
134134
const linksOnFirstPage: string[] = firstPage.organic_results.map((
135135
r: any,
136136
) => r.link);
137137

138138
await t.step("async/await", async () => {
139139
const links: string[] = [];
140140
let page;
141-
page = await getJson(engine, { q, start: 10 });
141+
page = await getJson({ engine, q, start: 10 });
142142
while (page) {
143143
links.push(...page.organic_results.map((r: any) => r.link));
144144
if (links.length >= 50) break;
@@ -155,7 +155,7 @@ describe("duckduckgo", {
155155
await t.step("callback", async () => {
156156
const links: string[] = [];
157157
await new Promise<void>((done) => {
158-
getJson(engine, { q, start: 10 }, (page) => {
158+
getJson({ engine, q, start: 10 }, (page) => {
159159
links.push(...page.organic_results.map((r: any) => r.link));
160160
if (links.length < 50 && page.next) {
161161
page.next();
@@ -178,7 +178,7 @@ describe("duckduckgo", {
178178
await t.step("async/await", async () => {
179179
let page;
180180
let pageNum = 0;
181-
page = await getJson(engine, { q, kl: "uk-en", no_cache: true });
181+
page = await getJson({ engine, q, kl: "uk-en", no_cache: true });
182182
while (page && pageNum < 8) {
183183
pageNum++;
184184
page = await page.next?.();
@@ -189,7 +189,7 @@ describe("duckduckgo", {
189189
await t.step("callback", async () => {
190190
let pageNum = 0;
191191
await new Promise<void>((done) => {
192-
getJson(engine, { q, kl: "uk-en" }, (page) => {
192+
getJson({ engine, q, kl: "uk-en" }, (page) => {
193193
pageNum++;
194194
if (pageNum < 8 && page.next) {
195195
page.next();

tests/engines/ebay_test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe("ebay", {
6060
await t.step("async/await", async () => {
6161
const links: string[] = [];
6262
let page;
63-
page = await getJson(engine, { _nkw: nkw });
63+
page = await getJson({ engine, _nkw: nkw });
6464
while (page) {
6565
links.push(...page.organic_results.map((r: any) => r.link));
6666
if (links.length >= 120) break;
@@ -72,7 +72,7 @@ describe("ebay", {
7272
await t.step("callback", async () => {
7373
const links: string[] = [];
7474
await new Promise<void>((done) => {
75-
getJson(engine, { _nkw: nkw }, (page) => {
75+
getJson({ engine, _nkw: nkw }, (page) => {
7676
links.push(...page.organic_results.map((r: any) => r.link));
7777
if (links.length < 120 && page.next) {
7878
page.next();
@@ -92,7 +92,8 @@ describe("ebay", {
9292
config.api_key = null;
9393

9494
await t.step("async/await", async () => {
95-
const page1 = await getJson(engine, {
95+
const page1 = await getJson({
96+
engine,
9697
api_key: SERPAPI_TEST_KEY,
9798
no_cache: false,
9899
_nkw: nkw,
@@ -109,7 +110,8 @@ describe("ebay", {
109110
await t.step("callback", async () => {
110111
const page1 = await new Promise<Awaited<ReturnType<typeof getJson>>>(
111112
(res) =>
112-
getJson(engine, {
113+
getJson({
114+
engine,
113115
api_key: SERPAPI_TEST_KEY,
114116
no_cache: false,
115117
_nkw: nkw,
@@ -130,13 +132,13 @@ describe("ebay", {
130132
it("getJson pagination with page + size", {
131133
ignore: !HAS_API_KEY,
132134
}, async (t) => {
133-
const firstPage = await getJson(engine, { _nkw: nkw });
135+
const firstPage = await getJson({ engine, _nkw: nkw });
134136
const linksOnFirstPage = firstPage.organic_results.map((r: any) => r.link);
135137

136138
await t.step("async/await", async () => {
137139
const links: string[] = [];
138140
let page;
139-
page = await getJson(engine, { _nkw: nkw, _pgn: "2", _ipg: "100" });
141+
page = await getJson({ engine, _nkw: nkw, _pgn: "2", _ipg: "100" });
140142
while (page) {
141143
links.push(...page.organic_results.map((r: any) => r.link));
142144
if (links.length >= 200) break;
@@ -152,7 +154,7 @@ describe("ebay", {
152154
await t.step("callback", async () => {
153155
const links: string[] = [];
154156
await new Promise<void>((done) => {
155-
getJson(engine, { _nkw: nkw, _pgn: "2", _ipg: "100" }, (page) => {
157+
getJson({ engine, _nkw: nkw, _pgn: "2", _ipg: "100" }, (page) => {
156158
links.push(...page.organic_results.map((r: any) => r.link));
157159
if (links.length < 200 && page.next) {
158160
page.next();
@@ -175,7 +177,7 @@ describe("ebay", {
175177
await t.step("async/await", async () => {
176178
let page;
177179
let pageNum = 0;
178-
page = await getJson(engine, { _nkw: nkw, _pgn: "7", _ipg: "200" });
180+
page = await getJson({ engine, _nkw: nkw, _pgn: "7", _ipg: "200" });
179181
while (page && pageNum < 5) {
180182
pageNum++;
181183
page = await page.next?.();
@@ -186,7 +188,7 @@ describe("ebay", {
186188
await t.step("callback", async () => {
187189
let pageNum = 0;
188190
await new Promise<void>((done) => {
189-
getJson(engine, { _nkw: nkw, _pgn: "7", _ipg: "200" }, (page) => {
191+
getJson({ engine, _nkw: nkw, _pgn: "7", _ipg: "200" }, (page) => {
190192
pageNum++;
191193
if (pageNum < 5 && page.next) {
192194
page.next();

0 commit comments

Comments
 (0)