From 8f16117831f7e527ec8ff54e7fcd8831e22e20f0 Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Tue, 17 Jun 2025 13:51:59 +0200 Subject: [PATCH 1/4] chore: fix backend-test-utils changeset Signed-off-by: benjdlambert --- .changeset/sweet-ducks-wait.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.changeset/sweet-ducks-wait.md b/.changeset/sweet-ducks-wait.md index 4792fafe84..35f2ddd1e9 100644 --- a/.changeset/sweet-ducks-wait.md +++ b/.changeset/sweet-ducks-wait.md @@ -2,4 +2,29 @@ '@backstage/backend-test-utils': minor --- -Added mock implementations for `ActionsService` and `ActionsRegistryService` +Added an `actionsRegistryServiceMock` and `actionsServiceMock` to `/alpha` export for the experimental services. + +This allows you to write tests for your actions by doing something similar to the following: + +```ts +import { actionsRegistryServiceMock } from '@backstage/backend-test-utils/alpha`; + +const mockActionsRegistry = actionsRegistryServiceMock(); +const mockCatalog = catalogServiceMock({ + entities: [ + ... + ], +}); + +createGetCatalogEntityAction({ + catalog: mockCatalog, + actionsRegistry: mockActionsRegistry, +}); + +await expect( + mockActionsRegistry.invoke({ + id: 'test:get-catalog-entity', + input: { name: 'test' }, + }), +).resolves.toEqual(...) +``` From 46b2794c631299de3710c80508bea5b50e67e27f Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Tue, 17 Jun 2025 13:56:36 +0200 Subject: [PATCH 2/4] chore: update the backend-plugin-api changeset Signed-off-by: benjdlambert --- .changeset/wet-bars-report.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.changeset/wet-bars-report.md b/.changeset/wet-bars-report.md index d556f6cc61..019f1f2f6c 100644 --- a/.changeset/wet-bars-report.md +++ b/.changeset/wet-bars-report.md @@ -2,4 +2,30 @@ '@backstage/backend-plugin-api': minor --- -Added `coreServices.actionsRegistry` and `coreServices.actions` to allow registration of distributed actions from plugins, and the ability to invoke these actions +Added `actionsRegistry` and `actions` experimental services to `/alpha` to allow registration of distributed actions from plugins, and the ability to invoke these actions. You can use these services by including them like the following: + +```ts +import { + actionsRegistryServiceRef, + actionsServiceRef, +} from '@backstage/backend-plugin-api/alpha'; + +createBackendPlugin({ + pluginId: 'test-plugin', + register({ registerInit }) { + registerInit({ + deps: { + actions: actionsServiceRef, + actionsRegistry: actionsRegistryServiceRef, + }, + async init({ actions, actionsRegistry }) { + actionsRegistry.register({ + ..., + }); + + await actions.invoke(...); + }, + }); + }, +}); +``` From ef91ae8283e9b240e0da60cd4ff22d8942c9c825 Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Tue, 17 Jun 2025 13:57:23 +0200 Subject: [PATCH 3/4] chore: fixing changesets Signed-off-by: benjdlambert --- .changeset/wet-bars-reporting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wet-bars-reporting.md b/.changeset/wet-bars-reporting.md index 7dc66cb280..2bcf4f502e 100644 --- a/.changeset/wet-bars-reporting.md +++ b/.changeset/wet-bars-reporting.md @@ -2,4 +2,4 @@ '@backstage/backend-defaults': patch --- -Added some default implementations for the `ActionsService` and `ActionsRegistryService` that allow registration of actions for a particular plugin. +Added some default implementations for the experimental `ActionsService` and `ActionsRegistryService` under `/alpha` that allow registration of actions for a particular plugin. From 4ed459eabf18652ea4d7d6466476504f096296d8 Mon Sep 17 00:00:00 2001 From: benjdlambert Date: Tue, 17 Jun 2025 14:10:39 +0200 Subject: [PATCH 4/4] chore: fix issue with formatting Signed-off-by: benjdlambert --- .changeset/sweet-ducks-wait.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/sweet-ducks-wait.md b/.changeset/sweet-ducks-wait.md index 35f2ddd1e9..8555f4785e 100644 --- a/.changeset/sweet-ducks-wait.md +++ b/.changeset/sweet-ducks-wait.md @@ -7,7 +7,7 @@ Added an `actionsRegistryServiceMock` and `actionsServiceMock` to `/alpha` expor This allows you to write tests for your actions by doing something similar to the following: ```ts -import { actionsRegistryServiceMock } from '@backstage/backend-test-utils/alpha`; +import { actionsRegistryServiceMock } from '@backstage/backend-test-utils/alpha'; const mockActionsRegistry = actionsRegistryServiceMock(); const mockCatalog = catalogServiceMock({