diff --git a/src/__mocks__/utils.ts b/src/__mocks__/utils.ts index c4c0c7561..223c6b9d3 100644 --- a/src/__mocks__/utils.ts +++ b/src/__mocks__/utils.ts @@ -1,5 +1,5 @@ -export function setPlatform(platform: NodeJS.Platform) { - Object.defineProperty(process, 'platform', { - value: platform, - }); +import * as helpers from '../utils/helpers'; + +export function mockDirectoryPath() { + jest.spyOn(helpers, 'getDirectoryPath').mockReturnValue('/mocked/dir/name'); } diff --git a/src/components/AccountNotifications.test.tsx b/src/components/AccountNotifications.test.tsx index 7df675406..f221b9b21 100644 --- a/src/components/AccountNotifications.test.tsx +++ b/src/components/AccountNotifications.test.tsx @@ -1,5 +1,6 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import { mockGitHubCloudAccount, mockSettings } from '../__mocks__/state-mocks'; +import { mockDirectoryPath } from '../__mocks__/utils'; import { AppContext } from '../context/App'; import { GroupBy } from '../types'; import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; @@ -15,6 +16,8 @@ describe('components/AccountNotifications.tsx', () => { // Have to make it consistent so the emojis are always the same beforeEach(() => { global.Math.random = jest.fn(() => 0.1); + + mockDirectoryPath(); }); it('should render itself - group notifications by repositories', () => { diff --git a/src/components/AllRead.test.tsx b/src/components/AllRead.test.tsx index cd12d4a19..f97be7e6c 100644 --- a/src/components/AllRead.test.tsx +++ b/src/components/AllRead.test.tsx @@ -1,4 +1,5 @@ import { render } from '@testing-library/react'; +import { mockDirectoryPath } from '../__mocks__/utils'; import { AllRead } from './AllRead'; describe('components/AllRead.tsx', () => { @@ -6,6 +7,8 @@ describe('components/AllRead.tsx', () => { // Have to make it consistent so the emojis are always the same beforeEach(() => { global.Math.random = jest.fn(() => 0.1); + + mockDirectoryPath(); }); it('should render itself & its children', () => { diff --git a/src/components/Oops.test.tsx b/src/components/Oops.test.tsx index 128055d3d..730d029bd 100644 --- a/src/components/Oops.test.tsx +++ b/src/components/Oops.test.tsx @@ -1,7 +1,12 @@ import { render } from '@testing-library/react'; +import { mockDirectoryPath } from '../__mocks__/utils'; import { Oops } from './Oops'; describe('components/Oops.tsx', () => { + beforeEach(() => { + mockDirectoryPath(); + }); + it('should render itself & its children', () => { const mockError = { title: 'Error title', diff --git a/src/components/__snapshots__/AccountNotifications.test.tsx.snap b/src/components/__snapshots__/AccountNotifications.test.tsx.snap index 3ca923268..0a554937f 100644 --- a/src/components/__snapshots__/AccountNotifications.test.tsx.snap +++ b/src/components/__snapshots__/AccountNotifications.test.tsx.snap @@ -79,7 +79,7 @@ exports[`components/AccountNotifications.tsx should render itself - account erro alt="🔥" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" /> @@ -171,7 +171,7 @@ exports[`components/AccountNotifications.tsx should render itself - account erro alt="🔥" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" /> @@ -1436,7 +1436,7 @@ exports[`components/AccountNotifications.tsx should render itself - no notificat alt="🎊" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" /> @@ -1523,7 +1523,7 @@ exports[`components/AccountNotifications.tsx should render itself - no notificat alt="🎊" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" /> diff --git a/src/components/__snapshots__/AllRead.test.tsx.snap b/src/components/__snapshots__/AllRead.test.tsx.snap index 08d2f7be9..f2b294a6b 100644 --- a/src/components/__snapshots__/AllRead.test.tsx.snap +++ b/src/components/__snapshots__/AllRead.test.tsx.snap @@ -16,7 +16,7 @@ exports[`components/AllRead.tsx should render itself & its children 1`] = ` alt="🎊" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" /> @@ -40,7 +40,7 @@ exports[`components/AllRead.tsx should render itself & its children 1`] = ` alt="🎊" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f38a.svg" /> diff --git a/src/components/__snapshots__/Oops.test.tsx.snap b/src/components/__snapshots__/Oops.test.tsx.snap index bae8e1e92..b910c2467 100644 --- a/src/components/__snapshots__/Oops.test.tsx.snap +++ b/src/components/__snapshots__/Oops.test.tsx.snap @@ -16,7 +16,7 @@ exports[`components/Oops.tsx should render itself & its children 1`] = ` alt="🔥" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" /> @@ -45,7 +45,7 @@ exports[`components/Oops.tsx should render itself & its children 1`] = ` alt="🔥" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f525.svg" /> diff --git a/src/components/icons/Emoji.test.tsx b/src/components/icons/Emoji.test.tsx index 35e1a89a2..a5e4e0950 100644 --- a/src/components/icons/Emoji.test.tsx +++ b/src/components/icons/Emoji.test.tsx @@ -1,7 +1,12 @@ import { render } from '@testing-library/react'; +import { mockDirectoryPath } from '../../__mocks__/utils'; import { Emoji, type IEmoji } from './Emoji'; describe('components/icons/Emoji.tsx', () => { + beforeEach(() => { + mockDirectoryPath(); + }); + it('should render', () => { const props: IEmoji = { emoji: '🍺', diff --git a/src/components/icons/Emoji.tsx b/src/components/icons/Emoji.tsx index db20fb64a..4a65ead6f 100644 --- a/src/components/icons/Emoji.tsx +++ b/src/components/icons/Emoji.tsx @@ -1,6 +1,7 @@ import path from 'node:path'; import twemoji from '@discordapp/twemoji'; import type { FC } from 'react'; +import { getDirectoryPath } from '../../utils/helpers'; export interface IEmoji { emoji: string; @@ -19,7 +20,8 @@ export const Emoji: FC = (props: IEmoji) => { ext: '.svg', callback: (icon: string, options: TwemojiOptions, _variant: string) => { const source = path.resolve( - `${__dirname}/../../node_modules/@discordapp/twemoji/dist`, + getDirectoryPath(), + '../../node_modules/@discordapp/twemoji/dist', ); return ''.concat(source, '/', options.size, '/', icon, options.ext); diff --git a/src/components/icons/__snapshots__/Emoji.test.tsx.snap b/src/components/icons/__snapshots__/Emoji.test.tsx.snap index 9fb4e8650..5117ddb54 100644 --- a/src/components/icons/__snapshots__/Emoji.test.tsx.snap +++ b/src/components/icons/__snapshots__/Emoji.test.tsx.snap @@ -10,7 +10,7 @@ exports[`components/icons/Emoji.tsx should render 1`] = ` alt="🍺" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f37a.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f37a.svg" /> @@ -21,7 +21,7 @@ exports[`components/icons/Emoji.tsx should render 1`] = ` alt="🍺" class="emoji" draggable="false" - src="/Users/asetch/Documents/dev/GitHub/gitify-app/gitify/src/node_modules/@discordapp/twemoji/dist/svg/1f37a.svg" + src="/mocked/node_modules/@discordapp/twemoji/dist/svg/1f37a.svg" /> , diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 10094b417..eb688437d 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -201,3 +201,7 @@ export function getFilterCount(settings: SettingsState): number { return count; } + +export function getDirectoryPath(): string { + return `${__dirname}`; +}