backend-test-utils: refactor to export mockServices and mockFactories
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
```ts
|
||||
import { Backend } from '@backstage/backend-app-api';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ConfigService } from '@backstage/backend-plugin-api';
|
||||
import { ExtendedHttpServer } from '@backstage/backend-app-api';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
@@ -17,13 +18,25 @@ import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
export function isDockerDisabledForTests(): boolean;
|
||||
|
||||
// @alpha (undocumented)
|
||||
export const mockConfigFactory: (
|
||||
options?:
|
||||
| {
|
||||
data?: JsonObject | undefined;
|
||||
}
|
||||
| undefined,
|
||||
) => ServiceFactory<ConfigService>;
|
||||
export namespace mockFactories {
|
||||
const // (undocumented)
|
||||
config: (
|
||||
options?: mockServices.config.Options | undefined,
|
||||
) => ServiceFactory<ConfigService>;
|
||||
}
|
||||
|
||||
// @alpha (undocumented)
|
||||
export namespace mockServices {
|
||||
// (undocumented)
|
||||
export namespace config {
|
||||
// (undocumented)
|
||||
export type Options = {
|
||||
data?: JsonObject;
|
||||
};
|
||||
}
|
||||
// (undocumented)
|
||||
export function config(options?: config.Options): ConfigReader;
|
||||
}
|
||||
|
||||
// @public
|
||||
export function setupRequestMockHandlers(worker: {
|
||||
|
||||
@@ -13,4 +13,5 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { mockConfigFactory } from './mockConfigService';
|
||||
export { mockFactories } from './mockFactories';
|
||||
export { mockServices } from './mockServices';
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2023 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.
|
||||
*/
|
||||
|
||||
import {
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { mockServices } from './mockServices';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export namespace mockFactories {
|
||||
export const config = createServiceFactory(
|
||||
(options?: mockServices.config.Options) => ({
|
||||
service: coreServices.config,
|
||||
deps: {},
|
||||
async factory() {
|
||||
return mockServices.config(options);
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
+13
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
* Copyright 2023 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.
|
||||
@@ -14,20 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/** @alpha */
|
||||
export const mockConfigFactory = createServiceFactory(
|
||||
(options?: { data?: JsonObject }) => ({
|
||||
service: coreServices.config,
|
||||
deps: {},
|
||||
async factory() {
|
||||
return new ConfigReader(options?.data, 'mock-config');
|
||||
},
|
||||
}),
|
||||
);
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export namespace mockServices {
|
||||
export namespace config {
|
||||
export type Options = { data?: JsonObject };
|
||||
}
|
||||
|
||||
export function config(options?: config.Options) {
|
||||
return new ConfigReader(options?.data, 'mock-config');
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
coreServices,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
import { mockConfigFactory } from '../implementations/mockConfigService';
|
||||
import { mockFactories } from '../implementations';
|
||||
import { mockRootLoggerService } from '../implementations/mockRootLoggerService';
|
||||
import { mockTokenManagerFactory } from '../implementations/mockTokenManagerService';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
@@ -89,7 +89,7 @@ const defaultServiceFactories = [
|
||||
httpRouterFactory(),
|
||||
lifecycleFactory(),
|
||||
loggerFactory(),
|
||||
mockConfigFactory(),
|
||||
mockFactories.config(),
|
||||
mockRootLoggerService(),
|
||||
mockIdentityFactory(),
|
||||
mockTokenManagerFactory(),
|
||||
|
||||
Reference in New Issue
Block a user