Skip to content

Commit d8e922d

Browse files
authored
add cloudflare worker tests for analytics-node (#967)
1 parent e01fb23 commit d8e922d

File tree

13 files changed

+1254
-24
lines changed

13 files changed

+1254
-24
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ env:
66
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
77
jobs:
88
analytics-node:
9-
name: "analytics-node QA (Node.js v${{ matrix.node-version }})"
9+
name: 'analytics-node QA (Node.js v${{ matrix.node-version }})'
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
node-version: [ 14, 16, 18 ]
13+
node-version: [14, 16, 18]
1414
steps:
1515
- uses: actions/checkout@v3
1616
- uses: actions/setup-node@v3
1717
with:
1818
node-version: ${{ matrix.node-version }}
19-
cache: "yarn"
19+
cache: 'yarn'
2020
- run: yarn install --immutable
2121
- name: Turbo cache
2222
uses: actions/cache@v3
@@ -27,6 +27,28 @@ jobs:
2727
${{ runner.os }}-turbo-
2828
- run: yarn turbo run --filter='./packages/node*' lint
2929
- run: yarn turbo run --filter='./packages/node*' test
30+
- run: yarn turbo run --filter='./packages/node-integration-tests' test:perf-and-durability
31+
analytics-node-cf-workers:
32+
name: 'analytics-node QA (Cloudflare Workers)'
33+
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
node-version: [18]
37+
steps:
38+
- uses: actions/checkout@v3
39+
- uses: actions/setup-node@v3
40+
with:
41+
node-version: ${{ matrix.node-version }}
42+
cache: 'yarn'
43+
- run: yarn install --immutable
44+
- name: Turbo cache
45+
uses: actions/cache@v3
46+
with:
47+
path: node_modules/.cache/turbo
48+
key: ${{ runner.os }}-turbo-${{ github.sha }}
49+
restore-keys: |
50+
${{ runner.os }}-turbo-
51+
- run: yarn turbo run --filter='./packages/node-integration-tests' test:cloudflare-workers
3052
consent-intg-tests:
3153
name: Consent Integration Tests
3254
runs-on: ubuntu-latest
@@ -37,7 +59,7 @@ jobs:
3759
- uses: actions/setup-node@v3
3860
with:
3961
node-version: 16
40-
cache: "yarn"
62+
cache: 'yarn'
4163
- run: yarn install --immutable
4264
- name: Turbo cache
4365
uses: actions/cache@v3
@@ -47,6 +69,3 @@ jobs:
4769
restore-keys: |
4870
${{ runner.os }}-turbo-
4971
- run: yarn turbo run --filter='consent-tools-integration-tests' test:int
50-
51-
52-
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Integration Tests for @segment/analytics-node
22

33
## Tests
4-
| Test Path | Description |
5-
| ---- | ----------- |
6-
| [./src/durability-tests](src/durability-tests/) | Test that all the events created by the Analytics SDK end up as HTTP Requests, and that graceful shutdown does not result in events getting lost. |
7-
| [./src/perf-tests](src/perf-tests/) | These tests confirm that performance has not regresssed relative to the old SDK or from the baseline (which a handler _without_ analytics).
4+
5+
| Test Path | Description |
6+
| ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
7+
| [./src/durability-tests](src/durability-tests/) | Test that all the events created by the Analytics SDK end up as HTTP Requests, and that graceful shutdown does not result in events getting lost. |
8+
| [./src/perf-tests](src/perf-tests/) | These tests confirm that performance has not regresssed relative to the old SDK or from the baseline (which a handler _without_ analytics). |
9+
| [./src/cloudflare-tests/](src/cloudflare-tests/) | These tests confirm that the SDK runs as expected in cloudflare workers. |
810

911
Build deps and run tests:
12+
1013
```sh
1114
yarn turbo run --filter=node-integration-tests test # from repo root
1215
```
13-
14-
15-
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { createJestTSConfig } = require('@internal/config')
2+
3+
module.exports = createJestTSConfig(__dirname)

packages/node-integration-tests/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
"durability": "yarn ts-node src/durability-tests/durability-tests.ts",
1111
"concurrently": "yarn run -T concurrently",
1212
"ts-node": "yarn run -T ts-node",
13-
"test": "yarn perf && yarn durability"
13+
"test:perf-and-durability": "yarn perf && yarn durability",
14+
"test:cloudflare-workers": "yarn run -T jest src/cloudflare-tests"
1415
},
1516
"devDependencies": {
17+
"@cloudflare/workers-types": "^4.20231002.0",
18+
"@internal/config": "workspace:^",
1619
"@internal/test-helpers": "workspace:^",
1720
"@segment/analytics-node": "workspace:^",
1821
"@types/analytics-node": "^3.1.9",
1922
"@types/autocannon": "^7",
2023
"@types/node": "^16",
2124
"analytics-node": "^6.2.0",
22-
"autocannon": "^7.10.0"
25+
"autocannon": "^7.10.0",
26+
"wrangler": "^3.11.0"
2327
},
2428
"packageManager": "yarn@3.4.1"
2529
}

0 commit comments

Comments
 (0)