Skip to content

Commit 0034dbc

Browse files
committed
test(bun): Add bun integration test folder
1 parent 61c5602 commit 0034dbc

File tree

11 files changed

+590
-301
lines changed

11 files changed

+590
-301
lines changed

.github/workflows/build.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ jobs:
158158
changed_bun:
159159
${{ needs.job_get_metadata.outputs.changed_ci == 'true' || contains(steps.checkForAffected.outputs.affected,
160160
'@sentry/bun') }}
161+
changed_bun_integration:
162+
${{ needs.job_get_metadata.outputs.changed_ci == 'true' || contains(steps.checkForAffected.outputs.affected,
163+
'@sentry-internal/bun-integration-tests') }}
161164
changed_browser_integration:
162165
${{ needs.job_get_metadata.outputs.changed_ci == 'true' || contains(steps.checkForAffected.outputs.affected,
163166
'@sentry-internal/browser-integration-tests') }}
@@ -769,6 +772,32 @@ jobs:
769772
working-directory: dev-packages/cloudflare-integration-tests
770773
run: yarn test
771774

775+
job_bun_integration_tests:
776+
name: Bun Integration Tests
777+
needs: [job_get_metadata, job_build]
778+
if: needs.job_build.outputs.changed_bun_integration == 'true' || github.event_name != 'pull_request'
779+
runs-on: ubuntu-24.04
780+
timeout-minutes: 15
781+
steps:
782+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
783+
uses: actions/checkout@v6
784+
with:
785+
ref: ${{ env.HEAD_COMMIT }}
786+
- name: Set up Node
787+
uses: actions/setup-node@v6
788+
with:
789+
node-version-file: 'package.json'
790+
- name: Set up Bun
791+
uses: oven-sh/setup-bun@v2
792+
- name: Restore caches
793+
uses: ./.github/actions/restore-cache
794+
with:
795+
dependency_cache_key: ${{ needs.job_build.outputs.dependency_cache_key }}
796+
797+
- name: Run integration tests
798+
working-directory: dev-packages/bun-integration-tests
799+
run: yarn test
800+
772801
job_remix_integration_tests:
773802
name: Remix (Node ${{ matrix.node }}) Tests
774803
needs: [job_get_metadata, job_build]
@@ -1109,6 +1138,7 @@ jobs:
11091138
job_node_integration_tests,
11101139
job_node_core_integration_tests,
11111140
job_cloudflare_integration_tests,
1141+
job_bun_integration_tests,
11121142
job_browser_playwright_tests,
11131143
job_browser_loader_tests,
11141144
job_remix_integration_tests,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "../../node_modules/oxlint/configuration_schema.json",
3+
"extends": ["../.oxlintrc.json"],
4+
"env": {
5+
"node": true
6+
},
7+
"overrides": [
8+
{
9+
"files": ["suites/**/*.ts"],
10+
"globals": {
11+
"Bun": "readonly",
12+
"fetch": "readonly"
13+
},
14+
"rules": {
15+
"typescript/ban-ts-comment": [
16+
"error",
17+
{
18+
"ts-ignore": "allow-with-description",
19+
"ts-expect-error": true
20+
}
21+
],
22+
"import/first": "off"
23+
}
24+
}
25+
]
26+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import type { Contexts, Envelope, Event, SdkInfo } from '@sentry/core';
2+
import { SDK_VERSION } from '@sentry/core';
3+
import { expect } from 'vitest';
4+
5+
export const UUID_MATCHER = expect.stringMatching(/^[\da-f]{32}$/);
6+
export const UUID_V4_MATCHER = expect.stringMatching(
7+
/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/,
8+
);
9+
export const SHORT_UUID_MATCHER = expect.stringMatching(/^[\da-f]{16}$/);
10+
export const ISO_DATE_MATCHER = expect.stringMatching(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
11+
12+
function dropUndefinedKeys<T extends Record<string, unknown>>(obj: T): T {
13+
for (const [key, value] of Object.entries(obj)) {
14+
if (value === undefined) {
15+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
16+
delete obj[key];
17+
}
18+
}
19+
return obj;
20+
}
21+
22+
function getSdk(sdk: 'bun' | 'hono'): SdkInfo {
23+
return {
24+
integrations: expect.any(Array),
25+
name: `sentry.javascript.${sdk}`,
26+
packages: [
27+
{
28+
name: `npm:@sentry/${sdk}`,
29+
version: SDK_VERSION,
30+
},
31+
...(sdk === 'hono' ? [{ name: 'npm:@sentry/bun', version: SDK_VERSION }] : []),
32+
],
33+
version: SDK_VERSION,
34+
};
35+
}
36+
37+
function defaultContexts(eventContexts: Contexts = {}): Contexts {
38+
return dropUndefinedKeys({
39+
app: { app_memory: expect.any(Number), app_start_time: expect.any(String), free_memory: expect.any(Number) },
40+
cloud_resource: expect.any(Object),
41+
trace: {
42+
trace_id: UUID_MATCHER,
43+
span_id: SHORT_UUID_MATCHER,
44+
},
45+
culture: { locale: expect.any(String), timezone: expect.any(String) },
46+
device: expect.any(Object),
47+
os: expect.any(Object),
48+
runtime: { name: 'bun', version: expect.any(String) },
49+
...eventContexts,
50+
});
51+
}
52+
53+
export function expectedEvent(event: Event, { sdk }: { sdk: 'bun' | 'hono' }): Event {
54+
return dropUndefinedKeys({
55+
event_id: UUID_MATCHER,
56+
timestamp: expect.any(Number),
57+
environment: 'production',
58+
platform: 'node',
59+
modules: expect.any(Object),
60+
sdk: getSdk(sdk),
61+
server_name: expect.any(String),
62+
...event,
63+
contexts: defaultContexts(event.contexts),
64+
});
65+
}
66+
67+
export function eventEnvelope(
68+
event: Event,
69+
{ includeSampleRand = false, sdk = 'bun' }: { includeSampleRand?: boolean; sdk?: 'bun' | 'hono' } = {},
70+
): Envelope {
71+
return [
72+
{
73+
event_id: UUID_MATCHER,
74+
sent_at: ISO_DATE_MATCHER,
75+
sdk: { name: `sentry.javascript.${sdk}`, version: SDK_VERSION },
76+
trace: {
77+
environment: event.environment || 'production',
78+
public_key: 'public',
79+
trace_id: UUID_MATCHER,
80+
sample_rate: expect.any(String),
81+
...(includeSampleRand && { sample_rand: expect.stringMatching(/^[01](\.\d+)?$/) }),
82+
sampled: expect.any(String),
83+
},
84+
},
85+
[[{ type: 'event' }, expectedEvent(event, { sdk })]],
86+
];
87+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@sentry-internal/bun-integration-tests",
3+
"version": "10.48.0",
4+
"license": "MIT",
5+
"engines": {
6+
"node": ">=18"
7+
},
8+
"private": true,
9+
"scripts": {
10+
"lint": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --type-aware",
11+
"lint:fix": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --fix --type-aware",
12+
"test": "vitest run",
13+
"test:watch": "yarn test --watch"
14+
},
15+
"dependencies": {
16+
"@sentry/bun": "10.48.0",
17+
"@sentry/hono": "10.48.0",
18+
"hono": "^4.12.12"
19+
},
20+
"devDependencies": {
21+
"@sentry-internal/test-utils": "10.48.0",
22+
"bun-types": "^1.2.9",
23+
"vitest": "^3.2.4"
24+
},
25+
"volta": {
26+
"extends": "../../package.json"
27+
}
28+
}

0 commit comments

Comments
 (0)