Skip to content

Commit 1efdea2

Browse files
fix(js): Directly access process.env.NODE_ENV (#99481)
For some unknown reason importing from the constants file is causing this to come back as a object of the module's exports
1 parent 3d0e504 commit 1efdea2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

static/app/components/frontendVersionContext.spec.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import ConfigStore from 'sentry/stores/configStore';
55

66
import {FrontendVersionProvider, useFrontendVersion} from './frontendVersionContext';
77

8-
// Mock constants to control test environment, the FrontendVersionProvider ony
9-
// does anything in production SAAS.
108
jest.mock('sentry/constants', () => ({
119
__esModule: true,
1210
DEPLOY_PREVIEW_CONFIG: undefined,
13-
NODE_ENV: 'production',
1411
}));
1512

13+
const originalNodeEnv = process.env.NODE_ENV;
14+
1615
function TestComponent() {
1716
const {state, deployedVersion, runningVersion} = useFrontendVersion();
1817

@@ -29,10 +28,12 @@ describe('FrontendVersionProvider', () => {
2928
beforeEach(() => {
3029
MockApiClient.clearMockResponses();
3130
ConfigStore.set('sentryMode', 'SAAS');
31+
process.env.NODE_ENV = 'production';
3232
});
3333

3434
afterEach(() => {
3535
jest.restoreAllMocks();
36+
process.env.NODE_ENV = originalNodeEnv;
3637
});
3738

3839
it('provides state="current" when server version matches current version', async () => {
@@ -133,7 +134,7 @@ describe('FrontendVersionProvider', () => {
133134
});
134135

135136
it('provides state="disabled" when NODE_ENV is not production', async () => {
136-
jest.mocked(constants).NODE_ENV = 'development';
137+
process.env.NODE_ENV = 'development';
137138

138139
MockApiClient.addMockResponse({
139140
url: '/internal/frontend-version/',

static/app/components/frontendVersionContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createContext, useContext} from 'react';
22

3-
import {DEPLOY_PREVIEW_CONFIG, NODE_ENV} from 'sentry/constants';
3+
import {DEPLOY_PREVIEW_CONFIG} from 'sentry/constants';
44
import ConfigStore from 'sentry/stores/configStore';
55
import {useLegacyStore} from 'sentry/stores/useLegacyStore';
66
import {useApiQuery} from 'sentry/utils/queryClient';
@@ -78,7 +78,7 @@ export function FrontendVersionProvider({children, force, releaseVersion}: Props
7878
//
7979
// We only make stale version assessments when the frontend is running a
8080
// production build.
81-
NODE_ENV === 'production' &&
81+
process.env.NODE_ENV === 'production' &&
8282
//
8383
// We do not make stale version assessments when running deployment
8484
// previews, these are inherinetly a differning version from what is

0 commit comments

Comments
 (0)