diff --git a/src/services/config.ts b/src/services/config.ts index 1d68a2b..9e4c7a1 100755 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -39,24 +39,37 @@ class Config { public setLiveShareProfile(profile: string) { let config = this.getConfig(); - return config.update(ConfigLiveShareProfileKey, profile, vscode.ConfigurationTarget.Global); + return config.update( + ConfigLiveShareProfileKey, + profile, + vscode.ConfigurationTarget.Global + ); } public async setCurrentProfile(profile: string) { if (this.context) { - const previousProfile = this.context.globalState.get(ContextSettingCurrentProfile); + const previousProfile = this.context.globalState.get( + ContextSettingCurrentProfile + ); this.setPreviousProfile(previousProfile); - await this.context.globalState.update(ContextSettingCurrentProfile, profile); + await this.context.globalState.update( + ContextSettingCurrentProfile, + profile + ); } } public getPreviousProfile(): string | undefined { - return this.context && this.context.globalState.get(ContextSettingPreviousProfile); + return ( + this.context && + this.context.globalState.get(ContextSettingPreviousProfile) + ); } public setPreviousProfile(profile: string | undefined) { - this.context && this.context.globalState.update(ContextSettingPreviousProfile, profile); + this.context && + this.context.globalState.update(ContextSettingPreviousProfile, profile); } public getProfiles() { @@ -107,14 +120,17 @@ class Config { } public addProfileSettings(profile: string, settings: Settings) { - // We don't want to save profile info in the profile storage - if (settings[`${ConfigKey}:${ConfigProfilesKey}`]) { - delete settings[`${ConfigKey}:${ConfigProfilesKey}`]; - } - - if (settings[`${ConfigKey}:${ConfigStorageKey}`]) { - delete settings[`${ConfigKey}:${ConfigStorageKey}`]; - } + const deleteSetting = (key: string) => { + if (`${ConfigKey}.${key}` in settings) { + delete settings[`${ConfigKey}.${key}`]; + } + }; + + deleteSetting(ConfigProfilesKey); + deleteSetting(ConfigStorageKey); + deleteSetting(ConfigExtensionsKey); + deleteSetting(ConfigExtensionsIgnoreKey); + deleteSetting(ConfigLiveShareProfileKey); let storage = this.getStorage(); storage[profile] = settings; diff --git a/src/test/saveProfile.test.ts b/src/test/saveProfile.test.ts index b0e00fa..0fdf935 100755 --- a/src/test/saveProfile.test.ts +++ b/src/test/saveProfile.test.ts @@ -5,7 +5,8 @@ import { ConfigKey, ConfigProfilesKey, ConfigStorageKey, - ConfigExtensionsKey + ConfigExtensionsKey, + ConfigLiveShareProfileKey } from "../constants"; import Config from "../services/config"; import { ExtensionInfo } from "../services/extensions"; @@ -34,6 +35,13 @@ suite("save profile", () => { suite("settings", () => { const expectedProfileSettings = { foo: "bar" }; const expectedUpdatedProfileSettings = { foo: "baz", a: "b" }; + const profileSwitcherSettings = { + [`${ConfigKey}.${ConfigProfilesKey}`]: [], + [`${ConfigKey}.${ConfigStorageKey}`]: {}, + [`${ConfigKey}.${ConfigExtensionsKey}`]: {}, + [`${ConfigKey}.${ConfigExtensionsKey}`]: [], + [`${ConfigKey}.${ConfigLiveShareProfileKey}`]: "" + }; teardown(async () => { let config = vscode.workspace.getConfiguration(ConfigKey); @@ -72,6 +80,23 @@ suite("save profile", () => { let settings = config.getProfileSettings(expectedProfileName); assert.deepEqual(settings, expectedUpdatedProfileSettings); }); + + test("saving profile doesn't include profileSwitcher settings", async () => { + var config = new Config(); + + await config.addProfileSettings( + expectedProfileName, + Object.assign({}, expectedProfileSettings, profileSwitcherSettings) + ); + + let settings = config.getProfileSettings(expectedProfileName); + Object.keys(profileSwitcherSettings).forEach(key => + assert.isUndefined( + settings[key], + `The key "${key}" should have been removed` + ) + ); + }); }); suite("extensions", () => { diff --git a/src/test/selectProfile.test.ts b/src/test/selectProfile.test.ts index dc77959..b0d7e6b 100755 --- a/src/test/selectProfile.test.ts +++ b/src/test/selectProfile.test.ts @@ -77,7 +77,7 @@ suite("select profile", () => { assert.deepEqual(settings, expectedProfileSettings); }); - test("storage contains the expected profile settings", () => { + test("storage contains the expected profile extensions", () => { let config = new Config(); let extensions = config.getProfileExtensions(expectedProfileName);