Skip to content

Commit c21e013

Browse files
committed
refactor shared logic into another helper
1 parent a0b1704 commit c21e013

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ export { extensionVersion }
6868
* @param throwWhen Throw if minimum vscode is equal or later than this version.
6969
*/
7070
export function isMinVscode(throwWhen?: string): boolean {
71-
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.`)
71+
if (throwWhen) {
72+
throwIfMinVscodeGte(throwWhen)
7473
}
7574
return vscode.version.startsWith(getMinVscodeVersion())
7675
}
7776

77+
export function throwIfMinVscodeGte(targetVersion: string): void | never {
78+
const minVscode = getMinVscodeVersion()
79+
if (semver.gte(minVscode, targetVersion)) {
80+
throw Error(`Min vscode ${minVscode} >= ${targetVersion}. Delete or update the code that called this.`)
81+
}
82+
}
83+
7884
/**
7985
* Returns the minimum vscode "engine" version declared in `package.json`.
8086
*/

packages/core/src/test/testUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { mkdirSync, existsSync } from 'fs' // eslint-disable-line no-restricted-
2020
import { randomBytes } from 'crypto'
2121
import request from '../shared/request'
2222
import { stub } from 'sinon'
23+
import { throwIfMinVscodeGte } from '../shared/vscode/env'
2324

2425
const testTempDirs: string[] = []
2526

@@ -637,6 +638,7 @@ export function copyEnv(): NodeJS.ProcessEnv {
637638
}
638639

639640
export function skipIfVscodeBelow(testContext: Mocha.Context, targetVersion: string) {
641+
throwIfMinVscodeGte(targetVersion)
640642
if (semver.lt(vscode.version, targetVersion)) {
641643
testContext.skip()
642644
}

0 commit comments

Comments
 (0)