Skip to content
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
5 changes: 3 additions & 2 deletions dev-packages/bun-integration-tests/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Envelope, EnvelopeItemType } from '@sentry/core';
import { normalize } from '@sentry/core';
import { createBasicSentryServer } from '@sentry-internal/test-utils';
import { spawn } from 'child_process';
import { existsSync } from 'fs';
import { existsSync, statSync } from 'fs';
import { join } from 'path';
import { inspect } from 'util';
import { expect } from 'vitest';
Expand Down Expand Up @@ -63,6 +63,8 @@ export function createRunner(...paths: string[]) {
throw new Error(`Test scenario not found: ${testPath}`);
}

const entryFile = statSync(testPath).isDirectory() ? join(testPath, 'index.ts') : testPath;

const expectedEnvelopes: Expected[] = [];
const ignored: Set<EnvelopeItemType> = new Set(['session', 'sessions', 'client_report']);
const envVars: Record<string, string> = {};
Expand Down Expand Up @@ -170,7 +172,6 @@ export function createRunner(...paths: string[]) {

if (process.env.DEBUG) log('Starting scenario', testPath);

const entryFile = join(testPath, 'index.ts');
if (!existsSync(entryFile)) {
reject(new Error(`Entry file not found: ${entryFile}`));
return;
Expand Down
18 changes: 18 additions & 0 deletions dev-packages/bun-integration-tests/suites/cjs/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const Sentry = require('@sentry/bun');

Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
});

const server = Bun.serve({
port: 0,
fetch() {
throw new Error('This is a test error from a CommonJS Bun app');
},
error() {
return new Response('Internal Server Error', { status: 500 });
},
});

process.send?.(JSON.stringify({ event: 'READY', port: server.port }));
35 changes: 35 additions & 0 deletions dev-packages/bun-integration-tests/suites/cjs/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { expect, it } from 'vitest';
import { eventEnvelope } from '../../expect';
import { createRunner } from '../../runner';

it('initializes when @sentry/bun is loaded with require()', async ({ signal }) => {
const runner = createRunner(__dirname, 'index.cjs')
.expect(
eventEnvelope(
{
level: 'error',
exception: {
values: [
{
type: 'Error',
value: 'This is a test error from a CommonJS Bun app',
stacktrace: {
frames: expect.any(Array),
},
mechanism: { type: 'auto.http.bun.serve', handled: false },
},
],
},
request: expect.objectContaining({
method: 'GET',
url: expect.stringContaining('/error'),
}),
},
{ includeSampleRand: true, includeTransaction: false },
),
)
.ignore('span')
.start(signal);
await runner.makeRequest('get', '/error', { expectError: true });
await runner.completed();
});
4 changes: 2 additions & 2 deletions packages/bun/src/integrations/bunHttpServer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { errorMonitor } from 'node:events';
import http from 'node:http';
import https from 'node:https';
import * as http from 'node:http';
import * as https from 'node:https';
import type { IntegrationFn, Span } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import type { HttpIncomingMessage, HttpServerResponse } from '@sentry/core/server';
Expand Down
Loading