-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Merged
AbhiPrasad
merged 18 commits into
develop
from
timfish/test/cloudflare-integration-tests
Jul 29, 2025
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cadcb75
test(cloudflare): Add integration tests
timfish 63013ad
Don't run with the unit tests...
timfish 581d0a4
Fix node integration tests
timfish 072e6e1
Improve test runner
timfish abfa737
Merge remote-tracking branch 'upstream/develop' into timfish/test/clo…
timfish 32ee76f
Run it all the time
timfish f763100
Fix the versions from the merge
timfish c6e1884
Merge branch 'develop' into timfish/test/cloudflare-integration-tests
timfish adbac79
Fix versions
timfish 3d502db
Merge branch 'timfish/test/cloudflare-integration-tests' of github.co…
timfish 6bc5e1e
PR review
timfish e25e730
Merge branch 'develop' into timfish/test/cloudflare-integration-tests
timfish a79ba28
Fix versions after bad merge
timfish 1940016
Merge branch 'develop' into timfish/test/cloudflare-integration-tests
timfish de17c6f
Merge branch 'develop' into timfish/test/cloudflare-integration-tests
timfish a2b082d
Use link
timfish 55ecbc1
Fix paths
timfish 640cb90
Merge remote-tracking branch 'upstream/develop' into timfish/test/clo…
timfish 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
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 |
---|---|---|
|
@@ -60,3 +60,4 @@ packages/gatsby/gatsby-node.d.ts | |
|
||
# intellij | ||
*.iml | ||
/**/.wrangler/* |
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 @@ | ||
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', | ||
}, | ||
}, | ||
], | ||
}; |
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,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)]], | ||
]; | ||
} |
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,27 @@ | ||
{ | ||
"name": "@sentry-internal/cloudflare-integration-tests", | ||
"version": "9.38.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.38.0" | ||
}, | ||
"devDependencies": { | ||
"@sentry-internal/test-utils": "9.38.0", | ||
timfish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@cloudflare/workers-types": "^4.20250708.0", | ||
"vitest": "^3.2.4", | ||
"wrangler": "4.22.0" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
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.