Merge pull request #25124 from backstage/camilaibs/nbs10-return-null-from-extension-point-t-prop

[NBS1.0] Set `ExtensionPoint.T` to null in realtime test environment
This commit is contained in:
Camila Belo
2024-06-11 14:17:55 +02:00
committed by GitHub
3 changed files with 10 additions and 1 deletions
+5
View File
@@ -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.
@@ -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}');
});
});
@@ -51,6 +51,10 @@ export function createExtensionPoint<T>(
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() {