Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
148f67d7
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,体验更适合开发者的 AI 搜索 >>
提交
148f67d7
编写于
7月 30, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
when running integration tests, use memfs instead of fs
上级
f2b65a96
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
260 addition
and
42 deletion
+260
-42
extensions/vscode-api-tests/src/memfs.ts
extensions/vscode-api-tests/src/memfs.ts
+229
-0
extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts
...vscode-api-tests/src/singlefolder-tests/languages.test.ts
+2
-2
extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts
...vscode-api-tests/src/singlefolder-tests/workspace.test.ts
+4
-8
extensions/vscode-api-tests/src/utils.ts
extensions/vscode-api-tests/src/utils.ts
+25
-32
未找到文件。
extensions/vscode-api-tests/src/memfs.ts
0 → 100644
浏览文件 @
148f67d7
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
*
as
path
from
'
path
'
;
import
*
as
vscode
from
'
vscode
'
;
class
File
implements
vscode
.
FileStat
{
type
:
vscode
.
FileType
;
ctime
:
number
;
mtime
:
number
;
size
:
number
;
name
:
string
;
data
?:
Uint8Array
;
constructor
(
name
:
string
)
{
this
.
type
=
vscode
.
FileType
.
File
;
this
.
ctime
=
Date
.
now
();
this
.
mtime
=
Date
.
now
();
this
.
size
=
0
;
this
.
name
=
name
;
}
}
class
Directory
implements
vscode
.
FileStat
{
type
:
vscode
.
FileType
;
ctime
:
number
;
mtime
:
number
;
size
:
number
;
name
:
string
;
entries
:
Map
<
string
,
File
|
Directory
>
;
constructor
(
name
:
string
)
{
this
.
type
=
vscode
.
FileType
.
Directory
;
this
.
ctime
=
Date
.
now
();
this
.
mtime
=
Date
.
now
();
this
.
size
=
0
;
this
.
name
=
name
;
this
.
entries
=
new
Map
();
}
}
export
type
Entry
=
File
|
Directory
;
export
class
MemFS
implements
vscode
.
FileSystemProvider
{
readonly
scheme
=
'
fake-fs
'
;
readonly
root
=
new
Directory
(
''
);
// --- manage file metadata
stat
(
uri
:
vscode
.
Uri
):
vscode
.
FileStat
{
return
this
.
_lookup
(
uri
,
false
);
}
readDirectory
(
uri
:
vscode
.
Uri
):
[
string
,
vscode
.
FileType
][]
{
const
entry
=
this
.
_lookupAsDirectory
(
uri
,
false
);
let
result
:
[
string
,
vscode
.
FileType
][]
=
[];
for
(
const
[
name
,
child
]
of
entry
.
entries
)
{
result
.
push
([
name
,
child
.
type
]);
}
return
result
;
}
// --- manage file contents
readFile
(
uri
:
vscode
.
Uri
):
Uint8Array
{
const
data
=
this
.
_lookupAsFile
(
uri
,
false
).
data
;
if
(
data
)
{
return
data
;
}
throw
vscode
.
FileSystemError
.
FileNotFound
();
}
writeFile
(
uri
:
vscode
.
Uri
,
content
:
Uint8Array
,
options
:
{
create
:
boolean
,
overwrite
:
boolean
}):
void
{
let
basename
=
path
.
posix
.
basename
(
uri
.
path
);
let
parent
=
this
.
_lookupParentDirectory
(
uri
);
let
entry
=
parent
.
entries
.
get
(
basename
);
if
(
entry
instanceof
Directory
)
{
throw
vscode
.
FileSystemError
.
FileIsADirectory
(
uri
);
}
if
(
!
entry
&&
!
options
.
create
)
{
throw
vscode
.
FileSystemError
.
FileNotFound
(
uri
);
}
if
(
entry
&&
options
.
create
&&
!
options
.
overwrite
)
{
throw
vscode
.
FileSystemError
.
FileExists
(
uri
);
}
if
(
!
entry
)
{
entry
=
new
File
(
basename
);
parent
.
entries
.
set
(
basename
,
entry
);
this
.
_fireSoon
({
type
:
vscode
.
FileChangeType
.
Created
,
uri
});
}
entry
.
mtime
=
Date
.
now
();
entry
.
size
=
content
.
byteLength
;
entry
.
data
=
content
;
this
.
_fireSoon
({
type
:
vscode
.
FileChangeType
.
Changed
,
uri
});
}
// --- manage files/folders
rename
(
oldUri
:
vscode
.
Uri
,
newUri
:
vscode
.
Uri
,
options
:
{
overwrite
:
boolean
}):
void
{
if
(
!
options
.
overwrite
&&
this
.
_lookup
(
newUri
,
true
))
{
throw
vscode
.
FileSystemError
.
FileExists
(
newUri
);
}
let
entry
=
this
.
_lookup
(
oldUri
,
false
);
let
oldParent
=
this
.
_lookupParentDirectory
(
oldUri
);
let
newParent
=
this
.
_lookupParentDirectory
(
newUri
);
let
newName
=
path
.
posix
.
basename
(
newUri
.
path
);
oldParent
.
entries
.
delete
(
entry
.
name
);
entry
.
name
=
newName
;
newParent
.
entries
.
set
(
newName
,
entry
);
this
.
_fireSoon
(
{
type
:
vscode
.
FileChangeType
.
Deleted
,
uri
:
oldUri
},
{
type
:
vscode
.
FileChangeType
.
Created
,
uri
:
newUri
}
);
}
delete
(
uri
:
vscode
.
Uri
):
void
{
let
dirname
=
uri
.
with
({
path
:
path
.
posix
.
dirname
(
uri
.
path
)
});
let
basename
=
path
.
posix
.
basename
(
uri
.
path
);
let
parent
=
this
.
_lookupAsDirectory
(
dirname
,
false
);
if
(
!
parent
.
entries
.
has
(
basename
))
{
throw
vscode
.
FileSystemError
.
FileNotFound
(
uri
);
}
parent
.
entries
.
delete
(
basename
);
parent
.
mtime
=
Date
.
now
();
parent
.
size
-=
1
;
this
.
_fireSoon
({
type
:
vscode
.
FileChangeType
.
Changed
,
uri
:
dirname
},
{
uri
,
type
:
vscode
.
FileChangeType
.
Deleted
});
}
createDirectory
(
uri
:
vscode
.
Uri
):
void
{
let
basename
=
path
.
posix
.
basename
(
uri
.
path
);
let
dirname
=
uri
.
with
({
path
:
path
.
posix
.
dirname
(
uri
.
path
)
});
let
parent
=
this
.
_lookupAsDirectory
(
dirname
,
false
);
let
entry
=
new
Directory
(
basename
);
parent
.
entries
.
set
(
entry
.
name
,
entry
);
parent
.
mtime
=
Date
.
now
();
parent
.
size
+=
1
;
this
.
_fireSoon
({
type
:
vscode
.
FileChangeType
.
Changed
,
uri
:
dirname
},
{
type
:
vscode
.
FileChangeType
.
Created
,
uri
});
}
// --- lookup
private
_lookup
(
uri
:
vscode
.
Uri
,
silent
:
false
):
Entry
;
private
_lookup
(
uri
:
vscode
.
Uri
,
silent
:
boolean
):
Entry
|
undefined
;
private
_lookup
(
uri
:
vscode
.
Uri
,
silent
:
boolean
):
Entry
|
undefined
{
let
parts
=
uri
.
path
.
split
(
'
/
'
);
let
entry
:
Entry
=
this
.
root
;
for
(
const
part
of
parts
)
{
if
(
!
part
)
{
continue
;
}
let
child
:
Entry
|
undefined
;
if
(
entry
instanceof
Directory
)
{
child
=
entry
.
entries
.
get
(
part
);
}
if
(
!
child
)
{
if
(
!
silent
)
{
throw
vscode
.
FileSystemError
.
FileNotFound
(
uri
);
}
else
{
return
undefined
;
}
}
entry
=
child
;
}
return
entry
;
}
private
_lookupAsDirectory
(
uri
:
vscode
.
Uri
,
silent
:
boolean
):
Directory
{
let
entry
=
this
.
_lookup
(
uri
,
silent
);
if
(
entry
instanceof
Directory
)
{
return
entry
;
}
throw
vscode
.
FileSystemError
.
FileNotADirectory
(
uri
);
}
private
_lookupAsFile
(
uri
:
vscode
.
Uri
,
silent
:
boolean
):
File
{
let
entry
=
this
.
_lookup
(
uri
,
silent
);
if
(
entry
instanceof
File
)
{
return
entry
;
}
throw
vscode
.
FileSystemError
.
FileIsADirectory
(
uri
);
}
private
_lookupParentDirectory
(
uri
:
vscode
.
Uri
):
Directory
{
const
dirname
=
uri
.
with
({
path
:
path
.
posix
.
dirname
(
uri
.
path
)
});
return
this
.
_lookupAsDirectory
(
dirname
,
false
);
}
// --- manage file events
private
_emitter
=
new
vscode
.
EventEmitter
<
vscode
.
FileChangeEvent
[]
>
();
private
_bufferedEvents
:
vscode
.
FileChangeEvent
[]
=
[];
private
_fireSoonHandle
?:
NodeJS
.
Timer
;
readonly
onDidChangeFile
:
vscode
.
Event
<
vscode
.
FileChangeEvent
[]
>
=
this
.
_emitter
.
event
;
watch
(
_resource
:
vscode
.
Uri
):
vscode
.
Disposable
{
// ignore, fires for all changes...
return
new
vscode
.
Disposable
(()
=>
{
});
}
private
_fireSoon
(...
events
:
vscode
.
FileChangeEvent
[]):
void
{
this
.
_bufferedEvents
.
push
(...
events
);
if
(
this
.
_fireSoonHandle
)
{
clearTimeout
(
this
.
_fireSoonHandle
);
}
this
.
_fireSoonHandle
=
setTimeout
(()
=>
{
this
.
_emitter
.
fire
(
this
.
_bufferedEvents
);
this
.
_bufferedEvents
.
length
=
0
;
},
5
);
}
}
extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts
浏览文件 @
148f67d7
...
...
@@ -6,7 +6,7 @@
import
*
as
assert
from
'
assert
'
;
import
{
join
}
from
'
path
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
createRandomFile
}
from
'
../utils
'
;
import
{
createRandomFile
,
testFs
}
from
'
../utils
'
;
suite
(
'
languages namespace tests
'
,
()
=>
{
...
...
@@ -103,7 +103,7 @@ suite('languages namespace tests', () => {
return
[
new
vscode
.
DocumentLink
(
range
,
target
)];
}
};
vscode
.
languages
.
registerDocumentLinkProvider
({
language
:
'
java
'
,
scheme
:
'
file
'
},
linkProvider
);
vscode
.
languages
.
registerDocumentLinkProvider
({
language
:
'
java
'
,
scheme
:
testFs
.
scheme
},
linkProvider
);
const
links
=
await
vscode
.
commands
.
executeCommand
<
vscode
.
DocumentLink
[]
>
(
'
vscode.executeLinkProvider
'
,
doc
.
uri
);
assert
.
equal
(
2
,
links
&&
links
.
length
);
...
...
extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts
浏览文件 @
148f67d7
...
...
@@ -5,10 +5,9 @@
import
*
as
assert
from
'
assert
'
;
import
*
as
vscode
from
'
vscode
'
;
import
{
createRandomFile
,
deleteFile
,
closeAllEditors
,
pathEquals
,
rndName
,
disposeAll
}
from
'
../utils
'
;
import
{
createRandomFile
,
deleteFile
,
closeAllEditors
,
pathEquals
,
rndName
,
disposeAll
,
testFs
}
from
'
../utils
'
;
import
{
join
,
posix
,
basename
}
from
'
path
'
;
import
*
as
fs
from
'
fs
'
;
import
*
as
os
from
'
os
'
;
suite
(
'
workspace-namespace
'
,
()
=>
{
...
...
@@ -131,8 +130,7 @@ suite('workspace-namespace', () => {
assert
.
ok
(
fs
.
existsSync
(
path
));
d0
.
dispose
();
return
deleteFile
(
vscode
.
Uri
.
file
(
join
(
vscode
.
workspace
.
rootPath
||
''
,
'
./newfile.txt
'
)));
fs
.
unlinkSync
(
join
(
vscode
.
workspace
.
rootPath
||
''
,
'
./newfile.txt
'
));
});
});
...
...
@@ -702,10 +700,8 @@ suite('workspace-namespace', () => {
test
(
'
WorkspaceEdit: edit and rename parent folder duplicates resource #42641
'
,
async
function
()
{
let
dir
=
join
(
os
.
tmpdir
(),
'
before-
'
+
rndName
());
if
(
!
fs
.
existsSync
(
dir
))
{
fs
.
mkdirSync
(
dir
);
}
let
dir
=
vscode
.
Uri
.
parse
(
`
${
testFs
.
scheme
}
:/before-
${
rndName
()}
`
);
await
testFs
.
createDirectory
(
dir
);
let
docUri
=
await
createRandomFile
(
''
,
dir
);
let
docParent
=
docUri
.
with
({
path
:
posix
.
dirname
(
docUri
.
path
)
});
...
...
extensions/vscode-api-tests/src/utils.ts
浏览文件 @
148f67d7
...
...
@@ -4,25 +4,35 @@
*--------------------------------------------------------------------------------------------*/
import
*
as
vscode
from
'
vscode
'
;
import
*
as
fs
from
'
fs
'
;
import
*
as
os
from
'
os
'
;
import
{
join
}
from
'
path
'
;
import
{
MemFS
}
from
'
./memfs
'
;
import
*
as
assert
from
'
assert
'
;
export
function
rndName
()
{
return
Math
.
random
().
toString
(
36
).
replace
(
/
[^
a-z
]
+/g
,
''
).
substr
(
0
,
10
);
}
export
function
createRandomFile
(
contents
=
''
,
dir
:
string
=
os
.
tmpdir
(),
ext
=
''
):
Thenable
<
vscode
.
Uri
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
tmpFile
=
join
(
dir
,
rndName
()
+
ext
);
fs
.
writeFile
(
tmpFile
,
contents
,
(
error
)
=>
{
if
(
error
)
{
return
reject
(
error
);
}
export
const
testFs
=
new
MemFS
();
vscode
.
workspace
.
registerFileSystemProvider
(
testFs
.
scheme
,
testFs
);
resolve
(
vscode
.
Uri
.
file
(
tmpFile
));
});
});
export
async
function
createRandomFile
(
contents
=
''
,
dir
:
vscode
.
Uri
|
undefined
=
undefined
,
ext
=
''
):
Promise
<
vscode
.
Uri
>
{
let
fakeFile
:
vscode
.
Uri
;
if
(
dir
)
{
assert
.
equal
(
dir
.
scheme
,
testFs
.
scheme
);
fakeFile
=
dir
.
with
({
path
:
dir
.
path
+
'
/
'
+
rndName
()
+
ext
});
}
else
{
fakeFile
=
vscode
.
Uri
.
parse
(
`
${
testFs
.
scheme
}
:/
${
rndName
()
+
ext
}
`
);
}
await
testFs
.
writeFile
(
fakeFile
,
Buffer
.
from
(
contents
),
{
create
:
true
,
overwrite
:
true
});
return
fakeFile
;
}
export
async
function
deleteFile
(
file
:
vscode
.
Uri
):
Promise
<
boolean
>
{
try
{
await
testFs
.
delete
(
file
);
return
true
;
}
catch
{
return
false
;
}
}
export
function
pathEquals
(
path1
:
string
,
path2
:
string
):
boolean
{
...
...
@@ -34,30 +44,13 @@ export function pathEquals(path1: string, path2: string): boolean {
return
path1
===
path2
;
}
export
function
deleteFile
(
file
:
vscode
.
Uri
):
Thenable
<
boolean
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fs
.
unlink
(
file
.
fsPath
,
(
err
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
true
);
}
});
});
}
export
function
closeAllEditors
():
Thenable
<
any
>
{
return
vscode
.
commands
.
executeCommand
(
'
workbench.action.closeAllEditors
'
);
}
export
function
disposeAll
(
disposables
:
vscode
.
Disposable
[])
{
while
(
disposables
.
length
)
{
let
item
=
disposables
.
pop
();
if
(
item
)
{
item
.
dispose
();
}
}
vscode
.
Disposable
.
from
(...
disposables
).
dispose
();
}
export
function
conditionalTest
(
name
:
string
,
testCallback
:
(
done
:
MochaDone
)
=>
void
|
Thenable
<
any
>
)
{
...
...
@@ -73,4 +66,4 @@ export function conditionalTest(name: string, testCallback: (done: MochaDone) =>
function
isTestTypeActive
():
boolean
{
return
!!
vscode
.
extensions
.
getExtension
(
'
vscode-resolver-test
'
);
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录