|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | import * as assert from "assert"; |
| 5 | +import * as os from "os"; |
5 | 6 | import * as vscode from "vscode"; |
6 | | -import { Settings, getSettings, getEffectiveConfigurationTarget, changeSetting, CommentType } from "../../src/settings"; |
| 7 | +import { |
| 8 | + Settings, |
| 9 | + getSettings, |
| 10 | + getEffectiveConfigurationTarget, |
| 11 | + changeSetting, |
| 12 | + CommentType, |
| 13 | + validateCwdSetting |
| 14 | +} from "../../src/settings"; |
| 15 | +import path from "path"; |
7 | 16 |
|
8 | 17 | describe("Settings E2E", function () { |
9 | | - it("Loads without error", function () { |
10 | | - assert.doesNotThrow(getSettings); |
| 18 | + describe("The 'getSettings' method loads the 'Settings' class", function () { |
| 19 | + it("Loads without error", function () { |
| 20 | + assert.doesNotThrow(getSettings); |
| 21 | + }); |
| 22 | + |
| 23 | + it("Loads the correct defaults", function () { |
| 24 | + const testSettings = new Settings(); |
| 25 | + const actualSettings = getSettings(); |
| 26 | + assert.deepStrictEqual(actualSettings, testSettings); |
| 27 | + }); |
11 | 28 | }); |
12 | 29 |
|
13 | | - it("Loads the correct defaults", function () { |
14 | | - const testSettings = new Settings(); |
15 | | - const actualSettings = getSettings(); |
16 | | - assert.deepStrictEqual(actualSettings, testSettings); |
| 30 | + describe("The 'changeSetting' method", function () { |
| 31 | + it("Updates correctly", async function () { |
| 32 | + await changeSetting("helpCompletion", CommentType.LineComment, false, undefined); |
| 33 | + assert.strictEqual(getSettings().helpCompletion, CommentType.LineComment); |
| 34 | + }); |
17 | 35 | }); |
18 | 36 |
|
19 | | - it("Updates correctly", async function () { |
20 | | - await changeSetting("helpCompletion", CommentType.LineComment, false, undefined); |
21 | | - assert.strictEqual(getSettings().helpCompletion, CommentType.LineComment); |
| 37 | + describe("The 'getEffectiveConfigurationTarget' method'", function () { |
| 38 | + it("Works for 'Workspace' target", async function () { |
| 39 | + await changeSetting("helpCompletion", CommentType.LineComment, false, undefined); |
| 40 | + const target = getEffectiveConfigurationTarget("helpCompletion"); |
| 41 | + assert.strictEqual(target, vscode.ConfigurationTarget.Workspace); |
| 42 | + }); |
| 43 | + |
| 44 | + it("Works for 'undefined' target", async function () { |
| 45 | + await changeSetting("helpCompletion", undefined, false, undefined); |
| 46 | + const target = getEffectiveConfigurationTarget("helpCompletion"); |
| 47 | + assert.strictEqual(target, undefined); |
| 48 | + }); |
22 | 49 | }); |
23 | 50 |
|
24 | | - it("Gets the effective configuration target", async function () { |
25 | | - await changeSetting("helpCompletion", CommentType.LineComment, false, undefined); |
26 | | - let target = getEffectiveConfigurationTarget("helpCompletion"); |
27 | | - assert.strictEqual(target, vscode.ConfigurationTarget.Workspace); |
| 51 | + describe("The CWD setting", function () { |
| 52 | + beforeEach(async function () { |
| 53 | + await changeSetting("cwd", undefined, undefined, undefined); |
| 54 | + }); |
| 55 | + |
| 56 | + const workspace = vscode.workspace.workspaceFolders![0].uri.fsPath; |
| 57 | + |
| 58 | + it("Defaults to the 'mocks' workspace folder", async function () { |
| 59 | + assert.strictEqual(await validateCwdSetting(undefined), workspace); |
| 60 | + }); |
| 61 | + |
| 62 | + it("Uses the default when given a non-existent folder", async function () { |
| 63 | + await changeSetting("cwd", "/a/totally/fake/folder", undefined, undefined); |
| 64 | + assert.strictEqual(await validateCwdSetting(undefined), workspace); |
| 65 | + }); |
| 66 | + |
| 67 | + it("Uses the given folder when it exists", async function () { |
| 68 | + // A different than default folder that definitely exists |
| 69 | + const cwd = path.resolve(path.join(process.cwd(), "..")); |
| 70 | + await changeSetting("cwd", cwd, undefined, undefined); |
| 71 | + assert.strictEqual(await validateCwdSetting(undefined), cwd); |
| 72 | + }); |
28 | 73 |
|
29 | | - await changeSetting("helpCompletion", undefined, false, undefined); |
30 | | - target = getEffectiveConfigurationTarget("helpCompletion"); |
31 | | - assert.strictEqual(target, undefined); |
| 74 | + it("Uses the home folder for ~ (tilde)", async function () { |
| 75 | + // A different than default folder that definitely exists |
| 76 | + await changeSetting("cwd", "~", undefined, undefined); |
| 77 | + assert.strictEqual(await validateCwdSetting(undefined), os.homedir()); |
| 78 | + }); |
32 | 79 | }); |
33 | 80 | }); |
0 commit comments