Skip to content

Commit 068241a

Browse files
committed
use dict version of isMinVscode
1 parent 67e6838 commit 068241a

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,12 @@ 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 {
71-
if (throwWhen) {
72-
throwIfMinVscodeGte(throwWhen)
73-
}
74-
return vscode.version.startsWith(getMinVscodeVersion())
75-
}
76-
77-
export function throwIfMinVscodeGte(targetVersion: string): void | never {
70+
export function isMinVscode(options: { throwWhen: string }): boolean {
7871
const minVscode = getMinVscodeVersion()
79-
if (semver.gte(minVscode, targetVersion)) {
80-
throw Error(`Min vscode ${minVscode} >= ${targetVersion}. 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.`)
8174
}
75+
return vscode.version.startsWith(getMinVscodeVersion())
8276
}
8377

8478
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ 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 { skipIfVscodeBelow } from '../../testUtil'
11+
import { isMinVscode } from '../../../shared/vscode/env'
1212

1313
describe('generateResourceHandler', function () {
1414
it('amazon q is not installed', async function () {
15-
skipIfVscodeBelow(this, '1.89.0')
15+
if (isMinVscode({ throwWhen: '1.89.0' })) {
16+
this.skip()
17+
}
1618
const panel = await createTemplate()
1719
const postMessageSpy = sinon.spy(panel.webview, 'postMessage')
1820
const context = await createWebviewContext({

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +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 { skipIfVscodeBelow } from '../../testUtil'
10+
import { isMinVscode } from '../../../shared/vscode/env'
1111

1212
describe('initMessageHandler', function () {
1313
afterEach(function () {
1414
sinon.restore()
1515
})
1616

1717
it('not connected to codewhisperer', async function () {
18-
skipIfVscodeBelow(this, '1.89.0')
18+
if (isMinVscode({ throwWhen: '1.89.0' })) {
19+
this.skip()
20+
}
1921
const panel = await createTemplate()
2022
const postMessageSpy = sinon.spy(panel.webview, 'postMessage')
2123
const context = await createWebviewContext({

packages/core/src/test/testUtil.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import assert from 'assert'
77
import * as path from 'path'
88
import * as vscode from 'vscode'
9-
import * as semver from 'semver'
109
import * as FakeTimers from '@sinonjs/fake-timers'
1110
import * as pathutil from '../shared/utilities/pathUtils'
1211
import { makeTemporaryToolkitFolder, tryRemoveFolder } from '../shared/filesystemUtilities'
@@ -20,7 +19,6 @@ import { mkdirSync, existsSync } from 'fs' // eslint-disable-line no-restricted-
2019
import { randomBytes } from 'crypto'
2120
import request from '../shared/request'
2221
import { stub } from 'sinon'
23-
import { throwIfMinVscodeGte } from '../shared/vscode/env'
2422

2523
const testTempDirs: string[] = []
2624

@@ -636,10 +634,3 @@ export function getFetchStubWithResponse(response: Partial<Response>) {
636634
export function copyEnv(): NodeJS.ProcessEnv {
637635
return { ...process.env }
638636
}
639-
640-
export function skipIfVscodeBelow(testContext: Mocha.Context, targetVersion: string) {
641-
throwIfMinVscodeGte(targetVersion)
642-
if (semver.lt(vscode.version, targetVersion)) {
643-
testContext.skip()
644-
}
645-
}

0 commit comments

Comments
 (0)