backstage

Форк
0
/
CreateBackend.test.ts 
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

17
import {
18
  coreServices,
19
  createServiceFactory,
20
} from '@backstage/backend-plugin-api';
21
import { createBackend } from './CreateBackend';
22

23
describe('createBackend', () => {
24
  it('should not throw when overriding a default service implementation', async () => {
25
    const backend = createBackend();
26

27
    backend.add(
28
      createServiceFactory({
29
        service: coreServices.rootConfig,
30
        deps: {},
31
        factory(): never {
32
          throw new Error('NOPE');
33
        },
34
      }),
35
    );
36

37
    // We expect the service factory error to be thrown, rather than any earlier validation
38
    await expect(backend.start()).rejects.toThrow('NOPE');
39
  });
40

41
  it('should throw on duplicate service implementations', async () => {
42
    const backend = createBackend();
43

44
    backend.add(
45
      createServiceFactory({
46
        service: coreServices.rootLifecycle,
47
        deps: {},
48
        factory: async () => ({
49
          addStartupHook: () => {},
50
          addShutdownHook: () => {},
51
        }),
52
      }),
53
    );
54
    backend.add(
55
      createServiceFactory({
56
        service: coreServices.rootLifecycle,
57
        deps: {},
58
        factory: async () => ({
59
          addStartupHook: () => {},
60
          addShutdownHook: () => {},
61
        }),
62
      }),
63
    );
64

65
    await expect(backend.start()).rejects.toThrow(
66
      'Duplicate service implementations provided for core.rootLifecycle',
67
    );
68
  });
69

70
  it('should throw when providing a plugin metadata service implementation', async () => {
71
    const backend = createBackend();
72
    backend.add(
73
      createServiceFactory({
74
        service: coreServices.pluginMetadata,
75
        deps: {},
76
        factory: () => ({ getId: () => 'test' }),
77
      }),
78
    );
79

80
    await expect(backend.start()).rejects.toThrow(
81
      'The core.pluginMetadata service cannot be overridden',
82
    );
83
  });
84
});
85

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.