Skip to content

Commit 308f654

Browse files
feat: add SDK tests and CI workflow
30 tests covering all scrapegraphai.ts functions — mocked fetch, polling, HTTP error mapping, validation, timeouts. GitHub Actions runs tests + lint on PRs to main. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 85a80b8 commit 308f654

5 files changed

Lines changed: 441 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: oven-sh/setup-bun@v2
16+
- run: bun install
17+
- run: bun test
18+
19+
lint:
20+
name: Lint & Typecheck
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- uses: oven-sh/setup-bun@v2
25+
- run: bun install
26+
- run: bun run check

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Command-line interface for [ScrapeGraph AI](https://scrapegraphai.com) — AI-po
1717
| Validation | **zod** v4 |
1818
| Env | **dotenv** |
1919
| Lint / Format | **Biome** |
20+
| Testing | **Bun test** (built-in) |
2021
| Target | **Node.js 22+**, ESM-only |
2122

2223
## Setup
@@ -193,6 +194,16 @@ scrapegraphai credits
193194
scrapegraphai validate
194195
```
195196

197+
## Testing
198+
199+
Tests use Bun's built-in test runner with `spyOn(globalThis, "fetch")` to mock all API calls — no network requests, no API key needed.
200+
201+
```bash
202+
bun test
203+
```
204+
205+
Covers all SDK functions: success paths, polling, HTTP error mapping (401/402/422/429/500), Zod validation, timeouts, and network failures.
206+
196207
## Project Structure
197208

198209
```
@@ -220,6 +231,8 @@ scrapegraph-cli/
220231
│ │ └── validate.ts
221232
│ └── utils/
222233
│ └── banner.ts # ASCII banner + version from package.json
234+
├── tests/
235+
│ └── scrapegraphai.test.ts # SDK layer tests (mocked fetch)
223236
├── dist/ # Build output (git-ignored)
224237
│ └── cli.mjs # Bundled ESM with shebang
225238
├── package.json

biome.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
"recommended": true
1515
}
1616
},
17+
"overrides": [
18+
{
19+
"include": ["tests/**"],
20+
"linter": {
21+
"rules": {
22+
"suspicious": {
23+
"noExplicitAny": "off"
24+
}
25+
}
26+
}
27+
}
28+
],
1729
"files": {
1830
"ignore": ["node_modules", "dist", "bun.lock"]
1931
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@biomejs/biome": "^1.9.4",
35+
"@types/bun": "^1.3.9",
3536
"@types/node": "^22.13.1",
3637
"tsup": "^8.3.6",
3738
"typescript": "^5.8.2"

0 commit comments

Comments
 (0)