Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +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 { disableIfVscodeBelow } from '../../testUtil'

describe('generateResourceHandler', function () {
it('amazon q is not installed', async function () {
if (env.isMinVscode('1.89.0')) {
this.skip()
}
disableIfVscodeBelow(this, '1.89.0')
const panel = await createTemplate()
const postMessageSpy = sinon.spy(panel.webview, 'postMessage')
const context = await createWebviewContext({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import assert from 'assert'
import sinon from 'sinon'
import { initMessageHandler } from '../../../applicationcomposer/messageHandlers/initMessageHandler'
import { createTemplate, createWebviewContext } from '../utils'
import { disableIfVscodeBelow } from '../../testUtil'

describe('initMessageHandler', function () {
afterEach(() => {
sinon.restore()
})

it('not connected to codewhisperer', async () => {
it('not connected to codewhisperer', async function () {
disableIfVscodeBelow(this, '1.89.0')
const panel = await createTemplate()
const postMessageSpy = sinon.spy(panel.webview, 'postMessage')
const context = await createWebviewContext({
Expand All @@ -22,5 +20,6 @@ describe('initMessageHandler', function () {
await initMessageHandler(context)
assert.ok(postMessageSpy.calledOnce)
assert.deepStrictEqual(postMessageSpy.getCall(0).args[0].isConnectedToCodeWhisperer, false)
postMessageSpy.restore()
})
})
7 changes: 7 additions & 0 deletions packages/core/src/test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { mkdirSync, existsSync } from 'fs' // eslint-disable-line no-restricted-
import { randomBytes } from 'crypto'
import request from '../shared/request'
import { stub } from 'sinon'
import { isMinVscode } from '../shared/vscode/env'

const testTempDirs: string[] = []

Expand Down Expand Up @@ -634,3 +635,9 @@ export function getFetchStubWithResponse(response: Partial<Response>) {
export function copyEnv(): NodeJS.ProcessEnv {
return { ...process.env }
}

export function disableIfVscodeBelow(testContext: Mocha.Context, version: string) {
if (isMinVscode(version)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really correct. isMinVscode checks if the current vscode is the min version.

The version arg is only relevant for when we bump the min version. It's unrelated to the check itself.

Copy link
Contributor

@justinmk3 justinmk3 Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isMinVscode might be less confusing if we change its argument to be dict-like:

if (isMinVscode({ throwIfMinGte = version })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I was assuming this cutoff version could only be below the stable/insider versions, which isn't correct. I went ahead and avoided using isMinVscode altogether so that this function can be used more generally.

testContext.skip()
}
}
Loading