Skip to content

Commit f8173bc

Browse files
committed
extension/src/welcome: fix 'go.showWelcome' setting interpretation
Fixes #3319 Change-Id: Idc64d150c170c96f6e2bee4016236666bf4d4c64 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/577075 kokoro-CI: kokoro <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Peter Weinberger <[email protected]>
1 parent ad37a53 commit f8173bc

File tree

2 files changed

+61
-44
lines changed

2 files changed

+61
-44
lines changed

extension/src/welcome.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import path = require('path');
1212
import semver = require('semver');
1313
import { extensionId } from './const';
1414
import { GoExtensionContext } from './context';
15-
import { extensionInfo } from './config';
15+
import { extensionInfo, getGoConfig } from './config';
1616
import { getFromGlobalState, updateGlobalState } from './stateUtils';
1717
import { createRegisterCommand } from './commands';
1818

@@ -29,11 +29,7 @@ export class WelcomePanel {
2929
}
3030
});
3131
}
32-
33-
// Show the Go welcome page on update.
34-
if (!extensionInfo.isInCloudIDE && vscode.workspace.getConfiguration('go.showWelcome')) {
35-
showGoWelcomePage();
36-
}
32+
showGoWelcomePage();
3733
}
3834

3935
public static currentPanel: WelcomePanel | undefined;
@@ -278,6 +274,9 @@ function showGoWelcomePage() {
278274
}
279275

