diff --git a/.changeset/sweet-cows-clean.md b/.changeset/sweet-cows-clean.md new file mode 100644 index 0000000000..fa2004186e --- /dev/null +++ b/.changeset/sweet-cows-clean.md @@ -0,0 +1,5 @@ +--- +'@backstage/frontend-test-utils': patch +--- + +Added the ability to provide additional `extensions` and `features` to `renderInTestApp` diff --git a/packages/frontend-test-utils/api-report.md b/packages/frontend-test-utils/api-report.md index 31e293e434..ba4b8aae2b 100644 --- a/packages/frontend-test-utils/api-report.md +++ b/packages/frontend-test-utils/api-report.md @@ -14,6 +14,7 @@ import { ErrorWithContext } from '@backstage/test-utils'; import { ExtensionDataRef } from '@backstage/frontend-plugin-api'; import { ExtensionDefinition } from '@backstage/frontend-plugin-api'; import { ExtensionDefinitionParameters } from '@backstage/frontend-plugin-api'; +import { FrontendFeature } from '@backstage/frontend-plugin-api'; import { JsonObject } from '@backstage/types'; import { MockConfigApi } from '@backstage/test-utils'; import { MockErrorApi } from '@backstage/test-utils'; @@ -134,6 +135,8 @@ export type TestAppOptions = { [path: string]: RouteRef; }; config?: JsonObject; + extensions?: ExtensionDefinition[]; + features?: FrontendFeature[]; }; export { withLogCollector }; diff --git a/packages/frontend-test-utils/src/app/renderInTestApp.tsx b/packages/frontend-test-utils/src/app/renderInTestApp.tsx index a9275071b4..cc919f3f3d 100644 --- a/packages/frontend-test-utils/src/app/renderInTestApp.tsx +++ b/packages/frontend-test-utils/src/app/renderInTestApp.tsx @@ -31,6 +31,7 @@ import { IconComponent, RouterBlueprint, NavItemBlueprint, + FrontendFeature, } from '@backstage/frontend-plugin-api'; /** @@ -60,6 +61,16 @@ export type TestAppOptions = { * Additional configuration passed to the app when rendering elements inside it. */ config?: JsonObject; + + /** + * Additional extensions to add to the test app. + */ + extensions?: ExtensionDefinition[]; + + /** + * Additional features to add to the test app. + */ + features?: FrontendFeature[]; }; const NavItem = (props: { @@ -167,12 +178,22 @@ export function renderInTestApp( } } + if (options?.extensions) { + extensions.push(...options.extensions); + } + + const features: FrontendFeature[] = [ + createExtensionOverrides({ + extensions, + }), + ]; + + if (options?.features) { + features.push(...options.features); + } + const app = createSpecializedApp({ - features: [ - createExtensionOverrides({ - extensions, - }), - ], + features, config: ConfigReader.fromConfigs([ { context: 'render-config', data: options?.config ?? {} }, ]),