From 82ee006c089315a2c4320c4249839eb70f523c1d Mon Sep 17 00:00:00 2001 From: Hweinstock <42325418+Hweinstock@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:15:51 -0500 Subject: [PATCH] test(appcomposer): fix initMessageHandler flaky test. (#5973) ## Problem See issue: https://github.com/aws/aws-toolkit-vscode/issues/5970 ## Solution appears to be similar to https://github.com/aws/aws-toolkit-vscode/pull/5955, so same solution is employed. - skip test if below 1.89 vscode version. - add helper function `skipIfVscodeBelow` for tests that are flaky on previous versions. --- License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --- packages/core/src/shared/vscode/env.ts | 6 +++--- .../messageHandlers/generateResourceHandler.test.ts | 4 ++-- .../messageHandlers/initMessageHandler.test.ts | 8 ++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/core/src/shared/vscode/env.ts b/packages/core/src/shared/vscode/env.ts index 7001ae6eadb..952284b6e2c 100644 --- a/packages/core/src/shared/vscode/env.ts +++ b/packages/core/src/shared/vscode/env.ts @@ -67,10 +67,10 @@ export { extensionVersion } * * @param throwWhen Throw if minimum vscode is equal or later than this version. */ -export function isMinVscode(throwWhen?: string): boolean { +export function isMinVscode(options?: { throwWhen: string }): boolean { const minVscode = getMinVscodeVersion() - if (throwWhen && semver.gte(minVscode, throwWhen)) { - throw Error(`Min vscode ${minVscode} >= ${throwWhen}. Delete or update the code that called this.`) + if (options?.throwWhen && semver.gte(minVscode, options.throwWhen)) { + throw Error(`Min vscode ${minVscode} >= ${options.throwWhen}. Delete or update the code that called this.`) } return vscode.version.startsWith(getMinVscodeVersion()) } diff --git a/packages/core/src/test/applicationcomposer/messageHandlers/generateResourceHandler.test.ts b/packages/core/src/test/applicationcomposer/messageHandlers/generateResourceHandler.test.ts index 3521f777379..72a3a03e15d 100644 --- a/packages/core/src/test/applicationcomposer/messageHandlers/generateResourceHandler.test.ts +++ b/packages/core/src/test/applicationcomposer/messageHandlers/generateResourceHandler.test.ts @@ -8,11 +8,11 @@ import sinon from 'sinon' import { createTemplate, createWebviewContext } from '../utils' import { generateResourceHandler } from '../../../applicationcomposer/messageHandlers/generateResourceHandler' import { Command, MessageType } from '../../../applicationcomposer/types' -import * as env from '../../../shared/vscode/env' +import { isMinVscode } from '../../../shared/vscode/env' describe('generateResourceHandler', function () { it('amazon q is not installed', async function () { - if (env.isMinVscode('1.89.0')) { + if (isMinVscode({ throwWhen: '1.89.0' })) { this.skip() } const panel = await createTemplate() diff --git a/packages/core/src/test/applicationcomposer/messageHandlers/initMessageHandler.test.ts b/packages/core/src/test/applicationcomposer/messageHandlers/initMessageHandler.test.ts index b47d4ab9d68..8c2013a2da6 100644 --- a/packages/core/src/test/applicationcomposer/messageHandlers/initMessageHandler.test.ts +++ b/packages/core/src/test/applicationcomposer/messageHandlers/initMessageHandler.test.ts @@ -7,13 +7,17 @@ import assert from 'assert' import sinon from 'sinon' import { initMessageHandler } from '../../../applicationcomposer/messageHandlers/initMessageHandler' import { createTemplate, createWebviewContext } from '../utils' +import { isMinVscode } from '../../../shared/vscode/env' describe('initMessageHandler', function () { - afterEach(() => { + afterEach(function () { sinon.restore() }) - it('not connected to codewhisperer', async () => { + it('not connected to codewhisperer', async function () { + if (isMinVscode({ throwWhen: '1.89.0' })) { + this.skip() + } const panel = await createTemplate() const postMessageSpy = sinon.spy(panel.webview, 'postMessage') const context = await createWebviewContext({