backend-test-utils: review fixes

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-10 10:51:14 +01:00
parent 42abfb1b85
commit 1cedbc7d1b
10 changed files with 12 additions and 43 deletions
@@ -13,6 +13,7 @@ import { JsonObject } from '@backstage/types';
import { JsonValue } from '@backstage/types';
import { LoggerService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
import { ServiceMock } from '@backstage/backend-test-utils';
// @alpha (undocumented)
export function actionsRegistryServiceMock(options?: {
@@ -70,16 +71,5 @@ export class MockActionsRegistry
>(options: ActionsRegistryActionOptions<TInputSchema, TOutputSchema>): void;
}
// @public (undocumented)
export type ServiceMock<TService> = {
factory: ServiceFactory<TService>;
} & {
[Key in keyof TService]: TService[Key] extends (
...args: infer Args
) => infer Return
? TService[Key] & jest.MockInstance<Return, Args>
: TService[Key];
};
// (No @packageDocumentation comment for this package)
```
@@ -16,7 +16,7 @@
import { mockServices } from '../../services';
import { LoggerService } from '@backstage/backend-plugin-api';
import { MockActionsRegistry } from './MockActionsRegistry';
import { createServiceMock } from './simpleMock';
import { createServiceMock } from '@backstage/backend-test-utils';
import { actionsRegistryServiceRef } from '@backstage/backend-plugin-api/alpha';
import { actionsRegistryServiceFactory } from '@backstage/backend-defaults/alpha';
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createServiceMock } from './simpleMock';
import { createServiceMock } from '@backstage/backend-test-utils';
import { actionsServiceRef } from '@backstage/backend-plugin-api/alpha';
import { actionsServiceFactory } from '@backstage/backend-defaults/alpha';
@@ -17,4 +17,3 @@
export { actionsRegistryServiceMock } from './ActionsRegistryServiceMock';
export { MockActionsRegistry } from './MockActionsRegistry';
export { actionsServiceMock } from './ActionsServiceMock';
export { type ServiceMock } from './simpleMock';
@@ -1,20 +0,0 @@
/*
* Copyright 2025 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.
*/
export { createServiceMock } from '../../services/simpleMock';
/** @alpha */
export type { ServiceMock } from '../../services/simpleMock';
@@ -15,4 +15,4 @@
*/
export { mockServices } from './mockServices';
export { mockCredentials } from './mockCredentials';
export { createServiceMock, type ServiceMock } from './simpleMock';
export { createServiceMock, type ServiceMock } from './createServiceMock';
@@ -57,7 +57,7 @@ import { MockUserInfoService } from './MockUserInfoService';
import { mockCredentials } from './mockCredentials';
import { MockEventsService } from './MockEventsService';
import { MockPermissionsService } from './MockPermissionsService';
import { createServiceMock } from './simpleMock';
import { createServiceMock } from './createServiceMock';
import { MockSchedulerService } from './MockSchedulerService';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { ObservableConfigProxy } from '../../../config-loader/src/sources/ObservableConfigProxy';
@@ -21,7 +21,6 @@ import {
import { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils';
import { Entity } from '@backstage/catalog-model';
import { catalogServiceRef } from '@backstage/plugin-catalog-node';
// eslint-disable-next-line @backstage/no-undeclared-imports
import { createServiceMock } from '@backstage/backend-test-utils';
import { CatalogServiceMock } from './types';
+7 -6
View File
@@ -47,12 +47,13 @@ describe('gateway', () => {
},
});
const discovery = mockServices.discovery.mock();
discovery.getBaseUrl.mockImplementation(async (pluginId: string) => {
if (pluginId === 'external-plugin') {
return 'http://localhost:7778/api/external-plugin';
}
return `http://localhost:7777/api/${pluginId}`;
const discovery = mockServices.discovery.mock({
async getBaseUrl(pluginId) {
if (pluginId === 'external-plugin') {
return 'http://localhost:7778/api/external-plugin';
}
return `http://localhost:7777/api/${pluginId}`;
},
});
beforeAll(async () => {