From 326a9e40e10d5c740dbb9d8cf3230ed1a814026e Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 15 Nov 2023 13:43:33 +0100 Subject: [PATCH] frontend-test-utils: switch createExtensionTester render to be sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Co-authored-by: Camila Belo Co-authored-by: Philipp Hugenroth Signed-off-by: Patrik Oldsberg --- .../src/components/ExtensionBoundary.test.tsx | 10 +++------- packages/frontend-test-utils/api-report.md | 2 +- .../src/app/createExtensionTester.test.tsx | 8 ++++---- .../src/app/createExtensionTester.ts | 2 +- plugins/search-react/src/alpha.test.tsx | 2 +- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/frontend-plugin-api/src/components/ExtensionBoundary.test.tsx b/packages/frontend-plugin-api/src/components/ExtensionBoundary.test.tsx index 483280dc3b..88bdcc6617 100644 --- a/packages/frontend-plugin-api/src/components/ExtensionBoundary.test.tsx +++ b/packages/frontend-plugin-api/src/components/ExtensionBoundary.test.tsx @@ -54,9 +54,7 @@ describe('ExtensionBoundary', () => { const TextComponent = () => { return

{text}

; }; - await createExtensionTester( - wrapInBoundaryExtension(), - ).render(); + createExtensionTester(wrapInBoundaryExtension()).render(); await waitFor(() => expect(screen.getByText(text)).toBeInTheDocument()); }); @@ -65,9 +63,7 @@ describe('ExtensionBoundary', () => { const ErrorComponent = () => { throw new Error(error); }; - await createExtensionTester( - wrapInBoundaryExtension(), - ).render(); + createExtensionTester(wrapInBoundaryExtension()).render(); await waitFor(() => expect(screen.getByText(error)).toBeInTheDocument()); }); @@ -84,7 +80,7 @@ describe('ExtensionBoundary', () => { return null; }; - await createExtensionTester( + createExtensionTester( wrapInBoundaryExtension( diff --git a/packages/frontend-test-utils/api-report.md b/packages/frontend-test-utils/api-report.md index c5afb3204d..2703efa228 100644 --- a/packages/frontend-test-utils/api-report.md +++ b/packages/frontend-test-utils/api-report.md @@ -25,7 +25,7 @@ export class ExtensionTester { }, ): ExtensionTester; // (undocumented) - render(options?: { config?: JsonObject }): Promise; + render(options?: { config?: JsonObject }): RenderResult; } // (No @packageDocumentation comment for this package) diff --git a/packages/frontend-test-utils/src/app/createExtensionTester.test.tsx b/packages/frontend-test-utils/src/app/createExtensionTester.test.tsx index 2c08b31837..946dd3cb0c 100644 --- a/packages/frontend-test-utils/src/app/createExtensionTester.test.tsx +++ b/packages/frontend-test-utils/src/app/createExtensionTester.test.tsx @@ -24,7 +24,7 @@ import { createExtensionTester } from './createExtensionTester'; describe('createExtensionTester', () => { it('should render a simple extension', async () => { - await createExtensionTester( + createExtensionTester( createExtension({ id: 'test', attachTo: { id: 'ignored', input: 'ignored' }, @@ -37,7 +37,7 @@ describe('createExtensionTester', () => { }); it('should render an extension even if disabled by default', async () => { - await createExtensionTester( + createExtensionTester( createExtension({ id: 'test', attachTo: { id: 'ignored', input: 'ignored' }, @@ -51,7 +51,7 @@ describe('createExtensionTester', () => { }); it("should fail to render an extension that doesn't output a react element", async () => { - await expect( + expect(() => createExtensionTester( createExtension({ id: 'test', @@ -61,7 +61,7 @@ describe('createExtensionTester', () => { factory: () => ({ path: '/foo' }), }), ).render(), - ).rejects.toThrow( + ).toThrow( "Failed to instantiate extension 'core', input 'root' did not receive required extension data 'core.reactElement' from extension 'test'", ); }); diff --git a/packages/frontend-test-utils/src/app/createExtensionTester.ts b/packages/frontend-test-utils/src/app/createExtensionTester.ts index c2d14d6a06..34833dfc69 100644 --- a/packages/frontend-test-utils/src/app/createExtensionTester.ts +++ b/packages/frontend-test-utils/src/app/createExtensionTester.ts @@ -49,7 +49,7 @@ export class ExtensionTester { return this; } - async render(options?: { config?: JsonObject }): Promise { + render(options?: { config?: JsonObject }): RenderResult { const { config = {} } = options ?? {}; const [subject, ...rest] = this.#extensions; diff --git a/plugins/search-react/src/alpha.test.tsx b/plugins/search-react/src/alpha.test.tsx index 102ad35cb3..e1a8166390 100644 --- a/plugins/search-react/src/alpha.test.tsx +++ b/plugins/search-react/src/alpha.test.tsx @@ -147,7 +147,7 @@ describe('createSearchResultListItemExtension', () => { }, }); - await createExtensionTester(SearchPageExtension) + createExtensionTester(SearchPageExtension) .add(TechDocsSearchResultItemExtension, { // TODO(Rugvip): We need to make the config input type available for use here config: {