Skip to content

Commit 545da21

Browse files
committed
Add smoke test for new API
1 parent fd71ea2 commit 545da21

3 files changed

Lines changed: 89 additions & 12 deletions

File tree

smoke_tests/commonjs/commonjs.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const run = async () => {
2828

2929
{
3030
console.log("getJson async await");
31-
const page1 = await getJson("google", params);
31+
const page1 = await getJson({ engine: "google", ...params });
3232
searchId = page1["search_metadata"]["id"];
3333
if (!page1["organic_results"]) throw new Error("No organic results");
3434
if (page1.next) {
@@ -39,7 +39,7 @@ const run = async () => {
3939

4040
{
4141
console.log("getJson callback");
42-
getJson("google", params, (page1) => {
42+
getJson({ engine: "google", ...params }, (page1) => {
4343
if (!page1["organic_results"]) throw new Error("No organic results");
4444
if (page1.next) {
4545
page1.next((page2) => {
@@ -52,6 +52,40 @@ const run = async () => {
5252
{
5353
console.log("getJson using global config");
5454
config.api_key = apiKey;
55+
const page1 = await getJson({ engine: "google", q: "Coffee" });
56+
if (!page1["organic_results"]) throw new Error("No organic results");
57+
if (page1.next) {
58+
const page2 = await page1.next();
59+
if (!page2["organic_results"]) throw new Error("No organic results");
60+
}
61+
}
62+
63+
{
64+
console.log("getJson (old API) async await");
65+
const page1 = await getJson("google", params);
66+
searchId = page1["search_metadata"]["id"];
67+
if (!page1["organic_results"]) throw new Error("No organic results");
68+
if (page1.next) {
69+
const page2 = await page1.next();
70+
if (!page2["organic_results"]) throw new Error("No organic results");
71+
}
72+
}
73+
74+
{
75+
console.log("getJson (old API) callback");
76+
getJson("google", params, (page1) => {
77+
if (!page1["organic_results"]) throw new Error("No organic results");
78+
if (page1.next) {
79+
page1.next((page2) => {
80+
if (!page2["organic_results"]) throw new Error("No organic results");
81+
});
82+
}
83+
});
84+
}
85+
86+
{
87+
console.log("getJson (old API) using global config");
88+
config.api_key = apiKey;
5589
const page1 = await getJson("google", { q: "Coffee" });
5690
if (!page1["organic_results"]) throw new Error("No organic results");
5791
if (page1.next) {
@@ -87,6 +121,16 @@ const run = async () => {
87121

88122
{
89123
console.log("getHtml");
124+
const html = await getHtml({ engine: "google", ...params });
125+
if (html.length < 1000) throw new Error("Incorrect HTML");
126+
127+
getHtml({ engine: "google", ...params }, (html) => {
128+
if (html.length < 1000) throw new Error("Incorrect HTML");
129+
});
130+
}
131+
132+
{
133+
console.log("getHtml (old API)");
90134
const html = await getHtml("google", params);
91135
if (html.length < 1000) throw new Error("Incorrect HTML");
92136

smoke_tests/esm/esm.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let searchId;
3131

3232
{
3333
console.log("getJson async await");
34-
const page1 = await getJson("google", params);
34+
const page1 = await getJson({ engine: "google", ...params });
3535
searchId = page1["search_metadata"]["id"];
3636
if (!page1["organic_results"]) throw new Error("No organic results");
3737
const page2 = await page1.next?.();
@@ -40,7 +40,7 @@ let searchId;
4040

4141
{
4242
console.log("getJson callback");
43-
getJson("google", params, (page1) => {
43+
getJson({ engine: "google", ...params }, (page1) => {
4444
if (!page1["organic_results"]) throw new Error("No organic results");
4545
page1.next?.((page2) => {
4646
if (!page2["organic_results"]) throw new Error("No organic results");
@@ -51,6 +51,34 @@ let searchId;
5151
{
5252
console.log("getJson using global config");
5353
config.api_key = apiKey;
54+
const page1 = await getJson({ engine: "google", q: "Coffee" });
55+
if (!page1["organic_results"]) throw new Error("No organic results");
56+
const page2 = await page1.next?.();
57+
if (!page2["organic_results"]) throw new Error("No organic results");
58+
}
59+
60+
{
61+
console.log("getJson (old API) async await");
62+
const page1 = await getJson("google", params);
63+
searchId = page1["search_metadata"]["id"];
64+
if (!page1["organic_results"]) throw new Error("No organic results");
65+
const page2 = await page1.next?.();
66+
if (!page2["organic_results"]) throw new Error("No organic results");
67+
}
68+
69+
{
70+
console.log("getJson (old API) callback");
71+
getJson("google", params, (page1) => {
72+
if (!page1["organic_results"]) throw new Error("No organic results");
73+
page1.next?.((page2) => {
74+
if (!page2["organic_results"]) throw new Error("No organic results");
75+
});
76+
});
77+
}
78+
79+
{
80+
console.log("getJson (old API) using global config");
81+
config.api_key = apiKey;
5482
const page1 = await getJson("google", { q: "Coffee" });
5583
if (!page1["organic_results"]) throw new Error("No organic results");
5684
const page2 = await page1.next?.();
@@ -84,6 +112,16 @@ let searchId;
84112

85113
{
86114
console.log("getHtml");
115+
const html = await getHtml({ engine: "google", ...params });
116+
if (html.length < 1000) throw new Error("Incorrect HTML");
117+
118+
getHtml({ engine: "google", ...params }, (html) => {
119+
if (html.length < 1000) throw new Error("Incorrect HTML");
120+
});
121+
}
122+
123+
{
124+
console.log("getHtml (old API)");
87125
const html = await getHtml("google", params);
88126
if (html.length < 1000) throw new Error("Incorrect HTML");
89127

tests/engines/google_test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ describe("google", {
9292
config.api_key = "test_initial_api_key";
9393
try {
9494
await getJson({ engine, api_key: "test_override_api_key", q: "coffee" });
95+
} catch {
96+
// pass
9597
} finally {
9698
executeSpy.restore();
9799
}
@@ -185,16 +187,9 @@ describe("google", {
185187
const executeSpy = spy(_internals, "execute");
186188
config.api_key = "test_initial_api_key";
187189
try {
188-
// HEAD
189-
await getHtml(engine, {
190-
api_key: "test_override_api_key",
191-
q: "coffee",
192-
});
190+
await getHtml({ engine, api_key: "test_override_api_key", q: "coffee" });
193191
} catch {
194192
// pass
195-
//
196-
await getHtml({ engine, api_key: "test_override_api_key", q: "coffee" });
197-
//master
198193
} finally {
199194
executeSpy.restore();
200195
}

0 commit comments

Comments
 (0)