-
Notifications
You must be signed in to change notification settings - Fork 542
Expand file tree
/
Copy pathsettings.test.ts
More file actions
138 lines (121 loc) · 4.85 KB
/
settings.test.ts
File metadata and controls
138 lines (121 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import * as assert from "assert";
import { existsSync } from "fs";
import * as os from "os";
import path from "path";
import * as vscode from "vscode";
import {
changeSetting,
CommentType,
getEffectiveConfigurationTarget,
getSettings,
Settings,
validateCwdSetting,
} from "../../src/settings";
import { ensureEditorServicesIsConnected } from "../utils";
describe("Settings E2E", function () {
async function changeCwdSetting(cwd: string | undefined): Promise<void> {
await changeSetting(
"cwd",
cwd,
vscode.ConfigurationTarget.Workspace,
undefined,
);
}
async function resetCwdSetting(): Promise<void> {
await changeCwdSetting(undefined);
}
describe("The 'getSettings' method loads the 'Settings' class", function () {
before(resetCwdSetting);
it("Loads without error", function () {
assert.doesNotThrow(getSettings);
});
it("Loads the correct defaults", function () {
const testSettings = new Settings();
if (existsSync("C:\\powershell-7\\pwsh.exe")) {
testSettings.powerShellAdditionalExePaths = {
OneBranch: "C:\\powershell-7\\pwsh.exe",
};
testSettings.powerShellDefaultVersion = "OneBranch";
}
const actualSettings = getSettings();
assert.deepStrictEqual(actualSettings, testSettings);
});
});
describe("The 'changeSetting' method", function () {
it("Updates correctly", async function () {
await changeSetting(
"helpCompletion",
CommentType.LineComment,
vscode.ConfigurationTarget.Workspace,
undefined,
);
assert.strictEqual(
getSettings().helpCompletion,
CommentType.LineComment,
);
});
});
describe("The 'getEffectiveConfigurationTarget' method'", function () {
it("Works for 'Workspace' target", async function () {
await changeSetting(
"helpCompletion",
CommentType.LineComment,
vscode.ConfigurationTarget.Workspace,
undefined,
);
const target = getEffectiveConfigurationTarget("helpCompletion");
assert.strictEqual(target, vscode.ConfigurationTarget.Workspace);
});
it("Works for 'undefined' target", async function () {
await changeSetting(
"helpCompletion",
undefined,
vscode.ConfigurationTarget.Workspace,
undefined,
);
const target = getEffectiveConfigurationTarget("helpCompletion");
assert.strictEqual(target, undefined);
});
});
describe("The CWD setting", function () {
// We're relying on this to be sure that the workspace is loaded.
before(ensureEditorServicesIsConnected);
before(resetCwdSetting);
afterEach(resetCwdSetting);
const workspace = vscode.workspace.workspaceFolders![0].uri.fsPath;
it("Defaults to the 'mocks' workspace folder", async function () {
assert.strictEqual(await validateCwdSetting(undefined), workspace);
});
it("Uses the default when given a non-existent folder", async function () {
await changeCwdSetting("/a/totally/fake/folder");
assert.strictEqual(await validateCwdSetting(undefined), workspace);
});
it("Uses the given folder when it exists", async function () {
// A different than default folder that definitely exists
const cwd = path.resolve(path.join(process.cwd(), ".."));
await changeCwdSetting(cwd);
assert.strictEqual(await validateCwdSetting(undefined), cwd);
});
it("Uses the home folder for ~ (tilde)", async function () {
await changeCwdSetting("~");
assert.strictEqual(
await validateCwdSetting(undefined),
os.homedir(),
);
});
it("Accepts relative paths", async function () {
// A different than default folder that definitely exists and is relative
const cwd = path.join("~", "somewhere", "..");
const expected = path.join(os.homedir(), "somewhere", "..");
await changeCwdSetting(cwd);
assert.strictEqual(await validateCwdSetting(undefined), expected);
});
it("Handles relative paths", async function () {
await changeCwdSetting("./BinaryModule");
const expected = path.join(workspace, "./BinaryModule");
assert.strictEqual(await validateCwdSetting(undefined), expected);
});
});
});