Skip to content

test(cloudflare): Add integration test infrastructure #16848

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
wants to merge 11 commits into
base: develop
Choose a base branch
from
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
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,29 @@ jobs:
directory: dev-packages/node-integration-tests
token: ${{ secrets.CODECOV_TOKEN }}

job_cloudflare_integration_tests:
name: Cloudflare Integration Tests
needs: [job_get_metadata, job_build]
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
with:
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}

- name: Run integration tests
working-directory: dev-packages/cloudflare-integration-tests
run: yarn test

job_remix_integration_tests:
name: Remix (Node ${{ matrix.node }}) Tests
needs: [job_get_metadata, job_build]
Expand Down Expand Up @@ -1095,6 +1118,7 @@ jobs:
job_deno_unit_tests,
job_node_unit_tests,
job_node_integration_tests,
job_cloudflare_integration_tests,
job_browser_playwright_tests,
job_browser_loader_tests,
job_remix_integration_tests,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ packages/gatsby/gatsby-node.d.ts

# intellij
*.iml
/**/.wrangler/*
35 changes: 35 additions & 0 deletions dev-packages/cloudflare-integration-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
env: {
node: true,
},
extends: ['../../.eslintrc.js'],
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: ['tsconfig.json'],
sourceType: 'module',
},
},
{
files: ['suites/**/*.ts', 'suites/**/*.mjs'],
globals: {
fetch: 'readonly',
},
rules: {
'@typescript-eslint/typedef': 'off',
// Explicitly allow ts-ignore with description for Node integration tests
// Reason: We run these tests on TS3.8 which doesn't support `@ts-expect-error`
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description',
'ts-expect-error': true,
},
],
// We rely on having imports after init() is called for OTEL
'import/first': 'off',
},
},
],
};
78 changes: 78 additions & 0 deletions dev-packages/cloudflare-integration-tests/expect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type { Contexts, Envelope, Event, SdkInfo } from '@sentry/core';
import { SDK_VERSION } from '@sentry/core';
import { expect } from 'vitest';

export const UUID_MATCHER = expect.stringMatching(/^[0-9a-f]{32}$/);
export const UUID_V4_MATCHER = expect.stringMatching(
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
);
export const SHORT_UUID_MATCHER = expect.stringMatching(/^[0-9a-f]{16}$/);
export const ISO_DATE_MATCHER = expect.stringMatching(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);

function dropUndefinedKeys<T extends Record<string, unknown>>(obj: T): T {
for (const [key, value] of Object.entries(obj)) {
if (value === undefined) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete obj[key];
}
}
return obj;
}

function getSdk(): SdkInfo {
return {
integrations: expect.any(Array),
name: 'sentry.javascript.cloudflare',
packages: [
{
name: 'npm:@sentry/cloudflare',
version: SDK_VERSION,
},
],
version: SDK_VERSION,
};
}

function defaultContexts(eventContexts: Contexts = {}): Contexts {
return dropUndefinedKeys({
trace: {
trace_id: UUID_MATCHER,
span_id: SHORT_UUID_MATCHER,
},
cloud_resource: { 'cloud.provider': 'cloudflare' },
culture: { timezone: expect.any(String) },
runtime: { name: 'cloudflare' },
...eventContexts,
});
}

export function expectedEvent(event: Event): Event {
return dropUndefinedKeys({
event_id: UUID_MATCHER,
timestamp: expect.any(Number),
environment: 'production',
platform: 'javascript',
sdk: getSdk(),
...event,
contexts: defaultContexts(event.contexts),
});
}

export function eventEnvelope(event: Event): Envelope {
return [
{
event_id: UUID_MATCHER,
sent_at: ISO_DATE_MATCHER,
sdk: { name: 'sentry.javascript.cloudflare', version: SDK_VERSION },
trace: {
environment: event.environment || 'production',
public_key: 'public',
trace_id: UUID_MATCHER,
sample_rate: expect.any(String),
sampled: expect.any(String),
transaction: expect.any(String),
},
},
[[{ type: 'event' }, expectedEvent(event)]],
];
}
27 changes: 27 additions & 0 deletions dev-packages/cloudflare-integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@sentry-internal/cloudflare-integration-tests",
"version": "9.36.0",
"license": "MIT",
"engines": {
"node": ">=18"
},
"private": true,
"scripts": {
"lint": "eslint . --format stylish",
"fix": "eslint . --format stylish --fix",
"test": "vitest run",
"test:watch": "yarn test --watch"
},
"dependencies": {
"@sentry/cloudflare": "9.36.0"
},
"devDependencies": {
"@sentry-internal/test-utils": "9.36.0",
"@cloudflare/workers-types": "^4.20250708.0",
"vitest": "^3.2.4",
"wrangler": "4.22.0"
},
"volta": {
"extends": "../../package.json"
}
}
Loading