Skip to content
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

test(e2e): Do not require DSN to run E2E tests #12743

Merged
merged 8 commits into from
Jul 4, 2024
Merged
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
38 changes: 21 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -971,22 +971,19 @@ jobs:

job_e2e_tests:
name: E2E ${{ matrix.label || matrix.test-application }} Test
# We only run E2E tests for non-fork PRs because the E2E tests require secrets to work and they can't be accessed from forks
# We need to add the `always()` check here because the previous step has this as well :(
# See: https://github.com/actions/runner/issues/2205
if:
always() && needs.job_e2e_prepare.result == 'success' &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
if: always() && needs.job_e2e_prepare.result == 'success'
needs: [job_get_metadata, job_build, job_e2e_prepare]
runs-on: ubuntu-20.04
timeout-minutes: 10
env:
E2E_TEST_AUTH_TOKEN: ${{ secrets.E2E_TEST_AUTH_TOKEN }}
E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
# We just use a dummy DSN here, only send to the tunnel anyhow
E2E_TEST_DSN: 'https://username@domain/123'
# Needed because some apps expect a certain prefix
NEXT_PUBLIC_E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
PUBLIC_E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
REACT_APP_E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
NEXT_PUBLIC_E2E_TEST_DSN: 'https://username@domain/123'
PUBLIC_E2E_TEST_DSN: 'https://username@domain/123'
REACT_APP_E2E_TEST_DSN: 'https://username@domain/123'
E2E_TEST_SENTRY_ORG_SLUG: 'sentry-javascript-sdks'
E2E_TEST_SENTRY_PROJECT: 'sentry-javascript-e2e-tests'
strategy:
Expand Down Expand Up @@ -1072,7 +1069,7 @@ jobs:
ref: ${{ env.HEAD_COMMIT }}
- uses: pnpm/action-setup@v4
with:
version: 8.3.1
version: 9.4.0
- name: Set up Node
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -1109,12 +1106,12 @@ jobs:
- name: Build E2E app
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
timeout-minutes: 5
run: yarn ${{ matrix.build-command || 'test:build' }}
run: pnpm ${{ matrix.build-command || 'test:build' }}

- name: Run E2E test
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
timeout-minutes: 5
run: yarn test:assert
run: pnpm test:assert

- name: Deploy Astro to Cloudflare
uses: cloudflare/pages-action@v1
Expand Down Expand Up @@ -1149,8 +1146,6 @@ jobs:
strategy:
fail-fast: false
matrix:
is_dependabot:
- ${{ github.actor == 'dependabot[bot]' }}
test-application:
[
'react-send-to-sentry',
Expand All @@ -1159,8 +1154,17 @@ jobs:
]
build-command:
- false
assert-command:
- false
label:
- false
include:
- test-application: 'create-remix-app'
assert-command: 'test:assert-sourcemaps'
label: 'create-remix-app (sourcemaps)'
- test-application: 'create-remix-app-legacy'
assert-command: 'test:assert-sourcemaps'
label: 'create-remix-app-legacy (sourcemaps)'

steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
Expand All @@ -1169,7 +1173,7 @@ jobs:
ref: ${{ env.HEAD_COMMIT }}
- uses: pnpm/action-setup@v4
with:
version: 8.3.1
version: 9.4.0
- name: Set up Node
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -1203,12 +1207,12 @@ jobs:
- name: Build E2E app
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
timeout-minutes: 5
run: yarn ${{ matrix.build-command || 'test:build' }}
run: pnpm ${{ matrix.build-command || 'test:build' }}

- name: Run E2E test
working-directory: dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}
timeout-minutes: 5
run: yarn test:assert
run: pnpm ${{ matrix.assert-command || 'test:assert' }}

job_profiling_e2e_tests:
name: E2E ${{ matrix.label || matrix.test-application }} Test
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ jobs:
runs-on: ubuntu-20.04
timeout-minutes: 20
env:
E2E_TEST_AUTH_TOKEN: ${{ secrets.E2E_TEST_AUTH_TOKEN }}
E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
# Needed because certain apps expect a certain prefix
NEXT_PUBLIC_E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
PUBLIC_E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
REACT_APP_E2E_TEST_DSN: ${{ secrets.E2E_TEST_DSN }}
# We just use a dummy DSN here, only send to the tunnel anyhow
E2E_TEST_DSN: 'https://username@domain/123'
# Needed because some apps expect a certain prefix
NEXT_PUBLIC_E2E_TEST_DSN: 'https://username@domain/123'
PUBLIC_E2E_TEST_DSN: 'https://username@domain/123'
REACT_APP_E2E_TEST_DSN: 'https://username@domain/123'
E2E_TEST_SENTRY_ORG_SLUG: 'sentry-javascript-sdks'
E2E_TEST_SENTRY_PROJECT: 'sentry-javascript-e2e-tests'
strategy:
Expand Down
3 changes: 2 additions & 1 deletion dev-packages/e2e-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ current state.
Prerequisites: Docker

- Copy `.env.example` to `.env`
- Fill in auth information in `.env` for an example Sentry project
- OPTIONAL: Fill in auth information in `.env` for an example Sentry project - you only need this to run E2E tests that
send data to Sentry.
- Run `yarn build:tarball` in the root of the repository

To finally run all of the tests:
Expand Down
33 changes: 0 additions & 33 deletions dev-packages/e2e-tests/lib/validate.ts

This file was deleted.

