Skip to content

Commit 4de287a

Browse files
committed
Simplify transport intercept
1 parent e4bc4c7 commit 4de287a

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

packages/bundler-plugin-core/src/sentry/transports.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,6 @@ function makeNodeTransport(options: BaseTransportOptions) {
9898
return createTransport(options, requestExecutor);
9999
}
100100

101-
/**
102-
* global.__SENTRY_INTERCEPT_TRANSPORT__ is used for testing purposes. If it is
103-
* set as an array, the transport will push envelopes to it instead of sending them.
104-
*/
105-
function getGlobalWithInterceptor(): typeof global & {
106-
__SENTRY_INTERCEPT_TRANSPORT__?: unknown[];
107-
} {
108-
return global;
109-
}
110-
111101
/** A transports that does nothing */
112102
export function makeOptionallyEnabledNodeTransport(
113103
shouldSendTelemetry: Promise<boolean>
@@ -117,10 +107,13 @@ export function makeOptionallyEnabledNodeTransport(
117107
return {
118108
flush: (timeout) => nodeTransport.flush(timeout),
119109
send: async (request) => {
120-
// Allow intercepting enveloped for testing
121-
const gbl = getGlobalWithInterceptor();
122-
if (gbl.__SENTRY_INTERCEPT_TRANSPORT__) {
123-
gbl.__SENTRY_INTERCEPT_TRANSPORT__.push(request);
110+
// If global.__SENTRY_INTERCEPT_TRANSPORT__ is an array, we push the
111+
// envelope into it for testing purposes.
112+
if (
113+
"__SENTRY_INTERCEPT_TRANSPORT__" in global &&
114+
Array.isArray(global.__SENTRY_INTERCEPT_TRANSPORT__)
115+
) {
116+
global.__SENTRY_INTERCEPT_TRANSPORT__.push(request);
124117
return { statusCode: 200 };
125118
}
126119

0 commit comments

Comments
 (0)