Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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
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: Install sdk-e2e-tests dependencies
working-directory: sdk-e2e-tests
run: npm ci

- name: Build sdk-e2e-tests
working-directory: sdk-e2e-tests
run: npm run build

- name: Run E2E tests
working-directory: sdk-e2e-tests
env:
CLI_COMMAND: node ${{ github.workspace }}/sdk/e2e-cli/dist/cli.js
E2E_TEST_SUITES: basic,retry
# E2E_TEST_SKIP: exponential-backoff # skip specific test files if needed
run: npm test

- 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/
54 changes: 54 additions & 0 deletions e2e-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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 }
```

On failure:

```json
{ "success": false, "error": "description" }
```
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',
});
Loading
Loading