Skip to content

Commit

Permalink
feat: Increase robustness of FUEL_NETWORK_URL config (#1379)
Browse files Browse the repository at this point in the history
* test: add testcases for wallet config network url export

* chore: changeset

* feat: increase robustness of fuel network url config
  • Loading branch information
danielbate authored Oct 26, 2023
1 parent ad72725 commit 0d12dc0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .changeset/strange-lions-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
52 changes: 52 additions & 0 deletions packages/wallet/src/configs.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
5 changes: 4 additions & 1 deletion packages/wallet/src/configs.ts
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 0d12dc0

Please sign in to comment.