Skip to content

Commit cda9852

Browse files
authored
fix(vscode): avoid recommending to upgrade when version is above constraints (#864)
1 parent bbde74b commit cda9852

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

extensions/vscode/src/extension.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,15 @@ export async function ensureCompatibleDartFrogCLI(): Promise<void> {
112112
return;
113113
}
114114

115+
const options = ["Update Dart Frog CLI", "Changelog", "Ignore"];
116+
const shouldUpdate = isCompatibleDartFrogCLIVersion(latestVersion);
117+
if (!shouldUpdate) {
118+
options.shift();
119+
}
120+
115121
const selection = await vscode.window.showWarningMessage(
116122
`Dart Frog CLI version ${version} is not compatible with this extension.`,
117-
"Update Dart Frog CLI",
118-
"Changelog",
119-
"Ignore"
123+
...options
120124
);
121125
switch (selection) {
122126
case "Update Dart Frog CLI":

extensions/vscode/src/test/suite/extension.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,15 @@ suite("ensureCompatibleDartFrogCLI", () => {
279279

280280
suite("incompatible CLI", () => {
281281
const version = "0.0.0";
282+
const latestVersion = "2.0.0";
282283

283284
beforeEach(() => {
284285
utilsStub.readDartFrogCLIVersion.returns(version);
285-
utilsStub.isCompatibleDartFrogCLIVersion.returns(false);
286-
utilsStub.readLatestDartFrogCLIVersion.returns(version);
286+
utilsStub.readLatestDartFrogCLIVersion.returns(latestVersion);
287+
utilsStub.isCompatibleDartFrogCLIVersion.withArgs(version).returns(false);
288+
utilsStub.isCompatibleDartFrogCLIVersion
289+
.withArgs(latestVersion)
290+
.returns(true);
287291
});
288292

289293
afterEach(() => {
@@ -302,6 +306,21 @@ suite("ensureCompatibleDartFrogCLI", () => {
302306
);
303307
});
304308

309+
test("shows warning without update action when latest version is not compatible", async () => {
310+
utilsStub.isCompatibleDartFrogCLIVersion
311+
.withArgs(latestVersion)
312+
.returns(false);
313+
314+
await extension.ensureCompatibleDartFrogCLI();
315+
316+
sinon.assert.calledOnceWithExactly(
317+
vscodeStub.window.showWarningMessage,
318+
`Dart Frog CLI version ${version} is not compatible with this extension.`,
319+
"Changelog",
320+
"Ignore"
321+
);
322+
});
323+
305324
test("updates CLI when selected", async () => {
306325
vscodeStub.window.showWarningMessage.returns("Update Dart Frog CLI");
307326

@@ -315,7 +334,10 @@ suite("ensureCompatibleDartFrogCLI", () => {
315334

316335
await extension.ensureCompatibleDartFrogCLI();
317336

318-
sinon.assert.calledOnceWithExactly(utilsStub.openChangelog, version);
337+
sinon.assert.calledOnceWithExactly(
338+
utilsStub.openChangelog,
339+
latestVersion
340+
);
319341
sinon.assert.notCalled(commandsStub.updateCLI);
320342
});
321343

0 commit comments

Comments
 (0)