diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4e71dc6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,20 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm check + - run: pnpm test -- --run diff --git a/biome.json b/biome.json index 3298bd7..a606d76 100644 --- a/biome.json +++ b/biome.json @@ -8,7 +8,7 @@ "indentStyle": "space", "indentWidth": 2, "lineEnding": "lf", - "lineWidth": 80, + "lineWidth": 100, "attributePosition": "auto" }, "linter": { diff --git a/examples/index.js b/examples/index.js index 9e7ee1d..f6b91ef 100644 --- a/examples/index.js +++ b/examples/index.js @@ -36,8 +36,7 @@ const testPost = "https://httpbin.org/anything"; try { const response = await client.get(urlPremium, { // autoparse: true, - css_extractor: - '{"aproximate_results": "#result-stats", "headers": "#search a > h3"}', + css_extractor: '{"aproximate_results": "#result-stats", "headers": "#search a > h3"}', // js_render: true, premium_proxy: true, proxy_country: "us", diff --git a/examples/index.ts b/examples/index.ts index 82110be..30ec22b 100644 --- a/examples/index.ts +++ b/examples/index.ts @@ -54,11 +54,7 @@ const testPost = "https://httpbin.org/anything"; } try { - const urls = [ - "https://httpbin.org/ip", - "https://httpbin.org/anything", - "https://ident.me", - ]; + const urls = ["https://httpbin.org/ip", "https://httpbin.org/anything", "https://ident.me"]; const promises = urls.map((url) => client.get(url)); @@ -67,8 +63,7 @@ const testPost = "https://httpbin.org/anything"; (item): item is PromiseRejectedResult => item.status === "rejected", ); const fulfilled = results.filter( - (item): item is PromiseFulfilledResult => - item.status === "fulfilled", + (item): item is PromiseFulfilledResult => item.status === "fulfilled", ); console.log(rejected); diff --git a/package.json b/package.json index 9e0b6fb..c49ccf8 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ }, "scripts": { "build": "tsup src/index.ts --dts --format cjs,esm --clean", - "test": "vitest" + "test": "vitest", + "format": "biome format --write .", + "check": "biome check ." }, "keywords": ["sdk", "zenrows", "scraping"], "author": "ZenRows", diff --git a/src/index.ts b/src/index.ts index 80fe8f1..b19ba4c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,7 +69,7 @@ export class ZenRows { public get( url: string, config?: ZenRowsConfig, - { headers = {} }: { headers?: Headers } = {} + { headers = {} }: { headers?: Headers } = {}, ): Promise { return this.queue.push({ url, config, headers }); } @@ -79,7 +79,7 @@ export class ZenRows { config?: ZenRowsConfig, { headers = {}, data = {} }: { headers?: Headers; data?: unknown } = { headers: { "Content-Type": "application/x-www-form-urlencoded" }, - } + }, ): Promise { const normalizedHeaders = Object.keys(headers).reduce( (acc: { [key: string]: string }, key: string) => { @@ -93,7 +93,7 @@ export class ZenRows { } return acc; }, - {} + {}, ); return this.queue.push({ diff --git a/tests/_setup.ts b/tests/_setup.ts index 0a2e761..2c563dc 100644 --- a/tests/_setup.ts +++ b/tests/_setup.ts @@ -1,29 +1,29 @@ -import { beforeAll, afterAll, afterEach } from "vitest"; -import { setupServer } from "msw/node"; import { http, HttpResponse } from "msw"; +import { setupServer } from "msw/node"; +import { afterAll, afterEach, beforeAll } from "vitest"; const handlers = [ - http.get("https://api.zenrows.com/v1/", () => { - return HttpResponse.json({ - firstName: "John", - lastName: "Maverick", - }); - }), - http.post("https://api.zenrows.com/v1/", () => { - return new HttpResponse(); - }), + http.get("https://api.zenrows.com/v1/", () => { + return HttpResponse.json({ + firstName: "John", + lastName: "Maverick", + }); + }), + http.post("https://api.zenrows.com/v1/", () => { + return new HttpResponse(); + }), ]; export const server = setupServer(...handlers); beforeAll(() => { - server.listen(); + server.listen(); }); afterEach(() => { - server.resetHandlers(); + server.resetHandlers(); }); afterAll(() => { - server.close(); + server.close(); }); diff --git a/tests/concurrency.test.ts b/tests/concurrency.test.ts index fe86b7b..eb44af3 100644 --- a/tests/concurrency.test.ts +++ b/tests/concurrency.test.ts @@ -1,4 +1,4 @@ -import { describe, test, expect, beforeEach } from "vitest"; //TODO(Nestor): Try to use globals instead of importing +import { beforeEach, describe, expect, test } from "vitest"; //TODO(Nestor): Try to use globals instead of importing import { ZenRows } from "../src"; describe("ZenRows Client with Concurrency", () => { diff --git a/tests/index.test.ts b/tests/index.test.ts index f40657c..f390e67 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,8 +1,8 @@ -import { describe, test, expect, vi, beforeEach, type Mock } from "vitest"; //TODO(Nestor): Try to use globals instead of importing -import { ZenRows } from "../src"; +import { http } from "msw"; +import { type Mock, beforeEach, describe, expect, test, vi } from "vitest"; //TODO(Nestor): Try to use globals instead of importing import packageJson from "../package.json" assert { type: "json" }; +import { ZenRows } from "../src"; import { server } from "./_setup"; -import { http } from "msw"; describe("ZenRows Client Get", () => { const apiKey = "API_KEY"; @@ -50,9 +50,7 @@ describe("ZenRows Client Get", () => { const parsedUrl = new URL(requestUrl); for (const key in optionalParams) { - expect(parsedUrl.searchParams.get(key)).toBe( - optionalParams[key].toString(), - ); + expect(parsedUrl.searchParams.get(key)).toBe(optionalParams[key].toString()); } }); @@ -98,7 +96,7 @@ describe("ZenRows Client Get", () => { headers: expect.objectContaining({ "Content-Type": "application/x-www-form-urlencoded", }), - body: `"${data}"`, + body: data, }), ); }); diff --git a/tests/retries.test.ts b/tests/retries.test.ts index 31d3e14..0f3782d 100644 --- a/tests/retries.test.ts +++ b/tests/retries.test.ts @@ -1,7 +1,7 @@ -import { vi, describe, test, expect, beforeEach, type Mock } from "vitest"; //TODO(Nestor): Try to use globals instead of importing +import { http, HttpResponse } from "msw"; +import { type Mock, beforeEach, describe, expect, test, vi } from "vitest"; //TODO(Nestor): Try to use globals instead of importing import { ZenRows } from "../src"; import { server } from "./_setup"; -import { HttpResponse, http } from "msw"; describe("ZenRows Client with Retries", () => { const apiKey = "API_KEY"; diff --git a/tests/retry-count.test.ts b/tests/retry-count.test.ts index e48088b..61fc964 100644 --- a/tests/retry-count.test.ts +++ b/tests/retry-count.test.ts @@ -1,7 +1,7 @@ -import { describe, test, expect } from "vitest"; +import { http, HttpResponse } from "msw"; +import { describe, expect, test } from "vitest"; import { ZenRows } from "../src"; import { server } from "./_setup"; -import { HttpResponse, http } from "msw"; describe("retryOn off-by-one fix", () => { test.each([ @@ -17,7 +17,7 @@ describe("retryOn off-by-one fix", () => { http.get("https://api.zenrows.com/v1/", () => { fetchCount++; return new HttpResponse("Could Not Get Content", { status: 422 }); - }) + }), ); const client = new ZenRows("API_KEY", { retries }); @@ -25,6 +25,6 @@ describe("retryOn off-by-one fix", () => { expect(response.status).toBe(422); expect(fetchCount).toBe(expectedCalls); - } + }, ); });