From bc67fe43cdf6a60eeacae439d4093d3c7ea97e1e Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 30 Mar 2023 15:51:11 +0200 Subject: [PATCH] config-loader: StaticConfigSource tests + fix Signed-off-by: Patrik Oldsberg --- .../src/sources/StaticConfigSource.test.ts | 49 +++++++++++++++++++ .../src/sources/StaticConfigSource.ts | 1 - 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/config-loader/src/sources/StaticConfigSource.test.ts diff --git a/packages/config-loader/src/sources/StaticConfigSource.test.ts b/packages/config-loader/src/sources/StaticConfigSource.test.ts new file mode 100644 index 0000000000..e05ed85b15 --- /dev/null +++ b/packages/config-loader/src/sources/StaticConfigSource.test.ts @@ -0,0 +1,49 @@ +/* + * 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 { JsonObject } from '@backstage/types'; +import { StaticConfigSource } from './StaticConfigSource'; +import { readAll } from './__testUtils__/testUtils'; +import ZenObservable from 'zen-observable'; + +describe('StaticConfigSource', () => { + it('should be created from data', async () => { + const source = StaticConfigSource.create({ data: { a: 1 } }); + await expect(readAll(source)).resolves.toEqual([ + [{ data: { a: 1 }, context: 'static-config' }], + ]); + }); + + it('should be created from promise', async () => { + const source = StaticConfigSource.create({ + data: Promise.resolve({ a: 1 }), + }); + await expect(readAll(source)).resolves.toEqual([ + [{ data: { a: 1 }, context: 'static-config' }], + ]); + }); + + it('should be created from observable', async () => { + const source = StaticConfigSource.create({ + data: ZenObservable.of({ a: 1 }, { a: 2 }, { a: 3 }), + }); + await expect(readAll(source)).resolves.toEqual([ + [{ data: { a: 1 }, context: 'static-config' }], + [{ data: { a: 2 }, context: 'static-config' }], + [{ data: { a: 3 }, context: 'static-config' }], + ]); + }); +}); diff --git a/packages/config-loader/src/sources/StaticConfigSource.ts b/packages/config-loader/src/sources/StaticConfigSource.ts index 3cd5c0c028..cc1098198a 100644 --- a/packages/config-loader/src/sources/StaticConfigSource.ts +++ b/packages/config-loader/src/sources/StaticConfigSource.ts @@ -51,7 +51,6 @@ class StaticObservableConfigSource implements ConfigSource { deferred = simpleDefer(); }, complete() { - queue.length = 0; deferred.resolve(); }, });