From a91c364097e334e57ab29cc2e6097e659b8f424d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 7 Sep 2023 13:19:01 +0200 Subject: [PATCH] fix flaky test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../PodExecTerminal/PodExecTerminal.test.tsx | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx b/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx index 00be5c453c..1c913a7726 100644 --- a/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx +++ b/plugins/kubernetes/src/components/PodExecTerminal/PodExecTerminal.test.tsx @@ -13,20 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import './matchMedia.mock'; -import '@testing-library/jest-dom'; import { DiscoveryApi, discoveryApiRef } from '@backstage/core-plugin-api'; import { - renderWithEffects, + renderInTestApp, TestApiProvider, textContentMatcher, - wrapInTestApp, } from '@backstage/test-utils'; -import { waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { screen } from '@testing-library/react'; import WS from 'jest-websocket-mock'; import React from 'react'; - +import './matchMedia.mock'; import { PodExecTerminal } from './PodExecTerminal'; const textEncoder = new TextEncoder(); @@ -42,22 +40,22 @@ describe('PodExecTerminal', () => { }; it('Should render an XTerm web terminal', async () => { - const { getByText } = await renderWithEffects( - wrapInTestApp( - - - , - ), + await renderInTestApp( + + + , ); - expect( - getByText(textContentMatcher('Starting terminal, please wait...')), - ).toBeInTheDocument(); + await expect( + screen.findByText( + textContentMatcher('Starting terminal, please wait...'), + ), + ).resolves.toBeInTheDocument(); }); it('Should connect to WebSocket server & render response', async () => { @@ -65,21 +63,21 @@ describe('PodExecTerminal', () => { 'ws://localhost/proxy/api/v1/namespaces/podNamespace/pods/pod1/exec?container=container2&stdin=true&stdout=true&stderr=true&tty=true&command=%2Fbin%2Fsh', ); - const { getByText } = await renderWithEffects( - wrapInTestApp( - - - , - ), + await renderInTestApp( + + + , ); // xterm uses a "W" character as a "measure element" -- if it exists, the terminal rendered correctly - expect(getByText(textContentMatcher('W'))).toBeInTheDocument(); + await expect( + screen.findByText(textContentMatcher('W')), + ).resolves.toBeInTheDocument(); await server.connected; @@ -90,8 +88,8 @@ describe('PodExecTerminal', () => { server.send(buffer); - await waitFor(() => - expect(getByText(textContentMatcher('hello world'))).toBeInTheDocument(), - ); + await expect( + screen.findByText(textContentMatcher('hello world')), + ).resolves.toBeInTheDocument(); }); });