From e035f6921253df9e2290eb173b77c0cf1dafade5 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Sun, 28 Apr 2019 22:40:27 -0700 Subject: [PATCH] backport: fix change session by moving to async/await promise (#1927) --- src/settings.ts | 4 ++-- test/settings.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/settings.test.ts diff --git a/src/settings.ts b/src/settings.ts index 6c7e2897ce..c221b109db 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -186,12 +186,12 @@ export function load(): ISettings { }; } -export function change(settingName: string, newValue: any, global: boolean = false): Thenable { +export async function change(settingName: string, newValue: any, global: boolean = false): Promise { const configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration( utils.PowerShellLanguageId); - return configuration.update(settingName, newValue, global); + await configuration.update(settingName, newValue, global); } function getWorkspaceSettingsWithDefaults( diff --git a/test/settings.test.ts b/test/settings.test.ts new file mode 100644 index 0000000000..258850cd48 --- /dev/null +++ b/test/settings.test.ts @@ -0,0 +1,22 @@ +/*--------------------------------------------------------- + * Copyright (C) Microsoft Corporation. All rights reserved. + *--------------------------------------------------------*/ + +import * as assert from "assert"; +import Settings = require("../src/settings"); + +suite("Settings module", () => { + test("Settings load without error", () => { + assert.doesNotThrow(Settings.load); + }); + + test("Settings update correctly", async () => { + // then syntax + Settings.change("powerShellExePath", "dummypath1", false).then(() => + assert.strictEqual(Settings.load().powerShellExePath, "dummypath1")); + + // async/await syntax + await Settings.change("powerShellExePath", "dummypath2", false); + assert.strictEqual(Settings.load().powerShellExePath, "dummypath2"); + }); +});