Skip to content

Commit ab9634a

Browse files
committed
Tweaks to environment checks, isDev() failing on GH Action run
1 parent a46dd1b commit ab9634a

9 files changed

Lines changed: 19 additions & 33 deletions

File tree

src/actions/utils/errors/actionsFunctionHandler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ActionError, type ActionErrorCode } from 'astro:actions'
22
import { captureException, withScope } from '@sentry/astro'
33
import { ensureActionSentry } from '@actions/utils/sentry'
4-
import { isDev, isProd, isTest, isUnitTest } from '@actions/utils/environment/environmentActions'
4+
import { isDev, isProd, isUnitTest } from '@actions/utils/environment/environmentActions'
55
import { ActionsFunctionError, type ActionsFunctionErrorParams } from './ActionsFunctionError'
66

77
ensureActionSentry()
@@ -136,13 +136,9 @@ export function formatActionsErrorLogEntry(
136136
}
137137

138138
/**
139-
* Writes the formatted actions error JSON to stderr. No-ops during tests to keep output clean.
139+
* Writes the formatted actions error JSON to stderr.
140140
*/
141141
function logActionsError(error: ActionsFunctionError, context: ActionsFunctionContext): void {
142-
if (isTest() || isUnitTest()) {
143-
return
144-
}
145-
146142
const entry = formatActionsErrorLogEntry(error, context)
147143
console.error(JSON.stringify(entry))
148144
}

src/actions/utils/sentry/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { init as sentryInit } from '@sentry/astro'
22
import {
33
getPackageRelease,
44
getSentryDsn,
5-
isDev,
65
isProd,
76
} from '@actions/utils/environment/environmentActions'
87

@@ -26,9 +25,7 @@ export function ensureActionSentry(): void {
2625
attachStacktrace: true,
2726
maxBreadcrumbs: 100,
2827
beforeSend(event) {
29-
if (isDev()) {
30-
return null
31-
}
28+
// any logic to modify the event before sending to Sentry
3229
return event
3330
},
3431
})
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
22
import VercelAnalytics from '@vercel/analytics/astro'
3-
import { isProd } from '@components/scripts/utils/environmentClient'
3+
import { isDev, isProd } from '@components/scripts/utils/environmentClient'
44
5-
const prod = isProd()
6-
const mode = prod ? 'production' : 'development'
7-
const debug = !prod
5+
const mode = isProd() ? 'production' : 'development'
86
---
97

108
<script>
@@ -16,4 +14,4 @@ const debug = !prod
1614
return event
1715
}
1816
</script>
19-
<VercelAnalytics debug={debug} mode={mode} />
17+
<VercelAnalytics debug={isDev()} mode={mode} />

src/components/Pwa/ServiceWorker/client/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ export const registerServiceWorker = () => {
3535
return
3636
}
3737

38-
const devMode = isDev()
39-
const allowDevServiceWorker = devMode && isE2eTest()
38+
const allowDevServiceWorker = isDev() && isE2eTest()
4039

41-
if (devMode && !allowDevServiceWorker) {
40+
if (isDev() && !allowDevServiceWorker) {
4241
void navigator.serviceWorker.getRegistrations().then(registrations => {
4342
registrations.forEach(registration => {
4443
console.info('[pwa] unregistering dev service worker', { scope: registration.scope })

src/components/scripts/utils/__tests__/environmentClient.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ describe('Environment detection utilities', () => {
1515
expect(isE2eTest()).toBe(false)
1616
})
1717

18-
it('isTest should return true when ran in unit test', () => {
18+
it('isTest() should return true when running in Vitest', () => {
1919
expect(isTest()).toBe(true)
2020
})
2121

22-
it('isDev should return true when ran in unit test', () => {
22+
it('isDev() should return true when running in Vitest', () => {
2323
expect(isDev()).toBe(true)
2424
})
2525

26-
it('isProd should return false when ran in unit test', () => {
26+
it('isProd() should return false when running in Vitest', () => {
2727
expect(isProd()).toBe(false)
2828
})
2929
})

src/components/scripts/utils/environmentClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ export const isTest = () => {
4848
*/
4949

5050
export const isDev = () => {
51-
return import.meta.env.MODE === 'development'
51+
return import.meta.env.DEV
5252
}
5353

5454
export const isProd = () => {
55-
return import.meta.env.MODE === 'production'
55+
return import.meta.env.PROD
5656
}
5757

5858
/**

src/lib/config/__tests__/environmentServer.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ describe('Build-time environment handling utilities', () => {
1414
expect(isE2eTest()).toBeFalsy()
1515
})
1616

17-
it('should report isTest is true when running in Vitest', () => {
17+
it('isTest() should return true when running in Vitest', () => {
1818
expect(isTest()).toBeTruthy()
1919
})
2020

21-
it('should report running in development environment when running in Vitest', () => {
21+
it('isDev() should return true when running in Vitest', () => {
2222
expect(isDev()).toBeTruthy()
2323
})
2424

25-
it('should report not running in production environment when running in Vitest', () => {
25+
it('isProd() should return false when running in Vitest', () => {
2626
expect(isProd()).toBeFalsy()
2727
})
2828
})

src/lib/config/environmentServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const isCI = () => {
3131
}
3232

3333
export const isDev = () => {
34-
return !isVercel() && !isGitHub()
34+
return !isVercel() && !isGitHub() && process.env['NODE_ENV'] !== 'production'
3535
}
3636

3737
export const isProd = () => {

src/pages/api/_utils/errors/apiFunctionHandler.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHash } from 'node:crypto'
22
import { captureException, withScope } from '@sentry/astro'
33
import { ensureApiSentry } from '@pages/api/_utils/sentry'
4-
import { isDev, isProd, isTest } from '@pages/api/_utils/environment'
4+
import { isDev, isProd } from '@pages/api/_utils/environment'
55
import { ApiFunctionError, type ApiFunctionErrorParams } from './ApiFunctionError'
66

77
ensureApiSentry()
@@ -108,7 +108,7 @@ export function handleApiFunctionError(
108108
requestMeta: sanitizedMetadata,
109109
})
110110

111-
if (isProd() && !isTest()) {
111+
if (isProd()) {
112112
withScope(scope => {
113113
scope.setTags({
114114
route: context.route,
@@ -228,10 +228,6 @@ type LogMetadata = {
228228
}
229229

230230
function logApiError(error: ApiFunctionError, metadata: LogMetadata) {
231-
if (isTest()) {
232-
return
233-
}
234-
235231
const entry = formatApiErrorLogEntry(error, metadata)
236232
console.error(JSON.stringify(entry))
237233
}

0 commit comments

Comments
 (0)