diff --git a/.changeset/strange-lions-warn.md b/.changeset/strange-lions-warn.md new file mode 100644 index 00000000000..a49ba48448f --- /dev/null +++ b/.changeset/strange-lions-warn.md @@ -0,0 +1,2 @@ +--- +--- \ No newline at end of file diff --git a/packages/wallet/src/configs.test.ts b/packages/wallet/src/configs.test.ts new file mode 100644 index 00000000000..1e71827fa93 --- /dev/null +++ b/packages/wallet/src/configs.test.ts @@ -0,0 +1,52 @@ +describe('Configs', () => { + it('exports FUEL_NETWORK_URL', async () => { + const configs = await import('./configs'); + expect(configs.FUEL_NETWORK_URL).toBe('http://127.0.0.1:4000/graphql'); + }); +}); + +describe('Configs - undefined process', () => { + const originalProcess = process; + + beforeEach(() => { + jest.resetModules(); + + // @ts-expect-error - test to assert undefined process + // eslint-disable-next-line no-global-assign + process = undefined; + }); + + afterEach(() => { + // eslint-disable-next-line no-global-assign + process = originalProcess; + }); + + it('exports FUEL_NETWORK_URL with undefined process', async () => { + expect(typeof process).toBe('undefined'); + expect(process).toBeUndefined(); + + const configs = await import('./configs'); + + expect(configs.FUEL_NETWORK_URL).toBe('http://127.0.0.1:4000/graphql'); + }); +}); + +describe('Configs - overridden env', () => { + const originalEnv = process.env; + + beforeEach(() => { + jest.resetModules(); + + process.env = { ...originalEnv, FUEL_NETWORK_URL: 'some-other-network-url' }; + }); + + afterEach(() => { + process.env = originalEnv; + }); + + it('exports FUEL_NETWORK_URL with overridden env', async () => { + const configs = await import('./configs'); + + expect(configs.FUEL_NETWORK_URL).toBe('some-other-network-url'); + }); +}); diff --git a/packages/wallet/src/configs.ts b/packages/wallet/src/configs.ts index b613aad39b8..182406d1cde 100644 --- a/packages/wallet/src/configs.ts +++ b/packages/wallet/src/configs.ts @@ -1 +1,4 @@ -export const FUEL_NETWORK_URL = process?.env?.FUEL_NETWORK_URL || 'http://127.0.0.1:4000/graphql'; +export const FUEL_NETWORK_URL = + typeof process !== 'undefined' + ? process?.env?.FUEL_NETWORK_URL || 'http://127.0.0.1:4000/graphql' + : 'http://127.0.0.1:4000/graphql';