Skip to content

Commit

Permalink
feat: set app version as dev when building locally
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed Jun 14, 2024
1 parent ba0a493 commit f6c1f60
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 7 deletions.
67 changes: 67 additions & 0 deletions src/routes/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<SettingsRoute />
</MemoryRouter>
</AppContext.Provider>,
);
});

expect(screen.getByTitle('app-version')).toMatchSnapshot();
});

it('should show development app version', async () => {
process.env = {
...originalEnv,
NODE_ENV: 'development',
};

await act(async () => {
render(
<AppContext.Provider
value={{
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<SettingsRoute />
</MemoryRouter>
</AppContext.Provider>,
);
});

expect(screen.getByTitle('app-version')).toMatchSnapshot();
});
});

it('should open release notes', async () => {
const openExternalLinkMock = jest.spyOn(comms, 'openExternalLink');

Expand Down
11 changes: 8 additions & 3 deletions src/routes/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -283,7 +288,7 @@ export const SettingsRoute: FC = () => {
title="View release notes"
onClick={() => openGitifyReleaseNotes(appVersion)}
>
Gitify v{appVersion}
<span title="app-version">Gitify {appVersion}</span>
</button>
<div>
<button
Expand Down
26 changes: 24 additions & 2 deletions src/routes/__snapshots__/Settings.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utils/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('utils/links.ts', () => {
});

it('openGitifyReleaseNotes', () => {
openGitifyReleaseNotes('1.0.0');
openGitifyReleaseNotes('v1.0.0');
expect(comms.openExternalLink).toHaveBeenCalledWith(
'https://github.com/gitify-app/gitify/releases/tag/v1.0.0',
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function openGitifyRepository() {

export function openGitifyReleaseNotes(version: string) {
openExternalLink(
`https://github.com/${Constants.REPO_SLUG}/releases/tag/v${version}` as Link,
`https://github.com/${Constants.REPO_SLUG}/releases/tag/${version}` as Link,
);
}

Expand Down

0 comments on commit f6c1f60

Please sign in to comment.