Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
coverage/
lib/
e2e/
e2e-cli/
examples/


Expand Down
62 changes: 62 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# E2E Tests for analytics-react-native
# Copy this file to: analytics-react-native/.github/workflows/e2e-tests.yml
#
# This workflow:
# 1. Checks out the SDK and sdk-e2e-tests repos
# 2. Builds the Node-based e2e-cli
# 3. Runs the e2e test suite

name: E2E Tests

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
workflow_dispatch: # Allow manual trigger

jobs:
e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout SDK
uses: actions/checkout@v4
with:
path: sdk

- name: Checkout sdk-e2e-tests
uses: actions/checkout@v4
with:
repository: segmentio/sdk-e2e-tests
# E2E_TESTS_TOKEN is a GitHub Personal Access Token or GitHub App installation token
# with read access to the segmentio/sdk-e2e-tests repository. Store it as a repository
# or organization secret named E2E_TESTS_TOKEN (see project/internal docs for setup).
token: ${{ secrets.E2E_TESTS_TOKEN }}
path: sdk-e2e-tests

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install and build e2e-cli
working-directory: sdk/e2e-cli
run: |
npm install
npm run build

- name: Run E2E tests
working-directory: sdk-e2e-tests
run: |
./scripts/run-tests.sh \
--sdk-dir "${{ github.workspace }}/sdk/e2e-cli" \
--cli "node ${{ github.workspace }}/sdk/e2e-cli/dist/cli.js"

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-test-results
path: sdk-e2e-tests/test-results/
if-no-files-found: ignore
2 changes: 2 additions & 0 deletions e2e-cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
56 changes: 56 additions & 0 deletions e2e-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# analytics-react-native e2e-cli

E2E test CLI for the [@segment/analytics-react-native](https://github.com/segmentio/analytics-react-native) SDK. Runs the **real SDK pipeline** on Node.js — events flow through `SegmentClient` → Timeline → `SegmentDestination` (batch chunking, upload) → `QueueFlushingPlugin` (queue management) → `uploadEvents` HTTP POST.

React Native runtime dependencies (`AppState`, `NativeModules`, sovran native bridge, AsyncStorage) are stubbed with minimal Node.js equivalents so the full event processing pipeline executes without a React Native runtime.

## Setup

```bash
npm install
npm run build
```

The build uses esbuild to bundle the CLI + SDK source + stubs into a single `dist/cli.js`.

## Usage

```bash
node dist/cli.js --input '{"writeKey":"...", ...}'
```

## Input Format

```jsonc
{
"writeKey": "your-write-key", // required
"apiHost": "https://...", // optional — SDK default if omitted
"cdnHost": "https://...", // optional — SDK default if omitted
"sequences": [ // required — event sequences to send
{
"delayMs": 0,
"events": [
{ "type": "track", "event": "Test", "userId": "user-1" }
]
}
],
"config": { // optional
"flushAt": 20,
"flushInterval": 30
}
}
```

## Output Format

```json
{ "success": true, "sentBatches": 0 }
```

On failure:

```json
{ "success": false, "error": "description", "sentBatches": 0 }
```

Note: `sentBatches` is always 0 — the React Native SDK does not expose batch count tracking. The field is present for compatibility with the `sdk-e2e-tests` CLIOutput interface.
35 changes: 35 additions & 0 deletions e2e-cli/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const esbuild = require('esbuild');

const coreDir = path.resolve(__dirname, '../packages/core');
const infoFile = path.join(coreDir, 'src/info.ts');

// Generate info.ts if it doesn't exist (required by context.ts)
if (!fs.existsSync(infoFile)) {
console.log('Generating packages/core/src/info.ts...');
execSync('node constants-generator.js', { cwd: coreDir, stdio: 'inherit' });
}

esbuild.buildSync({
entryPoints: [path.resolve(__dirname, 'src/cli.ts')],
bundle: true,
platform: 'node',
target: 'node18',
format: 'cjs',
outfile: path.resolve(__dirname, 'dist/cli.js'),
alias: {
'react-native': path.resolve(__dirname, 'src/stubs/react-native.ts'),
'@segment/sovran-react-native': path.resolve(
__dirname,
'src/stubs/sovran.ts'
),
'react-native-get-random-values': path.resolve(
__dirname,
'src/stubs/react-native-get-random-values.ts'
),
},
external: ['uuid', 'deepmerge', '@react-native-async-storage/async-storage'],
logLevel: 'info',
});
7 changes: 7 additions & 0 deletions e2e-cli/e2e-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": "react-native",
"test_suites": "basic",
"auto_settings": false,
"patch": null,
"env": {}
}
Loading