Skip to content

Commit 82ee006

Browse files
authored
test(appcomposer): fix initMessageHandler flaky test. (#5973)
## Problem See issue: #5970 ## Solution appears to be similar to #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. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 9a41a03 commit 82ee006

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

packages/core/src/shared/vscode/env.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export { extensionVersion }
6767
*
6868
* @param throwWhen Throw if minimum vscode is equal or later than this version.
6969
*/
70-
export function isMinVscode(throwWhen?: string): boolean {
70+
export function isMinVscode(options?: { throwWhen: string }): boolean {
7171
const minVscode = getMinVscodeVersion()
72-
if (throwWhen && semver.gte(minVscode, throwWhen)) {
73-
throw Error(`Min vscode ${minVscode} >= ${throwWhen}. Delete or update the code that called this.`)
72+
if (options?.throwWhen && semver.gte(minVscode, options.throwWhen)) {
73+
throw Error(`Min vscode ${minVscode} >= ${options.throwWhen}. Delete or update the code that called this.`)
7474
}
7575
return vscode.version.startsWith(getMinVscodeVersion())
7676
}

packages/core/src/test/applicationcomposer/messageHandlers/generateResourceHandler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import sinon from 'sinon'
88
import { createTemplate, createWebviewContext } from '../utils'
99
import { generateResourceHandler } from '../../../applicationcomposer/messageHandlers/generateResourceHandler'
1010
import { Command, MessageType } from '../../../applicationcomposer/types'
11-
import * as env from '../../../shared/vscode/env'
11+
import { isMinVscode } from '../../../shared/vscode/env'
1212

1313
describe('generateResourceHandler', function () {
1414
it('amazon q is not installed', async function () {
15-
if (env.isMinVscode('1.89.0')) {
15+
if (isMinVscode({ throwWhen: '1.89.0' })) {
1616
this.skip()
1717
}
1818
const panel = await createTemplate()

packages/core/src/test/applicationcomposer/messageHandlers/initMessageHandler.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import assert from 'assert'
77
import sinon from 'sinon'
88
import { initMessageHandler } from '../../../applicationcomposer/messageHandlers/initMessageHandler'
99
import { createTemplate, createWebviewContext } from '../utils'
10+
import { isMinVscode } from '../../../shared/vscode/env'
1011

1112
describe('initMessageHandler', function () {
12-
afterEach(() => {
13+
afterEach(function () {
1314
sinon.restore()
1415
})
1516

16-
it('not connected to codewhisperer', async () => {
17+
it('not connected to codewhisperer', async function () {
18+
if (isMinVscode({ throwWhen: '1.89.0' })) {
19+
this.skip()
20+
}
1721
const panel = await createTemplate()
1822
const postMessageSpy = sinon.spy(panel.webview, 'postMessage')
1923
const context = await createWebviewContext({

0 commit comments

Comments
 (0)