5 changes: 0 additions & 5 deletions dev-packages/e2e-tests/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
/* eslint-disable no-console */
import * as dotenv from 'dotenv';

import { validate } from './lib/validate';
import { registrySetup } from './registrySetup';

async function run(): Promise<void> {
// Load environment variables from .env file locally
dotenv.config();

if (!validate()) {
process.exit(1);
}

try {
registrySetup();
} catch (error) {
Expand Down
23 changes: 15 additions & 8 deletions dev-packages/e2e-tests/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { resolve } from 'path';
import * as dotenv from 'dotenv';
import { sync as globSync } from 'glob';

import { validate } from './lib/validate';
import { registrySetup } from './registrySetup';

const DEFAULT_DSN = 'https://username@domain/123';
const DEFAULT_SENTRY_ORG_SLUG = 'sentry-javascript-sdks';
const DEFAULT_SENTRY_PROJECT = 'sentry-javascript-e2e-tests';

function asyncExec(command: string, options: { env: Record<string, string | undefined>; cwd: string }): Promise<void> {
return new Promise((resolve, reject) => {
const process = spawn(command, { ...options, shell: true });
Expand Down Expand Up @@ -39,17 +42,21 @@ async function run(): Promise<void> {
// Allow to run a single app only via `yarn test:run <app-name>`
const appName = process.argv[2];

if (!validate()) {
process.exit(1);
}
const dsn = process.env.E2E_TEST_DSN || DEFAULT_DSN;

const envVarsToInject = {
NEXT_PUBLIC_E2E_TEST_DSN: process.env.E2E_TEST_DSN,
PUBLIC_E2E_TEST_DSN: process.env.E2E_TEST_DSN,
REACT_APP_E2E_TEST_DSN: process.env.E2E_TEST_DSN,
E2E_TEST_DSN: dsn,
NEXT_PUBLIC_E2E_TEST_DSN: dsn,
PUBLIC_E2E_TEST_DSN: dsn,
REACT_APP_E2E_TEST_DSN: dsn,
E2E_TEST_SENTRY_ORG_SLUG: process.env.E2E_TEST_SENTRY_ORG_SLUG || DEFAULT_SENTRY_ORG_SLUG,
E2E_TEST_SENTRY_PROJECT: process.env.E2E_TEST_SENTRY_PROJECT || DEFAULT_SENTRY_PROJECT,
};

const env = { ...process.env, ...envVarsToInject };
const env = {
...process.env,
...envVarsToInject,
};

try {
console.log('Cleaning test-applications...');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import { startEventProxyServer } from '@sentry-internal/test-utils';
startEventProxyServer({
port: 3031,
proxyServerName: 'aws-serverless-lambda-layer-cjs',
forwardToSentry: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"private": true,
"sideEffects": false,
"scripts": {
"build": "remix build --sourcemap && ./upload-sourcemaps.sh",
"build": "remix build --sourcemap",
"upload-sourcemaps": "./upload-sourcemaps.sh",
"dev": "remix dev",
"start": "remix-serve build",
"typecheck": "tsc",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm playwright test"
"test:assert": "pnpm playwright test",
"test:assert-sourcemaps": "pnpm upload-sourcemaps"
},
"dependencies": {
"@sentry/remix": "latest || *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"private": true,
"sideEffects": false,
"scripts": {
"build": "remix build --sourcemap && ./upload-sourcemaps.sh",
"build": "remix build --sourcemap",
"upload-sourcemaps": "./upload-sourcemaps.sh",
"dev": "remix dev",
"start": "NODE_OPTIONS='--require=./instrument.server.cjs' remix-serve build",
"typecheck": "tsc",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && npx playwright install && pnpm build",
"test:assert": "pnpm playwright test"
"test:assert": "pnpm playwright test",
"test:assert-sourcemaps": "pnpm upload-sourcemaps"
},
"dependencies": {
"@sentry/remix": "latest || *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import Index from './pages/Index';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn:
process.env.REACT_APP_E2E_TEST_DSN ||
'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576',
dsn: process.env.REACT_APP_E2E_TEST_DSN,
release: 'e2e-test',
tunnel: 'http://localhost:3031/', // proxy server
});
Expand Down
12 changes: 9 additions & 3 deletions dev-packages/test-utils/src/event-proxy-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface EventProxyServerOptions {
/** The name for the proxy server used for referencing it with listener functions */
proxyServerName: string;
/**
* Whether or not to forward the event to sentry. @default `true`
* Whether or not to forward the event to sentry. @default `false`
* This is helpful when you can't register a tunnel in the SDK setup (e.g. lambda layer without Sentry.init call)
*/
forwardToSentry?: boolean;
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
await startProxyServer(options, async (eventCallbackListeners, proxyRequest, proxyRequestBody, eventBuffer) => {
const envelopeHeader: EnvelopeItem[0] = JSON.parse(proxyRequestBody.split('\n')[0] as string);

const shouldForwardEventToSentry = options.forwardToSentry != null ? options.forwardToSentry : true;
const shouldForwardEventToSentry = options.forwardToSentry || false;

if (!envelopeHeader.dsn && shouldForwardEventToSentry) {
// eslint-disable-next-line no-console
Expand All @@ -195,7 +195,13 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
listener(Buffer.from(JSON.stringify(data)).toString('base64'));
});

return [200, '{}', {}];
return [
200,
'{}',
{
'Access-Control-Allow-Origin': '*',
},
];
}

const { origin, pathname, host } = new URL(envelopeHeader.dsn as string);
Expand Down
Loading