@@ -13,9 +13,20 @@ import {
13
13
validateCwdSetting
14
14
} from "../../src/settings" ;
15
15
import path from "path" ;
16
+ import { ensureEditorServicesIsConnected } from "../utils" ;
16
17
17
18
describe ( "Settings E2E" , function ( ) {
19
+ async function changeCwdSetting ( cwd : string | undefined ) : Promise < void > {
20
+ await changeSetting ( "cwd" , cwd , vscode . ConfigurationTarget . Workspace , undefined ) ;
21
+ }
22
+
23
+ async function resetCwdSetting ( ) : Promise < void > {
24
+ await changeCwdSetting ( undefined ) ;
25
+ }
26
+
18
27
describe ( "The 'getSettings' method loads the 'Settings' class" , function ( ) {
28
+ before ( resetCwdSetting ) ;
29
+
19
30
it ( "Loads without error" , function ( ) {
20
31
assert . doesNotThrow ( getSettings ) ;
21
32
} ) ;
@@ -29,29 +40,30 @@ describe("Settings E2E", function () {
29
40
30
41
describe ( "The 'changeSetting' method" , function ( ) {
31
42
it ( "Updates correctly" , async function ( ) {
32
- await changeSetting ( "helpCompletion" , CommentType . LineComment , false , undefined ) ;
43
+ await changeSetting ( "helpCompletion" , CommentType . LineComment , vscode . ConfigurationTarget . Workspace , undefined ) ;
33
44
assert . strictEqual ( getSettings ( ) . helpCompletion , CommentType . LineComment ) ;
34
45
} ) ;
35
46
} ) ;
36
47
37
48
describe ( "The 'getEffectiveConfigurationTarget' method'" , function ( ) {
38
49
it ( "Works for 'Workspace' target" , async function ( ) {
39
- await changeSetting ( "helpCompletion" , CommentType . LineComment , false , undefined ) ;
50
+ await changeSetting ( "helpCompletion" , CommentType . LineComment , vscode . ConfigurationTarget . Workspace , undefined ) ;
40
51
const target = getEffectiveConfigurationTarget ( "helpCompletion" ) ;
41
52
assert . strictEqual ( target , vscode . ConfigurationTarget . Workspace ) ;
42
53
} ) ;
43
54
44
55
it ( "Works for 'undefined' target" , async function ( ) {
45
- await changeSetting ( "helpCompletion" , undefined , false , undefined ) ;
56
+ await changeSetting ( "helpCompletion" , undefined , vscode . ConfigurationTarget . Workspace , undefined ) ;
46
57
const target = getEffectiveConfigurationTarget ( "helpCompletion" ) ;
47
58
assert . strictEqual ( target , undefined ) ;
48
59
} ) ;
49
60
} ) ;
50
61
51
62
describe ( "The CWD setting" , function ( ) {
52
- beforeEach ( async function ( ) {
53
- await changeSetting ( "cwd" , undefined , undefined , undefined ) ;
54
- } ) ;
63
+ // We're relying on this to be sure that the workspace is loaded.
64
+ before ( ensureEditorServicesIsConnected ) ;
65
+ before ( resetCwdSetting ) ;
66
+ afterEach ( resetCwdSetting ) ;
55
67
56
68
const workspace = vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath ;
57
69
@@ -60,20 +72,26 @@ describe("Settings E2E", function () {
60
72
} ) ;
61
73
62
74
it ( "Uses the default when given a non-existent folder" , async function ( ) {
63
- await changeSetting ( "cwd" , " /a/totally/fake/folder", undefined , undefined ) ;
75
+ await changeCwdSetting ( " /a/totally/fake/folder") ;
64
76
assert . strictEqual ( await validateCwdSetting ( undefined ) , workspace ) ;
65
77
} ) ;
66
78
67
79
it ( "Uses the given folder when it exists" , async function ( ) {
68
80
// A different than default folder that definitely exists
69
81
const cwd = path . resolve ( path . join ( process . cwd ( ) , ".." ) ) ;
70
- await changeSetting ( " cwd" , cwd , undefined , undefined ) ;
82
+ await changeCwdSetting ( cwd ) ;
71
83
assert . strictEqual ( await validateCwdSetting ( undefined ) , cwd ) ;
72
84
} ) ;
73
85
74
86
it ( "Uses the home folder for ~ (tilde)" , async function ( ) {
75
- // A different than default folder that definitely exists
76
- await changeSetting ( "cwd" , "~" , undefined , undefined ) ;
87
+ await changeCwdSetting ( "~" ) ;
88
+ assert . strictEqual ( await validateCwdSetting ( undefined ) , os . homedir ( ) ) ;
89
+ } ) ;
90
+
91
+ it ( "Resolves relative paths" , async function ( ) {
92
+ // A different than default folder that definitely exists and is relative
93
+ const cwd = path . join ( "~" , "somewhere" , ".." ) ;
94
+ await changeCwdSetting ( cwd ) ;
77
95
assert . strictEqual ( await validateCwdSetting ( undefined ) , os . homedir ( ) ) ;
78
96
} ) ;
79
97
} ) ;
0 commit comments