diff --git a/packages/frontend-app-api/package.json b/packages/frontend-app-api/package.json index 772dd62a36..7cd4557ea1 100644 --- a/packages/frontend-app-api/package.json +++ b/packages/frontend-app-api/package.json @@ -24,6 +24,7 @@ }, "devDependencies": { "@backstage/cli": "workspace:^", + "@backstage/test-utils": "workspace:^", "@testing-library/jest-dom": "^5.10.1" }, "configSchema": "config.d.ts", diff --git a/packages/frontend-app-api/src/wiring/createApp.test.tsx b/packages/frontend-app-api/src/wiring/createApp.test.tsx new file mode 100644 index 0000000000..a2f42257f0 --- /dev/null +++ b/packages/frontend-app-api/src/wiring/createApp.test.tsx @@ -0,0 +1,66 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createExtension, createPlugin } from '@backstage/frontend-plugin-api'; +import { createInstances } from './createApp'; + +import { MockConfigApi } from '@backstage/test-utils'; + +describe('createInstances', () => { + it('throws an error when a root extension is overridden', () => { + const config = new MockConfigApi({ + app: { + extensions: [ + { + root: { + at: '', + }, + }, + ], + }, + }); + const plugins = [ + createPlugin({ + id: 'plugin', + extensions: [], + }), + ]; + expect(() => createInstances({ config, plugins })).toThrow( + 'There is a root extension in the app config file and root extensions are not configurable', + ); + }); + + it('throws an error when cyclical dependencies are found', () => { + const config = new MockConfigApi({}); + const plugins = [ + createPlugin({ + id: 'plugin', + extensions: [ + createExtension({ + id: 'root', + at: 'core.routes/route', + inputs: {}, + output: {}, + factory() {}, + }), + ], + }), + ]; + expect(() => createInstances({ config, plugins })).toThrow( + 'There is a cyclical dependency with the extension "core.layout": core.layout → core.routes → root → core.layout', + ); + }); +}); diff --git a/yarn.lock b/yarn.lock index 0d7896d082..9cb61d15f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4213,6 +4213,7 @@ __metadata: "@backstage/core-plugin-api": "workspace:^" "@backstage/frontend-plugin-api": "workspace:^" "@backstage/plugin-graphiql": "workspace:^" + "@backstage/test-utils": "workspace:^" "@backstage/types": "workspace:^" "@material-ui/core": ^4.12.4 "@testing-library/jest-dom": ^5.10.1