backstage
84 строки · 2.4 Кб
1/*
2* Copyright 2023 The Backstage Authors
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17import {
18coreServices,
19createServiceFactory,
20} from '@backstage/backend-plugin-api';
21import { createBackend } from './CreateBackend';
22
23describe('createBackend', () => {
24it('should not throw when overriding a default service implementation', async () => {
25const backend = createBackend();
26
27backend.add(
28createServiceFactory({
29service: coreServices.rootConfig,
30deps: {},
31factory(): never {
32throw new Error('NOPE');
33},
34}),
35);
36
37// We expect the service factory error to be thrown, rather than any earlier validation
38await expect(backend.start()).rejects.toThrow('NOPE');
39});
40
41it('should throw on duplicate service implementations', async () => {
42const backend = createBackend();
43
44backend.add(
45createServiceFactory({
46service: coreServices.rootLifecycle,
47deps: {},
48factory: async () => ({
49addStartupHook: () => {},
50addShutdownHook: () => {},
51}),
52}),
53);
54backend.add(
55createServiceFactory({
56service: coreServices.rootLifecycle,
57deps: {},
58factory: async () => ({
59addStartupHook: () => {},
60addShutdownHook: () => {},
61}),
62}),
63);
64
65await expect(backend.start()).rejects.toThrow(
66'Duplicate service implementations provided for core.rootLifecycle',
67);
68});
69
70it('should throw when providing a plugin metadata service implementation', async () => {
71const backend = createBackend();
72backend.add(
73createServiceFactory({
74service: coreServices.pluginMetadata,
75deps: {},
76factory: () => ({ getId: () => 'test' }),
77}),
78);
79
80await expect(backend.start()).rejects.toThrow(
81'The core.pluginMetadata service cannot be overridden',
82);
83});
84});
85