backend-test-utils: update ServiceFactoryTester to not accept callback form

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-07-12 10:43:19 +02:00
parent 18b96b15ed
commit 906c817fd3
3 changed files with 12 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-test-utils': patch
---
Updated `ServiceFactoryTester` to only accept plain service factory objects, no longer supporting the callback form. This lines up with the changes to `@backstage/backend-plugin-api` and should not require any code changes.
+2 -4
View File
@@ -371,9 +371,7 @@ export namespace mockServices {
// @public
export class ServiceFactoryTester<TService, TScope extends 'root' | 'plugin'> {
static from<TService, TScope extends 'root' | 'plugin'>(
subject:
| ServiceFactory<TService, TScope>
| (() => ServiceFactory<TService, TScope>),
subject: ServiceFactory<TService, TScope>,
options?: ServiceFactoryTesterOptions,
): ServiceFactoryTester<TService, TScope>;
get(
@@ -387,7 +385,7 @@ export class ServiceFactoryTester<TService, TScope extends 'root' | 'plugin'> {
// @public
export interface ServiceFactoryTesterOptions {
dependencies?: Array<ServiceFactory | (() => ServiceFactory)>;
dependencies?: Array<ServiceFactory>;
}
// @public (undocumented)
@@ -35,7 +35,7 @@ export interface ServiceFactoryTesterOptions {
* If a service factory is provided for a service that already has a default
* implementation, the provided factory will override the default.
*/
dependencies?: Array<ServiceFactory | (() => ServiceFactory)>;
dependencies?: Array<ServiceFactory>;
}
/**
@@ -55,20 +55,15 @@ export class ServiceFactoryTester<TService, TScope extends 'root' | 'plugin'> {
* @returns A new tester instance for the provided subject.
*/
static from<TService, TScope extends 'root' | 'plugin'>(
subject:
| ServiceFactory<TService, TScope>
| (() => ServiceFactory<TService, TScope>),
subject: ServiceFactory<TService, TScope>,
options?: ServiceFactoryTesterOptions,
) {
const subjectFactory = typeof subject === 'function' ? subject() : subject;
const registry = ServiceRegistry.create([
...defaultServiceFactories,
...(options?.dependencies?.map(f =>
typeof f === 'function' ? f() : f,
) ?? []),
subjectFactory,
...(options?.dependencies ?? []),
subject,
]);
return new ServiceFactoryTester(subjectFactory.service, registry);
return new ServiceFactoryTester(subject.service, registry);
}
private constructor(