Skip to content

Commit c2db13f

Browse files
committed
Move smoke tests + format
1 parent 2264583 commit c2db13f

9 files changed

Lines changed: 50 additions & 35 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
env:
7575
SERPAPI_TEST_KEY: ${{ secrets.SERPAPI_TEST_KEY }}
7676
run: |
77-
cd tests/smoke/commonjs
77+
cd smoke_tests/commonjs
7878
npm i
7979
npm test
8080
@@ -107,6 +107,6 @@ jobs:
107107
env:
108108
SERPAPI_TEST_KEY: ${{ secrets.SERPAPI_TEST_KEY }}
109109
run: |
110-
cd tests/smoke/esm
110+
cd smoke_tests/esm
111111
npm i
112112
npm test

deno.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
},
1010
"fmt": {
1111
"files": {
12-
"exclude": ["npm/", "examples/node", "tests/smoke/"]
12+
"exclude": ["npm/", "examples/node", "smoke_tests/"]
1313
}
1414
},
1515
"lint": {
1616
"files": {
17-
"exclude": ["npm/", "examples/node", "tests/smoke/"]
17+
"exclude": ["npm/", "examples/node", "smoke_tests/"]
1818
}
1919
},
2020
"test": {
2121
"files": {
22-
"include": ["tests/"],
23-
"exclude": ["tests/smoke/"]
22+
"include": ["tests/"]
2423
}
2524
},
2625
"compilerOptions": {
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@
33
*/
44

55
const Dotenv = require("dotenv");
6-
const { config, getJson, getHtml, getJsonBySearchId, getHtmlBySearchId, getAccount, getLocations } = require("serpapi");
6+
const {
7+
config,
8+
getJson,
9+
getHtml,
10+
getJsonBySearchId,
11+
getHtmlBySearchId,
12+
getAccount,
13+
getLocations,
14+
} = require("serpapi");
715

816
Dotenv.config();
917
const apiKey = process.env.SERPAPI_TEST_KEY;
1018

1119
const run = async () => {
1220
console.log("running", process.versions.node);
13-
21+
1422
const params = {
1523
q: "Coffee",
1624
api_key: apiKey,
1725
};
1826

1927
let searchId;
20-
28+
2129
{
2230
console.log("getJson async await");
2331
const page1 = await getJson("google", params);
@@ -57,18 +65,18 @@ const run = async () => {
5765
const links = [];
5866
let page = await getJson("google", params);
5967
while (page) {
60-
links.push(...page.organic_results.map(r => r.link));
68+
links.push(...page.organic_results.map((r) => r.link));
6169
if (links.length >= 30) break;
62-
page = page.next ? await page.next(): undefined;
70+
page = page.next ? await page.next() : undefined;
6371
}
6472
if (links.length < 30) throw new Error("Incorrect number of links");
6573
}
66-
74+
6775
{
6876
console.log("getJson pagination loop (callback)");
6977
const links = [];
7078
getJson("google", params, (page) => {
71-
links.push(...page.organic_results.map(r => r.link));
79+
links.push(...page.organic_results.map((r) => r.link));
7280
if (links.length < 30 && page.next) {
7381
page.next();
7482
} else {
@@ -81,8 +89,8 @@ const run = async () => {
8189
console.log("getHtml");
8290
const html = await getHtml("google", params);
8391
if (html.length < 1000) throw new Error("Incorrect HTML");
84-
85-
getHtml("google", params, html => {
92+
93+
getHtml("google", params, (html) => {
8694
if (html.length < 1000) throw new Error("Incorrect HTML");
8795
});
8896
}
@@ -124,7 +132,7 @@ const run = async () => {
124132
console.log("getLocations");
125133
const locations = await getLocations({ limit: 3 });
126134
if (locations.length !== 3) throw new Error("Incorrect locations length");
127-
135+
128136
getLocations({ limit: 3 }, (locations) => {
129137
if (locations.length !== 3) throw new Error("Incorrect locations length");
130138
});
@@ -136,4 +144,4 @@ const run = async () => {
136144
run().catch((e) => {
137145
console.error(e);
138146
process.exitCode = 1;
139-
});
147+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"dotenv": "*",
4-
"serpapi": "../../../npm"
4+
"serpapi": "../../npm"
55
},
66
"scripts": {
77
"test": "node commonjs.js"
Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
*/
88

99
import Dotenv from "dotenv";
10-
import { config, getJson, getHtml, getJsonBySearchId, getHtmlBySearchId, getAccount, getLocations } from "serpapi";
10+
import {
11+
config,
12+
getAccount,
13+
getHtml,
14+
getHtmlBySearchId,
15+
getJson,
16+
getJsonBySearchId,
17+
getLocations,
18+
} from "serpapi";
1119

1220
Dotenv.config();
1321
const apiKey = process.env.SERPAPI_TEST_KEY;
@@ -22,7 +30,7 @@ const params = {
2230
let searchId;
2331

2432
{
25-
console.log("getJson async await")
33+
console.log("getJson async await");
2634
const page1 = await getJson("google", params);
2735
searchId = page1["search_metadata"]["id"];
2836
if (!page1["organic_results"]) throw new Error("No organic results");
@@ -31,7 +39,7 @@ let searchId;
3139
}
3240

3341
{
34-
console.log("getJson callback")
42+
console.log("getJson callback");
3543
getJson("google", params, (page1) => {
3644
if (!page1["organic_results"]) throw new Error("No organic results");
3745
page1.next?.((page2) => {
@@ -41,7 +49,7 @@ let searchId;
4149
}
4250

4351
{
44-
console.log("getJson using global config")
52+
console.log("getJson using global config");
4553
config.api_key = apiKey;
4654
const page1 = await getJson("google", { q: "Coffee" });
4755
if (!page1["organic_results"]) throw new Error("No organic results");
@@ -50,22 +58,22 @@ let searchId;
5058
}
5159

5260
{
53-
console.log("getJson pagination loop (async/await)")
61+
console.log("getJson pagination loop (async/await)");
5462
const links = [];
5563
let page = await getJson("google", params);
5664
while (page) {
57-
links.push(...page.organic_results.map(r => r.link));
65+
links.push(...page.organic_results.map((r) => r.link));
5866
if (links.length >= 30) break;
5967
page = await page.next?.();
6068
}
6169
if (links.length < 30) throw new Error("Incorrect number of links");
6270
}
6371

6472
{
65-
console.log("getJson pagination loop (callback)")
73+
console.log("getJson pagination loop (callback)");
6674
const links = [];
6775
getJson("google", params, (page) => {
68-
links.push(...page.organic_results.map(r => r.link));
76+
links.push(...page.organic_results.map((r) => r.link));
6977
if (links.length < 30 && page.next) {
7078
page.next();
7179
} else {
@@ -75,17 +83,17 @@ let searchId;
7583
}
7684

7785
{
78-
console.log("getHtml")
86+
console.log("getHtml");
7987
const html = await getHtml("google", params);
8088
if (html.length < 1000) throw new Error("Incorrect HTML");
81-
82-
getHtml("google", params, html => {
89+
90+
getHtml("google", params, (html) => {
8391
if (html.length < 1000) throw new Error("Incorrect HTML");
8492
});
8593
}
8694

8795
{
88-
console.log("getJsonBySearchId")
96+
console.log("getJsonBySearchId");
8997
config.api_key = apiKey;
9098
const json = await getJsonBySearchId(searchId);
9199
if (!json["organic_results"]) throw new Error("No organic results");
@@ -96,7 +104,7 @@ let searchId;
96104
}
97105

98106
{
99-
console.log("getHtmlBySearchId")
107+
console.log("getHtmlBySearchId");
100108
config.api_key = apiKey;
101109
const html = await getHtmlBySearchId(searchId);
102110
if (html.length < 1000) throw new Error("Incorrect HTML");
@@ -107,7 +115,7 @@ let searchId;
107115
}
108116

109117
{
110-
console.log("getAccount")
118+
console.log("getAccount");
111119
config.api_key = apiKey;
112120
const info = await getAccount();
113121
if (!info["account_email"]) throw new Error("Incorrect account info");
@@ -118,10 +126,10 @@ let searchId;
118126
}
119127

120128
{
121-
console.log("getLocations")
129+
console.log("getLocations");
122130
const locations = await getLocations({ limit: 3 });
123131
if (locations.length !== 3) throw new Error("Incorrect locations length");
124-
132+
125133
getLocations({ limit: 3 }, (locations) => {
126134
if (locations.length !== 3) throw new Error("Incorrect locations length");
127135
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "module",
33
"dependencies": {
44
"dotenv": "*",
5-
"serpapi": "../../../npm"
5+
"serpapi": "../../npm"
66
},
77
"scripts": {
88
"test": "node esm.js"

0 commit comments

Comments
 (0)