From 3ead02bc493b51c22f5a0eb0c623fa6be01189ac Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Wed, 30 Nov 2022 11:56:07 -0500 Subject: [PATCH] Revert test case changes. Signed-off-by: Aramis Sennyey --- .changeset/young-chairs-check.md | 2 +- packages/app/src/App.test.tsx | 1 - .../src/app/AppManager.compat.test.tsx | 1 - .../src/app/AppManager.stable.test.tsx | 2 - .../core-app-api/src/app/AppManager.test.tsx | 197 +++++++----------- packages/dev-utils/src/devApp/render.test.tsx | 3 +- .../src/App.test.tsx | 1 - 7 files changed, 81 insertions(+), 126 deletions(-) diff --git a/.changeset/young-chairs-check.md b/.changeset/young-chairs-check.md index 85d5bbf664..92426dd5e3 100644 --- a/.changeset/young-chairs-check.md +++ b/.changeset/young-chairs-check.md @@ -2,4 +2,4 @@ '@backstage/core-app-api': patch --- -Apps will now rewrite `app.baseUrl` and `backend.baseUrl` to match `location.origin` when `app.baseUrl` is the same as `backend.baseUrl`. This will help reduce the number of front end builds you have to do with a specific config. +Apps will now rewrite `app.baseUrl` and `backend.baseUrl` to match `location.origin` when `app.baseUrl` is the same as `backend.baseUrl`. This will help reduce the number of frontend builds you have to do with a specific config. diff --git a/packages/app/src/App.test.tsx b/packages/app/src/App.test.tsx index 6eaa9513cd..0c021a8f23 100644 --- a/packages/app/src/App.test.tsx +++ b/packages/app/src/App.test.tsx @@ -30,7 +30,6 @@ describe('App', () => { support: { url: 'http://localhost:7007/support' }, baseUrl: 'http://localhost:3000', }, - backend: { baseUrl: 'http://localhost:7007' }, lighthouse: { baseUrl: 'http://localhost:3003', }, diff --git a/packages/core-app-api/src/app/AppManager.compat.test.tsx b/packages/core-app-api/src/app/AppManager.compat.test.tsx index a0f27d751b..cfbcc87a01 100644 --- a/packages/core-app-api/src/app/AppManager.compat.test.tsx +++ b/packages/core-app-api/src/app/AppManager.compat.test.tsx @@ -83,7 +83,6 @@ describe.each(['beta', 'stable'])('react-router %s', rrVersion => { context: 'test', data: { app: { baseUrl: 'http://localhost/foo' }, - backend: { baseUrl: 'http://localhost' }, }, }, ], diff --git a/packages/core-app-api/src/app/AppManager.stable.test.tsx b/packages/core-app-api/src/app/AppManager.stable.test.tsx index 8c60293391..ba16353d47 100644 --- a/packages/core-app-api/src/app/AppManager.stable.test.tsx +++ b/packages/core-app-api/src/app/AppManager.stable.test.tsx @@ -64,7 +64,6 @@ describe('AppManager', () => { context: 'test', data: { app: { baseUrl: 'http://localhost/foo' }, - backend: { baseUrl: 'http://localhost' }, }, }, ], @@ -99,7 +98,6 @@ describe('AppManager', () => { context: 'test', data: { app: { baseUrl: 'http://localhost/foo' }, - backend: { baseUrl: 'http://localhost' }, }, }, ], diff --git a/packages/core-app-api/src/app/AppManager.test.tsx b/packages/core-app-api/src/app/AppManager.test.tsx index 89cd108dea..dd77c9b4bf 100644 --- a/packages/core-app-api/src/app/AppManager.test.tsx +++ b/packages/core-app-api/src/app/AppManager.test.tsx @@ -572,52 +572,10 @@ describe('Integration Test', () => { }); describe('relative url resolvers', () => { - const checkConfigValue = async ( - data: object, - configString: string, - expectedValue: string, - ) => { - const app = new AppManager({ - apis: [], - defaultApis: [], - themes: [ - { - id: 'light', - title: 'Light Theme', - variant: 'light', - Provider: ({ children }) => <>{children}, - }, - ], - icons, - plugins: [], - components, - configLoader: async () => [ - { - context: 'test', - data, - }, - ], - }); - - const Provider = app.getProvider(); - const ConfigDisplay = () => { - const apiHolder = useApiHolder(); - const config = apiHolder.get(configApiRef); - return {config?.getString(configString)}; - }; - - const dom = await renderWithEffects( - - - , - ); - - // Verify that the backend.baseUrl is set correctly by the AppManager. - expect(dom.getByText(expectedValue)).toBeTruthy(); - }; - [ - { - data: { + it.each([ + [ + [document.location.href, document.location.href], + { backend: { baseUrl: 'http://localhost:8008/', }, @@ -625,29 +583,13 @@ describe('Integration Test', () => { baseUrl: 'http://localhost:8008/', }, }, - paths: ['app.baseUrl', 'backend.baseUrl'], - }, - { - data: { - backend: { - baseUrl: 'http://test.com/', - }, - app: { - baseUrl: 'http://test.com/', - }, - }, - paths: ['app.baseUrl', 'backend.baseUrl'], - }, - ].forEach(item => { - item.paths.forEach(path => { - it('should force the urls to be relative when they are the same', async () => { - await checkConfigValue(item.data, path, 'http://localhost/'); - }); - }); - }); - [ - { - data: { + ], + [ + [ + `${document.location.origin}/backstage`, + `${document.location.origin}/backstage`, + ], + { backend: { baseUrl: 'http://test.com/backstage', }, @@ -655,65 +597,84 @@ describe('Integration Test', () => { baseUrl: 'http://test.com/backstage', }, }, - paths: ['app.baseUrl', 'backend.baseUrl'], - }, - ].forEach(item => { - item.paths.forEach(path => { - it('should force the urls to be relative when they are the same AND keep path values', async () => { - await checkConfigValue(item.data, path, 'http://localhost/backstage'); - }); - }); - }); - [ - { - data: { + ], + [ + [ + `${document.location.origin}/backstage/instance`, + `${document.location.origin}/backstage/instance`, + ], + { backend: { - baseUrl: 'http://test.com/backstage/my-instance', + baseUrl: 'http://test.com/backstage/instance', }, app: { - baseUrl: 'http://test.com/backstage/my-instance', + baseUrl: 'http://test.com/backstage/instance', }, }, - paths: ['app.baseUrl', 'backend.baseUrl'], - }, - ].forEach(item => { - item.paths.forEach(path => { - it('should force the urls to be relative when they are the same AND keep nested path values', async () => { - await checkConfigValue( - item.data, - path, - 'http://localhost/backstage/my-instance', - ); - }); - }); - }); - [ - { - data: { + ], + [ + [ + `http://test-front.com/backstage/instance`, + `http://test.com/backstage/instance`, + ], + { backend: { - baseUrl: 'https://google.com', + baseUrl: 'http://test.com/backstage/instance', }, app: { - baseUrl: 'https://bing.com', + baseUrl: 'http://test-front.com/backstage/instance', }, }, - paths: ['app.baseUrl', 'backend.baseUrl'], - }, - ].forEach(item => { - item.paths.forEach(path => { - it('should NOT change the origin when the relevant urls are absolute', async () => { - await checkConfigValue( - item.data, - path, - path - .split('.') - .reduce( - (o, i) => o[i] as { [key: string]: object }, - item.data as { [key: string]: object }, - ) as unknown as string, - ); + ], + ])( + 'should be %p when %p', + async ([expectedAppUrl, expectedBackendUrl], data) => { + const app = new AppManager({ + apis: [], + defaultApis: [], + themes: [ + { + id: 'light', + title: 'Light Theme', + variant: 'light', + Provider: ({ children }) => <>{children}, + }, + ], + icons, + plugins: [], + components, + configLoader: async () => [ + { + context: 'test', + data, + }, + ], }); - }); - }); + + const Provider = app.getProvider(); + const ConfigDisplay = ({ configString }: { configString: string }) => { + const apiHolder = useApiHolder(); + const config = apiHolder.get(configApiRef); + return ( + + {configString}: {config?.getString(configString)} + + ); + }; + + const dom = await renderWithEffects( + + + + , + ); + + expect(dom.getByText(`app.baseUrl: ${expectedAppUrl}`)).toBeTruthy(); + + expect( + dom.getByText(`backend.baseUrl: ${expectedBackendUrl}`), + ).toBeTruthy(); + }, + ); }); }); diff --git a/packages/dev-utils/src/devApp/render.test.tsx b/packages/dev-utils/src/devApp/render.test.tsx index f4e90df33d..2da6ef370a 100644 --- a/packages/dev-utils/src/devApp/render.test.tsx +++ b/packages/dev-utils/src/devApp/render.test.tsx @@ -27,8 +27,7 @@ describe('DevAppBuilder', () => { { context: 'test', data: { - app: { title: 'Test App', baseUrl: 'http://localhost:3000' }, - backend: { baseUrl: 'http://localhost:7007' }, + app: { title: 'Test App' }, }, }, ]; diff --git a/packages/techdocs-cli-embedded-app/src/App.test.tsx b/packages/techdocs-cli-embedded-app/src/App.test.tsx index 59ed11bb93..8415388ca9 100644 --- a/packages/techdocs-cli-embedded-app/src/App.test.tsx +++ b/packages/techdocs-cli-embedded-app/src/App.test.tsx @@ -23,7 +23,6 @@ jest.mock('./config', () => ({ { data: { app: { title: 'Test', baseUrl: 'http://localhost:3000' }, - backend: { baseUrl: 'http://localhost:7007' }, techdocs: { storageUrl: 'http://localhost:7007/api/techdocs/static/docs', },