diff --git a/.changeset/rude-fireants-accept.md b/.changeset/rude-fireants-accept.md new file mode 100644 index 0000000000..0b543eddb2 --- /dev/null +++ b/.changeset/rude-fireants-accept.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-plugin-api': patch +--- + +Add a `toJSON` on refs so that they can appear in expectations in jest tests diff --git a/packages/backend-plugin-api/src/services/system/types.ts b/packages/backend-plugin-api/src/services/system/types.ts index a14e388bd0..7e4b78b5a1 100644 --- a/packages/backend-plugin-api/src/services/system/types.ts +++ b/packages/backend-plugin-api/src/services/system/types.ts @@ -17,7 +17,9 @@ import { BackendFeature } from '../../types'; /** - * TODO + * A reference to a backend service. You can use these references to mark + * dependencies on services and having their implementations injected + * automatically. * * @public */ @@ -39,6 +41,11 @@ export type ServiceRef< */ scope: TScope; + /** + * Marks whether the service is a multiton or not. Multiton services the + * opposite of singletons - they can be provided many times, and when depended + * on, you receive an array of all provided instances. + */ multiton?: TInstances extends 'multiton' ? true : false; /** @@ -142,6 +149,15 @@ export function createServiceRef< toString() { return `serviceRef{${options.id}}`; }, + toJSON() { + // This avoids accidental calls to T happening e.g. in tests + return { + $$type: '@backstage/ServiceRef', + id, + scope, + multiton, + }; + }, $$type: '@backstage/ServiceRef', __defaultFactory: defaultFactory, } as ServiceRef & {