Skip to content

Commit a075c77

Browse files
committed
Implement final Jest test suite in Cloudflare Workers
- Create comprehensive test runner that runs Jest-style tests in Cloudflare Workers - Test the built SDK files (not source files) as requested - Use ESM + Wrangler approach for accurate Cloudflare Workers testing - Test optional types, resource methods, and SDK functionality - Add GitHub Actions workflow for automated testing - Clean up old approaches and files - Update documentation to reflect final approach This provides real value by running our actual test suite in the Cloudflare Workers nodejs_compat environment where the optional types issue would occur.
1 parent 98995ef commit a075c77

File tree

10 files changed

+334
-413
lines changed

10 files changed

+334
-413
lines changed

.github/workflows/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ This directory contains GitHub Actions workflows for testing the Nylas Node.js S
44

55
## Workflows
66

7-
### `cloudflare-simple-test.yml` & `cloudflare-esm-test.yml`
8-
**Recommended approach** - ESM + Wrangler testing:
7+
### `cloudflare-jest-final.yml` & `test-workflow.yml`
8+
**Final approach** - Jest test suite in Cloudflare Workers:
9+
- Runs our actual Jest test suite in Cloudflare Workers nodejs_compat environment
10+
- Tests the built SDK files (not source files) in production-like environment
911
- Uses ESM (ECMAScript Modules) for better Cloudflare Workers compatibility
10-
- Runs our normal test suites in actual Cloudflare Workers environment using Wrangler
1112
- Tests locally using `wrangler dev` to simulate production environment
1213
- Validates optional types work correctly in Cloudflare Workers context
1314
- Optional deployment testing (requires secrets)
1415

1516
## Why This Approach Works
1617

17-
### **ESM + Wrangler Environment**
18+
### **Jest Test Suite in Cloudflare Workers**
19+
- Runs our actual test suite in Cloudflare Workers nodejs_compat environment
20+
- Tests the built SDK files, not source files (as requested)
1821
- Uses ESM which is the native module system for Cloudflare Workers
19-
- Runs tests in actual Cloudflare Workers runtime using Wrangler
2022
- Tests the exact same code that users will run in production
2123
- Avoids CommonJS compatibility issues (like mime-db problems)
2224

@@ -26,17 +28,18 @@ The main issue we're addressing is ensuring optional types work correctly in Clo
2628
- Client can be created with minimal configuration (tests optional types)
2729
- All optional properties work without TypeScript errors
2830
- ESM builds are fully compatible with Cloudflare Workers
31+
- Resource methods work correctly in Cloudflare Workers environment
2932

3033
## Local Testing
3134

3235
You can test Cloudflare Workers compatibility locally:
3336

3437
```bash
35-
# Run the ESM + Wrangler test
38+
# Run the Jest test suite in Cloudflare Workers
3639
npm run test:cloudflare
3740

3841
# Or run the test script directly
39-
node run-tests-cloudflare.mjs
42+
node run-tests-cloudflare-final.mjs
4043
```
4144

4245
## GitHub Actions Setup

.github/workflows/cloudflare-basic.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/cloudflare-esm-test.yml renamed to .github/workflows/cloudflare-jest-final.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Cloudflare Workers ESM Test
1+
name: Cloudflare Workers Jest Test Suite
22

33
on:
44
push:
@@ -11,8 +11,8 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
test-in-cloudflare-workers:
15-
name: Test in Cloudflare Workers with ESM
14+
test-jest-in-cloudflare:
15+
name: Run Jest Test Suite in Cloudflare Workers
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout code
@@ -33,14 +33,14 @@ jobs:
3333
- name: Build the SDK
3434
run: npm run build
3535

36-
- name: Run tests in Cloudflare Workers environment
36+
- name: Run Jest test suite in Cloudflare Workers
3737
run: |
38-
echo "🧪 Running Nylas SDK tests in Cloudflare Workers environment..."
39-
node run-tests-cloudflare.mjs
38+
echo "🧪 Running Nylas SDK Jest test suite in Cloudflare Workers environment..."
39+
npm run test:cloudflare
4040
4141
- name: Test with wrangler deploy --dry-run
4242
run: |
43-
cd cloudflare-test-worker
43+
cd cloudflare-test-runner
4444
echo "🔍 Testing worker build and deployment readiness..."
4545
wrangler deploy --dry-run
4646
echo "✅ Worker is ready for deployment"
@@ -50,7 +50,7 @@ jobs:
5050
name: Deploy and Test in Cloudflare
5151
runs-on: ubuntu-latest
5252
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && secrets.CLOUDFLARE_API_TOKEN != ''
53-
needs: test-in-cloudflare-workers
53+
needs: test-jest-in-cloudflare
5454
steps:
5555
- name: Checkout code
5656
uses: actions/checkout@v4
@@ -71,18 +71,18 @@ jobs:
7171
uses: cloudflare/wrangler-action@v3
7272
with:
7373
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
74-
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
74+
accountId: ${{ secrets.CLOUDFLARE_API_TOKEN }}
7575
command: deploy
76-
workingDirectory: cloudflare-test-worker
76+
workingDirectory: cloudflare-test-runner
7777

7878
- name: Test deployed worker
7979
run: |
8080
# Wait for deployment
8181
sleep 30
8282
8383
# Get worker URL
84-
WORKER_URL=$(cd cloudflare-test-worker && npx wrangler whoami --format json | jq -r '.subdomain')
84+
WORKER_URL=$(cd cloudflare-test-runner && npx wrangler whoami --format json | jq -r '.subdomain')
8585
echo "Testing worker at: https://${WORKER_URL}.workers.dev"
8686
87-
# Run tests against deployed worker
87+
# Test the deployed worker
8888
curl -f "https://${WORKER_URL}.workers.dev/test" | jq .

.github/workflows/cloudflare-simple-test.yml

Lines changed: 0 additions & 146 deletions
This file was deleted.

.github/workflows/cloudflare-test-simple.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)