Skip to content

Commit 3bede8b

Browse files
committed
change loadedGlobalConfigs to getLoadedGlobalConfigs (#803)
1 parent 29ed52f commit 3bede8b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/utils/config/__tests__/get-config-value.node.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { z } from 'zod';
22

33
import getConfigValue from '../get-config-value';
4-
import { loadedGlobalConfigs } from '../global-configs-ref';
4+
import { getLoadedGlobalConfigs } from '../global-configs-ref';
55

66
jest.mock('../global-configs-ref', () => ({
7-
loadedGlobalConfigs: {
7+
getLoadedGlobalConfigs: jest.fn().mockReturnValue({
88
COMPUTED: jest.fn(),
99
CADENCE_WEB_PORT: 'someValue',
10-
},
10+
}),
1111
}));
1212

1313
jest.mock('@/config/dynamic/resolvers/schemas/resolver-schemas', () => ({
@@ -30,8 +30,8 @@ describe('getConfigValue', () => {
3030

3131
it('calls the function with the provided argument and returns the result', async () => {
3232
// TODO: Fix the type of LoadedConfigs and make it more unit testable
33-
// @ts-expect-error COMPUTED is a function
34-
const mockFn = loadedGlobalConfigs.COMPUTED as jest.Mock;
33+
// @ts-expect-error COMPUTED doesn't exist in the original loaded configs but it exists in the mocks
34+
const mockFn = getLoadedGlobalConfigs().COMPUTED as jest.Mock;
3535
mockFn.mockResolvedValue('resolvedValue');
3636
// @ts-expect-error COMPUTED is not a loaded config
3737
const result = await getConfigValue('COMPUTED');

src/utils/config/get-config-value.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
ConfigKeysWithoutArgs,
99
ResolverSchemas,
1010
} from './config.types';
11-
import { loadedGlobalConfigs } from './global-configs-ref';
11+
import { getLoadedGlobalConfigs } from './global-configs-ref';
1212

1313
// Overload for keys requiring arguments
1414
export default async function getConfigValue<K extends ConfigKeysWithArgs>(
@@ -35,6 +35,7 @@ export default async function getConfigValue<K extends keyof LoadedConfigs>(
3535
throw new Error('getConfigValue cannot be invoked on browser');
3636
}
3737

38+
const loadedGlobalConfigs = getLoadedGlobalConfigs();
3839
const value = loadedGlobalConfigs[key as K];
3940

4041
if (typeof value === 'function') {

src/utils/config/global-configs-ref.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ const setLoadedGlobalConfigs = (c: LoadedConfigs): void => {
77
globalConfigRef.value = c;
88
};
99

10-
const loadedGlobalConfigs: LoadedConfigs = globalConfigRef.value;
11-
export { loadedGlobalConfigs, setLoadedGlobalConfigs };
10+
const getLoadedGlobalConfigs = (): LoadedConfigs => {
11+
return globalConfigRef.value;
12+
};
13+
14+
export { getLoadedGlobalConfigs, setLoadedGlobalConfigs };

0 commit comments

Comments
 (0)