Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0456ff93
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0456ff93
编写于
7月 01, 2020
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix #101339
上级
b4d8f06c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
132 deletion
+82
-132
src/vs/platform/configuration/test/node/configurationService.test.ts
...form/configuration/test/node/configurationService.test.ts
+82
-132
未找到文件。
src/vs/platform/configuration/test/node/configurationService.test.ts
浏览文件 @
0456ff93
...
@@ -4,179 +4,142 @@
...
@@ -4,179 +4,142 @@
*--------------------------------------------------------------------------------------------*/
*--------------------------------------------------------------------------------------------*/
import
*
as
assert
from
'
assert
'
;
import
*
as
assert
from
'
assert
'
;
import
*
as
os
from
'
os
'
;
import
*
as
path
from
'
vs/base/common/path
'
;
import
*
as
fs
from
'
fs
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
import
{
ConfigurationService
}
from
'
vs/platform/configuration/common/configurationService
'
;
import
{
ConfigurationService
}
from
'
vs/platform/configuration/common/configurationService
'
;
import
*
as
uuid
from
'
vs/base/common/uuid
'
;
import
{
IConfigurationRegistry
,
Extensions
as
ConfigurationExtensions
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
{
IConfigurationRegistry
,
Extensions
as
ConfigurationExtensions
}
from
'
vs/platform/configuration/common/configurationRegistry
'
;
import
{
testFile
}
from
'
vs/base/test/node/utils
'
;
import
{
testFile
,
ITestFileResult
}
from
'
vs/base/test/node/utils
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
ConfigurationTarget
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ConfigurationTarget
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
import
{
FileService
}
from
'
vs/platform/files/common/fileService
'
;
import
{
FileService
}
from
'
vs/platform/files/common/fileService
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
DiskFileSystemProvider
}
from
'
vs/platform/files/node/diskFileSystemProvider
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
import
{
InMemoryFileSystemProvider
}
from
'
vs/platform/files/common/inMemoryFilesystemProvider
'
;
suite
(
'
ConfigurationService - Node
'
,
()
=>
{
suite
(
'
ConfigurationService - Node
'
,
()
=>
{
let
fileService
:
IFileService
;
let
fileService
:
IFileService
;
const
disposables
:
IDisposable
[]
=
[];
let
testFileResult
:
ITestFileResult
;
let
settingsResource
:
URI
;
setup
(()
=>
{
const
disposables
:
DisposableStore
=
new
DisposableStore
();
const
logService
=
new
NullLogService
();
fileService
=
new
FileService
(
logService
);
setup
(
async
()
=>
{
disposables
.
push
(
fileService
);
fileService
=
new
FileService
(
new
NullLogService
());
const
diskFileSystemProvider
=
new
DiskFileSystemProvider
(
logService
);
disposables
.
add
(
fileService
);
disposables
.
push
(
diskFileSystemProvider
);
const
diskFileSystemProvider
=
new
InMemoryFileSystemProvider
();
disposables
.
add
(
diskFileSystemProvider
);
fileService
.
registerProvider
(
Schemas
.
file
,
diskFileSystemProvider
);
fileService
.
registerProvider
(
Schemas
.
file
,
diskFileSystemProvider
);
testFileResult
=
await
testFile
(
'
config
'
,
'
config.json
'
);
settingsResource
=
URI
.
file
(
testFileResult
.
testFile
);
});
});
test
(
'
simple
'
,
async
()
=>
{
teardown
(
async
()
=>
{
const
res
=
await
testFile
(
'
config
'
,
'
config.json
'
);
disposables
.
clear
();
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "foo": "bar" }
'
);
await
testFileResult
.
cleanUp
();
});
const
service
=
new
ConfigurationService
(
URI
.
file
(
res
.
testFile
),
fileService
);
test
(
'
simple
'
,
async
()
=>
{
await
service
.
initialize
();
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "foo": "bar" }
'
));
const
config
=
service
.
getValue
<
{
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
await
testObject
.
initialize
();
const
config
=
testObject
.
getValue
<
{
foo
:
string
;
foo
:
string
;
}
>
();
}
>
();
assert
.
ok
(
config
);
assert
.
ok
(
config
);
assert
.
equal
(
config
.
foo
,
'
bar
'
);
assert
.
equal
(
config
.
foo
,
'
bar
'
);
service
.
dispose
();
return
res
.
cleanUp
();
});
});
test
(
'
config gets flattened
'
,
async
()
=>
{
test
(
'
config gets flattened
'
,
async
()
=>
{
const
res
=
await
testFile
(
'
config
'
,
'
config.json
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "testworkbench.editor.tabs": true }
'
)
);
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "testworkbench.editor.tabs": true }
'
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
await
testObject
.
initialize
();
const
service
=
new
ConfigurationService
(
URI
.
file
(
res
.
testFile
),
fileService
);
const
config
=
testObject
.
getValue
<
{
await
service
.
initialize
();
const
config
=
service
.
getValue
<
{
testworkbench
:
{
testworkbench
:
{
editor
:
{
editor
:
{
tabs
:
boolean
;
tabs
:
boolean
;
};
};
};
};
}
>
();
}
>
();
assert
.
ok
(
config
);
assert
.
ok
(
config
);
assert
.
ok
(
config
.
testworkbench
);
assert
.
ok
(
config
.
testworkbench
);
assert
.
ok
(
config
.
testworkbench
.
editor
);
assert
.
ok
(
config
.
testworkbench
.
editor
);
assert
.
equal
(
config
.
testworkbench
.
editor
.
tabs
,
true
);
assert
.
equal
(
config
.
testworkbench
.
editor
.
tabs
,
true
);
service
.
dispose
();
return
res
.
cleanUp
();
});
});
test
(
'
error case does not explode
'
,
async
()
=>
{
test
(
'
error case does not explode
'
,
async
()
=>
{
const
res
=
await
testFile
(
'
config
'
,
'
config.json
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
,,,,
'
)
);
fs
.
writeFileSync
(
res
.
testFile
,
'
,,,,
'
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
await
testObject
.
initialize
();
const
service
=
new
ConfigurationService
(
URI
.
file
(
res
.
testFile
),
fileService
);
const
config
=
testObject
.
getValue
<
{
await
service
.
initialize
();
const
config
=
service
.
getValue
<
{
foo
:
string
;
foo
:
string
;
}
>
();
}
>
();
assert
.
ok
(
config
);
service
.
dispose
();
assert
.
ok
(
config
);
return
res
.
cleanUp
();
});
});
test
(
'
missing file does not explode
'
,
async
()
=>
{
test
(
'
missing file does not explode
'
,
async
()
=>
{
const
id
=
uuid
.
generateUuid
();
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
URI
.
file
(
'
__testFile
'
),
fileService
));
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
await
testObject
.
initialize
();
const
newDir
=
path
.
join
(
parentDir
,
'
config
'
,
id
);
const
testFile
=
path
.
join
(
newDir
,
'
config.json
'
);
const
service
=
new
ConfigurationService
(
URI
.
file
(
testFile
),
fileService
);
const
config
=
testObject
.
getValue
<
{
foo
:
string
}
>
();
await
service
.
initialize
();
const
config
=
service
.
getValue
<
{
foo
:
string
}
>
();
assert
.
ok
(
config
);
assert
.
ok
(
config
);
service
.
dispose
();
});
});
test
(
'
trigger configuration change event when file does not exist
'
,
async
()
=>
{
test
(
'
trigger configuration change event when file does not exist
'
,
async
()
=>
{
const
res
=
await
testFile
(
'
config
'
,
'
config.json
'
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
const
settingsFile
=
URI
.
file
(
res
.
testFile
);
await
testObject
.
initialize
();
const
service
=
new
ConfigurationService
(
settingsFile
,
fileService
);
await
service
.
initialize
();
return
new
Promise
(
async
(
c
,
e
)
=>
{
return
new
Promise
(
async
(
c
,
e
)
=>
{
const
disposable
=
Event
.
filter
(
service
.
onDidChangeConfiguration
,
e
=>
e
.
source
===
ConfigurationTarget
.
USER
)(
async
(
e
)
=>
{
disposables
.
add
(
Event
.
filter
(
testObject
.
onDidChangeConfiguration
,
e
=>
e
.
source
===
ConfigurationTarget
.
USER
)(()
=>
{
disposable
.
dispose
();
assert
.
equal
(
testObject
.
getValue
(
'
foo
'
),
'
bar
'
);
assert
.
equal
(
service
.
getValue
(
'
foo
'
),
'
bar
'
);
service
.
dispose
();
await
res
.
cleanUp
();
c
();
c
();
});
})
)
;
await
fileService
.
writeFile
(
settings
Fil
e
,
VSBuffer
.
fromString
(
'
{ "foo": "bar" }
'
));
await
fileService
.
writeFile
(
settings
Resourc
e
,
VSBuffer
.
fromString
(
'
{ "foo": "bar" }
'
));
});
});
});
});
test
(
'
trigger configuration change event when file exists
'
,
async
()
=>
{
test
(
'
trigger configuration change event when file exists
'
,
async
()
=>
{
const
res
=
await
testFile
(
'
config
'
,
'
config.json
'
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "foo": "bar" }
'
));
await
testObject
.
initialize
();
const
service
=
new
ConfigurationService
(
URI
.
file
(
res
.
testFile
),
fileService
);
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "foo": "bar" }
'
);
await
service
.
initialize
();
return
new
Promise
((
c
,
e
)
=>
{
return
new
Promise
((
c
,
e
)
=>
{
const
disposable
=
Event
.
filter
(
service
.
onDidChangeConfiguration
,
e
=>
e
.
source
===
ConfigurationTarget
.
USER
)(
async
(
e
)
=>
{
disposables
.
add
(
Event
.
filter
(
testObject
.
onDidChangeConfiguration
,
e
=>
e
.
source
===
ConfigurationTarget
.
USER
)(
async
(
e
)
=>
{
disposable
.
dispose
();
assert
.
equal
(
testObject
.
getValue
(
'
foo
'
),
'
barz
'
);
assert
.
equal
(
service
.
getValue
(
'
foo
'
),
'
barz
'
);
service
.
dispose
();
await
res
.
cleanUp
();
c
();
c
();
});
})
)
;
f
s
.
writeFileSync
(
res
.
testFile
,
'
{ "foo": "barz" }
'
);
f
ileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "foo": "barz" }
'
)
);
});
});
});
});
test
(
'
reloadConfiguration
'
,
async
()
=>
{
test
(
'
reloadConfiguration
'
,
async
()
=>
{
const
res
=
await
testFile
(
'
config
'
,
'
config.json
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "foo": "bar" }
'
));
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "foo": "bar" }
'
);
const
service
=
new
ConfigurationService
(
URI
.
file
(
res
.
testFile
),
fileService
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
await
service
.
initialize
();
await
testObject
.
initialize
();
let
config
=
service
.
getValue
<
{
let
config
=
testObject
.
getValue
<
{
foo
:
string
;
}
>
();
assert
.
ok
(
config
);
assert
.
equal
(
config
.
foo
,
'
bar
'
);
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "foo": "changed" }
'
);
// still outdated
config
=
service
.
getValue
<
{
foo
:
string
;
foo
:
string
;
}
>
();
}
>
();
assert
.
ok
(
config
);
assert
.
ok
(
config
);
assert
.
equal
(
config
.
foo
,
'
bar
'
);
assert
.
equal
(
config
.
foo
,
'
bar
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "foo": "changed" }
'
));
// force a reload to get latest
// force a reload to get latest
await
service
.
reloadConfiguration
();
await
testObject
.
reloadConfiguration
();
config
=
service
.
getValue
<
{
config
=
testObject
.
getValue
<
{
foo
:
string
;
foo
:
string
;
}
>
();
}
>
();
assert
.
ok
(
config
);
assert
.
ok
(
config
);
assert
.
equal
(
config
.
foo
,
'
changed
'
);
assert
.
equal
(
config
.
foo
,
'
changed
'
);
service
.
dispose
();
return
res
.
cleanUp
();
});
});
test
(
'
model defaults
'
,
async
()
=>
{
test
(
'
model defaults
'
,
async
()
=>
{
...
@@ -200,33 +163,27 @@ suite('ConfigurationService - Node', () => {
...
@@ -200,33 +163,27 @@ suite('ConfigurationService - Node', () => {
}
}
});
});
let
serviceWithoutFile
=
new
ConfigurationService
(
URI
.
file
(
'
__testFile
'
),
fileService
);
let
testObject
=
disposables
.
add
(
new
ConfigurationService
(
URI
.
file
(
'
__testFile
'
),
fileService
)
);
await
serviceWithoutFile
.
initialize
();
await
testObject
.
initialize
();
let
setting
=
serviceWithoutFile
.
getValue
<
ITestSetting
>
();
let
setting
=
testObject
.
getValue
<
ITestSetting
>
();
assert
.
ok
(
setting
);
assert
.
ok
(
setting
);
assert
.
equal
(
setting
.
configuration
.
service
.
testSetting
,
'
isSet
'
);
assert
.
equal
(
setting
.
configuration
.
service
.
testSetting
,
'
isSet
'
);
return
testFile
(
'
config
'
,
'
config.json
'
).
then
(
async
res
=>
{
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "testworkbench.editor.tabs": true }
'
));
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "testworkbench.editor.tabs": true }
'
);
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
)
);
const
service
=
new
ConfigurationService
(
URI
.
file
(
res
.
testFile
),
fileService
);
setting
=
testObject
.
getValue
<
ITestSetting
>
(
);
let
setting
=
service
.
getValue
<
ITestSetting
>
();
assert
.
ok
(
setting
);
assert
.
equal
(
setting
.
configuration
.
service
.
testSetting
,
'
isSet
'
);
assert
.
ok
(
setting
);
assert
.
equal
(
setting
.
configuration
.
service
.
testSetting
,
'
isSet
'
);
fs
.
writeFileSync
(
res
.
testFile
,
'
{ "configuration.service.testSetting": "isChanged" }
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "configuration.service.testSetting": "isChanged" }
'
)
);
await
service
.
reloadConfiguration
();
await
testObject
.
reloadConfiguration
();
let
setting_1
=
service
.
getValue
<
ITestSetting
>
();
setting
=
testObject
.
getValue
<
ITestSetting
>
();
assert
.
ok
(
setting_1
);
assert
.
ok
(
setting
);
assert
.
equal
(
setting_1
.
configuration
.
service
.
testSetting
,
'
isChanged
'
);
assert
.
equal
(
setting
.
configuration
.
service
.
testSetting
,
'
isChanged
'
);
service
.
dispose
();
serviceWithoutFile
.
dispose
();
return
res
.
cleanUp
();
});
});
});
test
(
'
lookup
'
,
async
()
=>
{
test
(
'
lookup
'
,
async
()
=>
{
...
@@ -242,30 +199,27 @@ suite('ConfigurationService - Node', () => {
...
@@ -242,30 +199,27 @@ suite('ConfigurationService - Node', () => {
}
}
});
});
const
r
=
await
testFile
(
'
config
'
,
'
config.json
'
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
const
service
=
new
ConfigurationService
(
URI
.
file
(
r
.
testFile
),
fileService
);
testObject
.
initialize
();
service
.
initialize
();
let
res
=
service
.
inspect
(
'
something.missing
'
);
let
res
=
testObject
.
inspect
(
'
something.missing
'
);
assert
.
strictEqual
(
res
.
value
,
undefined
);
assert
.
strictEqual
(
res
.
value
,
undefined
);
assert
.
strictEqual
(
res
.
defaultValue
,
undefined
);
assert
.
strictEqual
(
res
.
defaultValue
,
undefined
);
assert
.
strictEqual
(
res
.
userValue
,
undefined
);
assert
.
strictEqual
(
res
.
userValue
,
undefined
);
res
=
service
.
inspect
(
'
lookup.service.testSetting
'
);
res
=
testObject
.
inspect
(
'
lookup.service.testSetting
'
);
assert
.
strictEqual
(
res
.
defaultValue
,
'
isSet
'
);
assert
.
strictEqual
(
res
.
defaultValue
,
'
isSet
'
);
assert
.
strictEqual
(
res
.
value
,
'
isSet
'
);
assert
.
strictEqual
(
res
.
value
,
'
isSet
'
);
assert
.
strictEqual
(
res
.
userValue
,
undefined
);
assert
.
strictEqual
(
res
.
userValue
,
undefined
);
fs
.
writeFileSync
(
r
.
testFile
,
'
{ "lookup.service.testSetting": "bar" }
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "lookup.service.testSetting": "bar" }
'
)
);
await
service
.
reloadConfiguration
();
await
testObject
.
reloadConfiguration
();
res
=
service
.
inspect
(
'
lookup.service.testSetting
'
);
res
=
testObject
.
inspect
(
'
lookup.service.testSetting
'
);
assert
.
strictEqual
(
res
.
defaultValue
,
'
isSet
'
);
assert
.
strictEqual
(
res
.
defaultValue
,
'
isSet
'
);
assert
.
strictEqual
(
res
.
userValue
,
'
bar
'
);
assert
.
strictEqual
(
res
.
userValue
,
'
bar
'
);
assert
.
strictEqual
(
res
.
value
,
'
bar
'
);
assert
.
strictEqual
(
res
.
value
,
'
bar
'
);
service
.
dispose
();
return
r
.
cleanUp
();
});
});
test
(
'
lookup with null
'
,
async
()
=>
{
test
(
'
lookup with null
'
,
async
()
=>
{
...
@@ -280,25 +234,21 @@ suite('ConfigurationService - Node', () => {
...
@@ -280,25 +234,21 @@ suite('ConfigurationService - Node', () => {
}
}
});
});
const
r
=
await
testFile
(
'
config
'
,
'
config.json
'
);
const
testObject
=
disposables
.
add
(
new
ConfigurationService
(
settingsResource
,
fileService
));
const
service
=
new
ConfigurationService
(
URI
.
file
(
r
.
testFile
),
fileService
);
testObject
.
initialize
();
service
.
initialize
();
let
res
=
service
.
inspect
(
'
lookup.service.testNullSetting
'
);
let
res
=
testObject
.
inspect
(
'
lookup.service.testNullSetting
'
);
assert
.
strictEqual
(
res
.
defaultValue
,
null
);
assert
.
strictEqual
(
res
.
defaultValue
,
null
);
assert
.
strictEqual
(
res
.
value
,
null
);
assert
.
strictEqual
(
res
.
value
,
null
);
assert
.
strictEqual
(
res
.
userValue
,
undefined
);
assert
.
strictEqual
(
res
.
userValue
,
undefined
);
fs
.
writeFileSync
(
r
.
testFile
,
'
{ "lookup.service.testNullSetting": null }
'
);
await
fileService
.
writeFile
(
settingsResource
,
VSBuffer
.
fromString
(
'
{ "lookup.service.testNullSetting": null }
'
)
);
await
service
.
reloadConfiguration
();
await
testObject
.
reloadConfiguration
();
res
=
service
.
inspect
(
'
lookup.service.testNullSetting
'
);
res
=
testObject
.
inspect
(
'
lookup.service.testNullSetting
'
);
assert
.
strictEqual
(
res
.
defaultValue
,
null
);
assert
.
strictEqual
(
res
.
defaultValue
,
null
);
assert
.
strictEqual
(
res
.
value
,
null
);
assert
.
strictEqual
(
res
.
value
,
null
);
assert
.
strictEqual
(
res
.
userValue
,
null
);
assert
.
strictEqual
(
res
.
userValue
,
null
);
service
.
dispose
();
return
r
.
cleanUp
();
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录