From d288aa603b623f1919e6476c4e9fde08f9cbfab0 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Fri, 14 Jun 2024 12:08:22 -0400 Subject: [PATCH] feat: set app version as `dev` when building locally (#1237) --- src/routes/Settings.test.tsx | 67 +++++++++++++++++++ src/routes/Settings.tsx | 11 ++- .../__snapshots__/Settings.test.tsx.snap | 26 ++++++- src/utils/links.test.ts | 2 +- src/utils/links.ts | 2 +- 5 files changed, 101 insertions(+), 7 deletions(-) diff --git a/src/routes/Settings.test.tsx b/src/routes/Settings.test.tsx index 35e6b4a73..399aaefe4 100644 --- a/src/routes/Settings.test.tsx +++ b/src/routes/Settings.test.tsx @@ -31,6 +31,11 @@ describe('routes/Settings.tsx', () => { Object.defineProperty(process, 'platform', { value: originalPlatform, }); + + // Restore the original node env value + Object.defineProperty(process, 'platform', { + value: originalPlatform, + }); }); describe('General', () => { @@ -481,6 +486,68 @@ describe('routes/Settings.tsx', () => { }); describe('Footer section', () => { + describe('app version', () => { + let originalEnv: NodeJS.ProcessEnv; + + beforeEach(() => { + // Save the original node env state + originalEnv = process.env; + }); + + afterEach(() => { + // Restore the original node env state + process.env = originalEnv; + }); + + it('should show production app version', async () => { + process.env = { + ...originalEnv, + NODE_ENV: 'production', + }; + + await act(async () => { + render( + + + + + , + ); + }); + + expect(screen.getByTitle('app-version')).toMatchSnapshot(); + }); + + it('should show development app version', async () => { + process.env = { + ...originalEnv, + NODE_ENV: 'development', + }; + + await act(async () => { + render( + + + + + , + ); + }); + + expect(screen.getByTitle('app-version')).toMatchSnapshot(); + }); + }); + it('should open release notes', async () => { const openExternalLinkMock = jest.spyOn(comms, 'openExternalLink'); diff --git a/src/routes/Settings.tsx b/src/routes/Settings.tsx index c13fed871..4b8285f7e 100644 --- a/src/routes/Settings.tsx +++ b/src/routes/Settings.tsx @@ -38,8 +38,13 @@ export const SettingsRoute: FC = () => { useEffect(() => { (async () => { - const result = await getAppVersion(); - setAppVersion(result); + console.log('process.env.NODE_ENV', process.env.NODE_ENV); + if (process.env.NODE_ENV === 'development') { + setAppVersion('dev'); + } else { + const result = await getAppVersion(); + setAppVersion(`v${result}`); + } })(); ipcRenderer.on('gitify:update-theme', (_, updatedTheme: Theme) => { @@ -283,7 +288,7 @@ export const SettingsRoute: FC = () => { title="View release notes" onClick={() => openGitifyReleaseNotes(appVersion)} > - Gitify v{appVersion} + Gitify {appVersion}