280276
export function shouldShowGoWelcomePage(showVersions: string[], newVersion: string, oldVersion: string): boolean {
277+
if (!extensionInfo.isInCloudIDE && getGoConfig().get('showWelcome') === false) {
278+
return false;
279+
}
281280
if (newVersion === oldVersion) {
282281
return false;
283282
}

extension/test/integration/welcome.test.ts

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,70 @@ import assert from 'assert';
88
import { shouldShowGoWelcomePage } from '../../src/welcome';
99
import { extensionId } from '../../src/const';
1010
import { WelcomePanel } from '../../src/welcome';
11+
import sinon = require('sinon');
12+
import * as config from '../../src/config';
13+
import { MockCfg } from '../mocks/MockCfg';
1114

1215
suite('WelcomePanel Tests', () => {
13-
// 0:showVersions, 1:newVersion, 2:oldVersion, 3:expected
14-
type testCase = [string[], string, string, boolean];
16+
let sandbox: sinon.SinonSandbox;
17+
setup(() => {
18+
sandbox = sinon.createSandbox();
19+
});
20+
teardown(() => sandbox.restore());
21+
22+
// 0:showVersions, 1:newVersion, 2:oldVersion, 3: showWelcome, 4:expected
23+
//
24+
// If showWelcome is false, then expected has to be false.
25+
// Otherwise, expected is true if (and only if) newVersion occurs in showVersions
26+
// and is newer than oldVersion (as semantic versions).
27+
type testCase = [string[], string, string, boolean, boolean];
1528
const testCases: testCase[] = [
16-
[[], '0.22.0', '0.0.0', false],
17-
[[], '0.22.0', '0.21.0', false],
18-
[[], '0.22.0', '0.22.0-rc.1', false],
19-
[[], '0.22.0', '0.22.0', false],
20-
[[], '0.22.0', '0.23.0', false],
29+
[[], '0.22.0', '0.0.0', true, false],
30+
[[], '0.22.0', '0.21.0', true, false],
31+
[[], '0.22.0', '0.22.0-rc.1', true, false],
32+
[[], '0.22.0', '0.22.0', true, false],
33+
[[], '0.22.0', '0.23.0', true, false],
2134

22-
[['0.22.0'], '0.22.0', '0.0.0', true],
23-
[['0.22.0'], '0.22.0', '0.21.0-rc.1', true],
24-
[['0.22.0'], '0.22.0', '0.21.0', true],
25-
[['0.22.0'], '0.22.0', '0.22.0-rc.1', true],
26-
[['0.22.0'], '0.22.0', '0.22.0', false],
27-
[['0.22.0'], '0.22.0', '0.22.1', false],
28-
[['0.22.0'], '0.22.0', '0.23.0', false],
29-
[['0.22.0'], '0.22.0', '1.0.0', false],
30-
[['0.22.0'], '0.22.0', '2021.1.100', false],
35+
[['0.22.0'], '0.22.0', '0.0.0', true, true],
36+
[['0.22.0'], '0.22.0', '0.0.0', false, false],
37+
[['0.22.0'], '0.22.0', '0.21.0-rc.1', true, true],
38+
[['0.22.0'], '0.22.0', '0.21.0', true, true],
39+
[['0.22.0'], '0.22.0', '0.22.0-rc.1', true, true],
40+
[['0.22.0'], '0.22.0', '0.22.0', true, false],
41+
[['0.22.0'], '0.22.0', '0.22.1', true, false],
42+
[['0.22.0'], '0.22.0', '0.23.0', true, false],
43+
[['0.22.0'], '0.22.0', '1.0.0', true, false],
44+
[['0.22.0'], '0.22.0', '2021.1.100', true, false],
3145

32-
[['0.22.0'], '0.22.0-rc.2', '0.0.0', true],
33-
[['0.22.0'], '0.22.0-rc.2', '0.21.0-rc.1', true],
34-
[['0.22.0'], '0.22.0-rc.2', '0.21.0', true],
35-
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.1', true],
36-
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.2', false],
37-
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.3', true],
38-
[['0.22.0'], '0.22.0-rc.2', '0.22.0', true],
39-
[['0.22.0'], '0.22.0-rc.2', '0.22.1', false],
40-
[['0.22.0'], '0.22.0-rc.2', '0.23.0', false],
41-
[['0.22.0'], '0.22.0-rc.2', '1.0.0', false],
42-
[['0.22.0'], '0.22.0-rc.2', '2021.1.100', false],
46+
[['0.22.0'], '0.22.0-rc.2', '0.0.0', true, true],
47+
[['0.22.0'], '0.22.0-rc.2', '0.21.0-rc.1', true, true],
48+
[['0.22.0'], '0.22.0-rc.2', '0.21.0', true, true],
49+
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.1', true, true],
50+
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.2', true, false],
51+
[['0.22.0'], '0.22.0-rc.2', '0.22.0-rc.3', true, true],
52+
[['0.22.0'], '0.22.0-rc.2', '0.22.0', true, true],
53+
[['0.22.0'], '0.22.0-rc.2', '0.22.1', true, false],
54+
[['0.22.0'], '0.22.0-rc.2', '0.23.0', true, false],
55+
[['0.22.0'], '0.22.0-rc.2', '1.0.0', true, false],
56+
[['0.22.0'], '0.22.0-rc.2', '2021.1.100', true, false],
4357

44-
[['0.22.0'], '0.22.1', '0.0.0', false],
45-
[['0.22.0'], '0.22.1', '0.21.0-rc.1', false],
46-
[['0.22.0'], '0.22.1', '0.21.0', false],
47-
[['0.22.0'], '0.22.1', '0.22.0-rc.1', false],
48-
[['0.22.0'], '0.22.1', '0.22.0', false],
49-
[['0.22.0'], '0.22.1', '0.23.0', false],
50-
[['0.22.0'], '0.22.1', '1.0.0', false],
51-
[['0.22.0'], '0.22.1', '2021.1.100', false]
58+
[['0.22.0'], '0.22.1', '0.0.0', true, false],
59+
[['0.22.0'], '0.22.1', '0.21.0-rc.1', true, false],
60+
[['0.22.0'], '0.22.1', '0.21.0', true, false],
61+
[['0.22.0'], '0.22.1', '0.22.0-rc.1', true, false],
62+
[['0.22.0'], '0.22.1', '0.22.0', true, false],
63+
[['0.22.0'], '0.22.1', '0.23.0', true, false],
64+
[['0.22.0'], '0.22.1', '1.0.0', true, false],
65+
[['0.22.0'], '0.22.1', '2021.1.100', true, false]
5266
];
5367
testCases.forEach((c: testCase) => {
54-
const [showVersions, newVersion, oldVersion, expected] = c;
55-
56-
test(`shouldShowGoWelcomePage(${JSON.stringify(showVersions)}, ${newVersion}, ${oldVersion})`, () => {
68+
const [showVersions, newVersion, oldVersion, showWelcome, expected] = c;
69+
test(`shouldShowGoWelcomePage(${JSON.stringify(
70+
showVersions
71+
)}, ${newVersion}, ${oldVersion}, (showWelcome=${showWelcome}))`, () => {
72+
const goConfig = new MockCfg([]);
73+
sandbox.stub(config, 'getGoConfig').returns(goConfig);
74+
sinon.stub(goConfig, 'get').withArgs('showWelcome').returns(showWelcome);
5775
assert.strictEqual(shouldShowGoWelcomePage(showVersions, newVersion, oldVersion), expected);
5876
});
5977
});

0 commit comments

Comments
 (0)