app-defaults: move defaultConfigLoader back to core-app-api

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-10-27 21:21:58 +02:00
parent 5bfe8917c7
commit 3fb98cfcbf
4 changed files with 14 additions and 12 deletions
@@ -16,6 +16,5 @@
export { apis } from './apis';
export { components } from './components';
export { configLoader } from './configLoader';
export { icons } from './icons';
export { themes } from './themes';
@@ -14,13 +14,13 @@
* limitations under the License.
*/
import { configLoader } from './configLoader';
import { defaultConfigLoader } from './defaultConfigLoader';
(process as any).env = { NODE_ENV: 'test' };
const anyEnv = process.env as any;
const anyWindow = window as any;
describe('configLoader', () => {
describe('defaultConfigLoader', () => {
afterEach(() => {
delete anyEnv.APP_CONFIG;
delete anyWindow.__APP_CONFIG__;
@@ -32,7 +32,7 @@ describe('configLoader', () => {
{ data: { my: 'override-config' }, context: 'b' },
];
const configs = await configLoader();
const configs = await defaultConfigLoader();
expect(configs).toEqual([
{ data: { my: 'config' }, context: 'a' },
{ data: { my: 'override-config' }, context: 'b' },
@@ -45,7 +45,9 @@ describe('configLoader', () => {
{ data: { my: 'config' }, context: 'b' },
];
const configs = await (configLoader as any)('{"my":"runtime-config"}');
const configs = await (defaultConfigLoader as any)(
'{"my":"runtime-config"}',
);
expect(configs).toEqual([
{ data: { my: 'override-config' }, context: 'a' },
{ data: { my: 'config' }, context: 'b' },
@@ -54,14 +56,14 @@ describe('configLoader', () => {
});
it('fails to load invalid missing config', async () => {
await expect(configLoader()).rejects.toThrow(
await expect(defaultConfigLoader()).rejects.toThrow(
'No static configuration provided',
);
});
it('fails to load invalid static config', async () => {
anyEnv.APP_CONFIG = { my: 'invalid-config' };
await expect(configLoader()).rejects.toThrow(
await expect(defaultConfigLoader()).rejects.toThrow(
'Static configuration has invalid format',
);
});
@@ -69,7 +71,7 @@ describe('configLoader', () => {
it('fails to load bad runtime config', async () => {
anyEnv.APP_CONFIG = [{ data: { my: 'config' }, context: 'a' }];
await expect((configLoader as any)('}')).rejects.toThrow(
await expect((defaultConfigLoader as any)('}')).rejects.toThrow(
'Failed to load runtime configuration, SyntaxError: Unexpected token } in JSON at position 0',
);
});
@@ -82,7 +84,7 @@ describe('configLoader', () => {
const windowConfig = { app: { configKey: 'config-value' } };
anyWindow.__APP_CONFIG__ = windowConfig;
const configs = await configLoader();
const configs = await defaultConfigLoader();
expect(configs).toEqual([
...anyEnv.APP_CONFIG,
@@ -16,7 +16,7 @@
import { AppConfig } from '@backstage/config';
import { JsonObject } from '@backstage/types';
import { AppConfigLoader } from '@backstage/core-app-api';
import { AppConfigLoader } from './types';
/**
* The default config loader, which expects that config is available at compile-time
@@ -30,7 +30,7 @@ import { AppConfigLoader } from '@backstage/core-app-api';
*
* @public
*/
export const configLoader: AppConfigLoader = async (
export const defaultConfigLoader: AppConfigLoader = async (
// This string may be replaced at runtime to provide additional config.
// It should be replaced by a JSON-serialized config object.
// It's a param so we can test it, but at runtime this will always fall back to default.
+2 -1
View File
@@ -14,6 +14,7 @@
* limitations under the License.
*/
export { createApp, defaultConfigLoader } from './createApp';
export { createApp } from './createApp';
export { defaultConfigLoader } from './defaultConfigLoader';
export type { AppIcons } from './icons';
export * from './types';