-
Notifications
You must be signed in to change notification settings - Fork 201
E2e cli for cross-sdk tests #1122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MichaelGHSeg
wants to merge
19
commits into
master
Choose a base branch
from
e2e-cli-work
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a23de9e
Add e2e-cli and e2e-tests workflow
MichaelGHSeg d9a5cb3
Add .gitignore for e2e-cli build artifacts
MichaelGHSeg e91a1cd
Separate cdnHost from apiHost in e2e-cli, add README
MichaelGHSeg dffb3eb
Rewrite e2e-cli to run real SDK pipeline with Node.js stubs
MichaelGHSeg e5104ec
Add E2E_TESTS_TOKEN for private sdk-e2e-tests repo checkout
MichaelGHSeg d4b7d44
Add e2e-config.json and run-e2e.sh for local E2E testing
MichaelGHSeg 13235e6
Update CI workflow to use run-tests.sh from sdk-e2e-tests
MichaelGHSeg 042be47
Add e2e-cli/ to .eslintignore
MichaelGHSeg 8388897
Fix e2e-cli review comments: types, field mapping, sovran stub
MichaelGHSeg b168637
Map page events to screen in e2e-cli for consistency
MichaelGHSeg 12d6a76
Remove CLI-side validation, let SDK handle invalid input
MichaelGHSeg 4ed8656
Validate and warn on invalid events, skip instead of crashing
MichaelGHSeg ebacabf
Comment to clarify build process
MichaelGHSeg 348f5f6
Use the cdnHost parameter
MichaelGHSeg 263e722
handle incorrect E2E_DIR
MichaelGHSeg 0e67631
Improving error handling
MichaelGHSeg a12dca1
Clarify token requirements
MichaelGHSeg 56fa57b
Document sentBatches field in README and code
MichaelGHSeg ef14e04
Address Copilot review feedback
MichaelGHSeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ node_modules/ | |
| coverage/ | ||
| lib/ | ||
| e2e/ | ||
| e2e-cli/ | ||
| examples/ | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
MichaelGHSeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| node_modules/ | ||
| dist/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": {} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.