From f1e08f7dd8917bd382111667159e014b3a5cfcf2 Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 28 Aug 2024 08:52:27 +0200 Subject: [PATCH] chore: created a frontend module Signed-off-by: blam --- .../src/wiring/createFrontendModule.test.ts | 62 +++++++++++++++++++ .../src/wiring/createFrontendModule.ts | 4 +- .../frontend-plugin-api/src/wiring/index.ts | 2 +- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 packages/frontend-plugin-api/src/wiring/createFrontendModule.test.ts diff --git a/packages/frontend-plugin-api/src/wiring/createFrontendModule.test.ts b/packages/frontend-plugin-api/src/wiring/createFrontendModule.test.ts new file mode 100644 index 0000000000..d895f6de0f --- /dev/null +++ b/packages/frontend-plugin-api/src/wiring/createFrontendModule.test.ts @@ -0,0 +1,62 @@ +/* + * Copyright 2024 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 } from './createExtension'; +import { createFrontendModule } from './createFrontendModule'; + +describe('createFrontendModule', () => { + it('should create a frontend module', () => { + expect( + createFrontendModule({ + pluginId: 'test', + extensions: [ + createExtension({ + kind: 'route', + name: 'test', + output: [], + attachTo: { id: 'ignored', input: 'ignored' }, + factory: () => [], + }), + ], + }), + ).toMatchInlineSnapshot(` + { + "$$type": "@backstage/FrontendModule", + "extensions": [ + { + "$$type": "@backstage/Extension", + "T": undefined, + "attachTo": { + "id": "ignored", + "input": "ignored", + }, + "configSchema": undefined, + "disabled": false, + "factory": [Function], + "id": "route:test/test", + "inputs": {}, + "output": [], + "toString": [Function], + "version": "v2", + }, + ], + "featureFlags": [], + "pluginId": "test", + "toString": [Function], + "version": "v1", + } + `); + }); +}); diff --git a/packages/frontend-plugin-api/src/wiring/createFrontendModule.ts b/packages/frontend-plugin-api/src/wiring/createFrontendModule.ts index ae444cb152..15e195f56d 100644 --- a/packages/frontend-plugin-api/src/wiring/createFrontendModule.ts +++ b/packages/frontend-plugin-api/src/wiring/createFrontendModule.ts @@ -26,7 +26,7 @@ import { import { FeatureFlagConfig } from './types'; /** @public */ -export interface ModuleOptions< +export interface FrontendModuleOptions< TPluginId extends string, TExtensions extends readonly ExtensionDefinition[], > { @@ -52,7 +52,7 @@ export interface InternalFrontendModule extends FrontendModule { export function createFrontendModule< TId extends string, TExtensions extends readonly ExtensionDefinition[] = [], ->(options: ModuleOptions): FrontendModule { +>(options: FrontendModuleOptions): FrontendModule { const { pluginId } = options; const extensions = new Array>(); diff --git a/packages/frontend-plugin-api/src/wiring/index.ts b/packages/frontend-plugin-api/src/wiring/index.ts index 4954d8e72d..5cbeeb3c24 100644 --- a/packages/frontend-plugin-api/src/wiring/index.ts +++ b/packages/frontend-plugin-api/src/wiring/index.ts @@ -46,7 +46,7 @@ export { export { createFrontendModule, type FrontendModule, - type ModuleOptions, + type FrontendModuleOptions, } from './createFrontendModule'; export { createExtensionOverrides,