Skip to content

Commit 2b0d67b

Browse files
committed
fix(node): Guard process.env.NODE_ENV access in Spotlight integration
1 parent 8744898 commit 2b0d67b

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

packages/node/src/integrations/spotlight.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class Spotlight implements Integration {
4141
* Sets up forwarding envelopes to the Spotlight Sidecar
4242
*/
4343
public setup(client: Client): void {
44-
if (process.env.NODE_ENV !== 'development') {
45-
logger.warn("[Spotlight] It seems you're not in dev mode. Do you really want to have Spoltight enabled?");
44+
if (typeof process === 'object' && process.env && process.env.NODE_ENV !== 'development') {
45+
logger.warn("[Spotlight] It seems you're not in dev mode. Do you really want to have Spotlight enabled?");
4646
}
4747
connectToSpotlight(client, this._options);
4848
}

packages/node/test/integrations/spotlight.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('Spotlight', () => {
138138
integration.setup(client);
139139

140140
expect(loggerSpy).toHaveBeenCalledWith(
141-
expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spoltight enabled?"),
141+
expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"),
142142
);
143143

144144
process.env.NODE_ENV = oldEnvValue;
@@ -152,9 +152,41 @@ describe('Spotlight', () => {
152152
integration.setup(client);
153153

154154
expect(loggerSpy).not.toHaveBeenCalledWith(
155-
expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spoltight enabled?"),
155+
expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"),
156156
);
157157

158158
process.env.NODE_ENV = oldEnvValue;
159159
});
160+
161+
it('handles `process` not being available', () => {
162+
const originalProcess = process;
163+
164+
// @ts-expect-error - TS complains but we explicitly wanna test this
165+
delete globalThis.process;
166+
167+
const integration = new Spotlight({ sidecarUrl: 'http://localhost:8969' });
168+
integration.setup(client);
169+
170+
expect(loggerSpy).not.toHaveBeenCalledWith(
171+
expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"),
172+
);
173+
174+
globalThis.process = originalProcess;
175+
});
176+
177+
it('handles `process.env` not being available', () => {
178+
const originalEnv = process.env;
179+
180+
// @ts-expect-error - TS complains but we explicitly wanna test this
181+
delete process.env;
182+
183+
const integration = new Spotlight({ sidecarUrl: 'http://localhost:8969' });
184+
integration.setup(client);
185+
186+
expect(loggerSpy).not.toHaveBeenCalledWith(
187+
expect.stringContaining("It seems you're not in dev mode. Do you really want to have Spotlight enabled?"),
188+
);
189+
190+
process.env = originalEnv;
191+
});
160192
});

0 commit comments

Comments
 (0)