From 9bdc3e89ab4f5bc20815dfd3793d4897900d1622 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Tue, 11 Jun 2024 09:36:58 +0200 Subject: [PATCH] refactor: set extenstion point "t" to null Signed-off-by: Camila Belo --- .changeset/calm-files-sort.md | 5 +++++ packages/backend-plugin-api/src/wiring/factories.test.ts | 2 +- packages/backend-plugin-api/src/wiring/factories.ts | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/calm-files-sort.md diff --git a/.changeset/calm-files-sort.md b/.changeset/calm-files-sort.md new file mode 100644 index 0000000000..a487c00eb4 --- /dev/null +++ b/.changeset/calm-files-sort.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-plugin-api': patch +--- + +In tests, return `null` rather than throwing an error when trying to get the `ExtensionPoint.T` property, so that tests asserting the property are not easily broken. diff --git a/packages/backend-plugin-api/src/wiring/factories.test.ts b/packages/backend-plugin-api/src/wiring/factories.test.ts index 1fd05a1605..9f11c9b40b 100644 --- a/packages/backend-plugin-api/src/wiring/factories.test.ts +++ b/packages/backend-plugin-api/src/wiring/factories.test.ts @@ -26,7 +26,7 @@ describe('createExtensionPoint', () => { const extensionPoint = createExtensionPoint({ id: 'x' }); expect(extensionPoint).toBeDefined(); expect(extensionPoint.id).toBe('x'); - expect(() => extensionPoint.T).toThrow(); + expect(() => extensionPoint.T).not.toThrow(); expect(String(extensionPoint)).toBe('extensionPoint{x}'); }); }); diff --git a/packages/backend-plugin-api/src/wiring/factories.ts b/packages/backend-plugin-api/src/wiring/factories.ts index d0199e775a..5442bab897 100644 --- a/packages/backend-plugin-api/src/wiring/factories.ts +++ b/packages/backend-plugin-api/src/wiring/factories.ts @@ -51,6 +51,10 @@ export function createExtensionPoint( return { id: options.id, get T(): T { + if (process.env.NODE_ENV === 'test') { + // Avoid throwing errors so tests asserting extensions' properties cannot be easily broken + return null as T; + } throw new Error(`tried to read ExtensionPoint.T of ${this}`); }, toString() {