Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
35aed337
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
35aed337
编写于
3月 04, 2021
作者:
C
Connor Peet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
testing: improve RequiredTestItem api
Fixes #117384
上级
db06103f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
60 addition
and
105 deletion
+60
-105
src/vs/vscode.proposed.d.ts
src/vs/vscode.proposed.d.ts
+42
-16
src/vs/workbench/api/common/extHostTesting.ts
src/vs/workbench/api/common/extHostTesting.ts
+6
-74
src/vs/workbench/api/common/extHostTypeConverters.ts
src/vs/workbench/api/common/extHostTypeConverters.ts
+1
-1
src/vs/workbench/api/common/extHostTypes.ts
src/vs/workbench/api/common/extHostTypes.ts
+5
-1
src/vs/workbench/test/browser/api/extHostTesting.test.ts
src/vs/workbench/test/browser/api/extHostTesting.test.ts
+6
-13
未找到文件。
src/vs/vscode.proposed.d.ts
浏览文件 @
35aed337
...
...
@@ -2200,7 +2200,7 @@ declare module 'vscode' {
/**
* List of tests returned by test provider for files in the workspace.
*/
readonly
tests
:
ReadonlyArray
<
Requir
edTestItem
>
;
readonly
tests
:
ReadonlyArray
<
Observ
edTestItem
>
;
/**
* An event that fires when an existing test in the collection changes, or
...
...
@@ -2230,23 +2230,17 @@ declare module 'vscode' {
/**
* List of all tests that are newly added.
*/
readonly
added
:
ReadonlyArray
<
Requir
edTestItem
>
;
readonly
added
:
ReadonlyArray
<
Observ
edTestItem
>
;
/**
* List of existing tests that have updated.
*/
readonly
updated
:
ReadonlyArray
<
Requir
edTestItem
>
;
readonly
updated
:
ReadonlyArray
<
Observ
edTestItem
>
;
/**
* List of existing tests that have been removed.
*/
readonly
removed
:
ReadonlyArray
<
RequiredTestItem
>
;
/**
* Highest node in the test tree under which changes were made. This can
* be easily plugged into events like the TreeDataProvider update event.
*/
readonly
commonChangeAncestor
:
RequiredTestItem
|
null
;
readonly
removed
:
ReadonlyArray
<
ObservedTestItem
>
;
}
/**
...
...
@@ -2432,13 +2426,45 @@ declare module 'vscode' {
}
/**
* A {@link TestItem} with its defaults filled in.
* A readonly {@link TestItem}-like interface with its defaults filled in,
* exposed in the {@link TestObserver} interface.
*/
export
type
RequiredTestItem
=
{
[
K
in
keyof
Required
<
TestItem
>
]:
K
extends
'
children
'
?
RequiredTestItem
[]
:
(
K
extends
'
description
'
|
'
location
'
?
TestItem
[
K
]
:
Required
<
TestItem
>
[
K
])
};
export
interface
ObservedTestItem
{
/**
* See {@link TestItem.id}
*/
readonly
id
:
string
;
/**
* See {@link TestItem.label}
*/
readonly
label
:
string
;
/**
* Optional description that appears next to the label.
*/
readonly
description
?:
string
;
/**
* See {@link TestItem.runnable}
*/
readonly
runnable
:
boolean
;
/**
* See {@link TestItem.debuggable}
*/
readonly
debuggable
:
boolean
;
/**
* See {@link TestItem.location}
*/
readonly
location
?:
Location
;
/**
* See {@link TestItem.children}
*/
readonly
children
:
ReadonlyArray
<
ObservedTestItem
>
;
}
/**
* Possible states of tests in a test run.
...
...
src/vs/workbench/api/common/extHostTesting.ts
浏览文件 @
35aed337
...
...
@@ -501,7 +501,7 @@ export class TestItemFilteredWrapper implements vscode.TestItem {
interface
MirroredCollectionTestItem
extends
IncrementalTestCollectionItem
{
revived
:
vscode
.
TestItem
;
depth
:
number
;
wrapped
?:
vscode
.
Requir
edTestItem
;
wrapped
?:
vscode
.
Observ
edTestItem
;
}
class
MirroredChangeCollector
extends
IncrementalChangeCollector
<
MirroredCollectionTestItem
>
{
...
...
@@ -564,74 +564,6 @@ class MirroredChangeCollector extends IncrementalChangeCollector<MirroredCollect
get
added
()
{
return
[...
added
].
map
(
collection
.
getPublicTestItem
,
collection
);
},
get
updated
()
{
return
[...
updated
].
map
(
collection
.
getPublicTestItem
,
collection
);
},
get
removed
()
{
return
[...
removed
].
map
(
collection
.
getPublicTestItem
,
collection
);
},
get
commonChangeAncestor
()
{
let
ancestorPath
:
MirroredCollectionTestItem
[]
|
undefined
;
const
buildAncestorPath
=
(
node
:
MirroredCollectionTestItem
|
undefined
)
=>
{
if
(
!
node
)
{
return
undefined
;
}
// add the node and all its parents to the list of ancestors. If
// the node is detached, do not return a path (its parent will
// also have been passed to remove() and be present)
const
path
:
MirroredCollectionTestItem
[]
=
new
Array
(
node
.
depth
+
1
);
for
(
let
i
=
node
.
depth
;
i
>=
0
;
i
--
)
{
if
(
!
node
)
{
return
undefined
;
// detached child
}
path
[
node
.
depth
]
=
node
;
node
=
node
.
parent
?
collection
.
getMirroredTestDataById
(
node
.
parent
)
:
undefined
;
}
return
path
;
};
const
addAncestorPath
=
(
node
:
MirroredCollectionTestItem
)
=>
{
// fast path: if the common ancestor is already the root, no more work to do
if
(
ancestorPath
&&
ancestorPath
.
length
===
0
)
{
return
;
}
const
thisPath
=
buildAncestorPath
(
node
);
if
(
!
thisPath
)
{
return
;
}
if
(
!
ancestorPath
)
{
ancestorPath
=
thisPath
;
return
;
}
// removes node from the path to the ancestor that don't match
// the corresponding node in *this* path.
for
(
let
i
=
ancestorPath
.
length
-
1
;
i
>=
0
;
i
--
)
{
if
(
ancestorPath
[
i
]
!==
thisPath
[
i
])
{
ancestorPath
.
pop
();
}
}
};
const
addParentAncestor
=
(
node
:
MirroredCollectionTestItem
)
=>
{
if
(
ancestorPath
&&
ancestorPath
.
length
===
0
)
{
// no-op
}
else
if
(
node
.
parent
===
null
)
{
ancestorPath
=
[];
}
else
{
const
parent
=
collection
.
getMirroredTestDataById
(
node
.
parent
);
if
(
parent
)
{
addAncestorPath
(
parent
);
}
}
};
for
(
const
node
of
added
)
{
addParentAncestor
(
node
);
}
for
(
const
node
of
updated
)
{
addAncestorPath
(
node
);
}
for
(
const
node
of
removed
)
{
addParentAncestor
(
node
);
}
const
ancestor
=
ancestorPath
&&
ancestorPath
[
ancestorPath
.
length
-
1
];
return
ancestor
?
collection
.
getPublicTestItem
(
ancestor
)
:
null
;
},
};
}
...
...
@@ -664,8 +596,8 @@ export class MirroredTestCollection extends AbstractIncrementalTestCollection<Mi
/**
* Translates the item IDs to TestItems for exposure to extensions.
*/
public
getAllAsTestItem
(
itemIds
:
Iterable
<
string
>
)
:
vscode
.
RequiredTestItem
[]
{
let
output
:
vscode
.
Requir
edTestItem
[]
=
[];
public
getAllAsTestItem
(
itemIds
:
Iterable
<
string
>
)
{
let
output
:
vscode
.
Observ
edTestItem
[]
=
[];
for
(
const
itemId
of
itemIds
)
{
const
item
=
this
.
items
.
get
(
itemId
);
if
(
item
)
{
...
...
@@ -708,7 +640,7 @@ export class MirroredTestCollection extends AbstractIncrementalTestCollection<Mi
/**
* Gets the public test item instance for the given mirrored record.
*/
public
getPublicTestItem
(
item
:
MirroredCollectionTestItem
):
vscode
.
Requir
edTestItem
{
public
getPublicTestItem
(
item
:
MirroredCollectionTestItem
):
vscode
.
Observ
edTestItem
{
if
(
!
item
.
wrapped
)
{
item
.
wrapped
=
new
TestItemFromMirror
(
item
,
this
);
}
...
...
@@ -717,7 +649,7 @@ export class MirroredTestCollection extends AbstractIncrementalTestCollection<Mi
}
}
class
TestItemFromMirror
implements
vscode
.
Requir
edTestItem
{
class
TestItemFromMirror
implements
vscode
.
Observ
edTestItem
{
readonly
#
internal
:
MirroredCollectionTestItem
;
readonly
#
collection
:
MirroredTestCollection
;
...
...
@@ -737,7 +669,7 @@ class TestItemFromMirror implements vscode.RequiredTestItem {
}
public
toJSON
()
{
const
serialized
:
vscode
.
Requir
edTestItem
&
TestIdWithProvider
=
{
const
serialized
:
vscode
.
Observ
edTestItem
&
TestIdWithProvider
=
{
id
:
this
.
id
,
label
:
this
.
label
,
description
:
this
.
description
,
...
...
src/vs/workbench/api/common/extHostTypeConverters.ts
浏览文件 @
35aed337
...
...
@@ -1637,7 +1637,7 @@ export namespace TestItem {
};
}
export
function
toShallow
(
item
:
ITestItem
):
Omit
<
vscode
.
RequiredTestItem
,
'
children
'
>
{
export
function
toShallow
(
item
:
ITestItem
):
Omit
<
types
.
RequiredTestItem
,
'
children
'
>
{
return
{
id
:
item
.
extId
,
label
:
item
.
label
,
...
...
src/vs/workbench/api/common/extHostTypes.ts
浏览文件 @
35aed337
...
...
@@ -3294,7 +3294,11 @@ export enum TestMessageSeverity {
Hint
=
3
}
export
type
RequiredTestItem
=
vscode
.
RequiredTestItem
;
export
type
RequiredTestItem
=
{
[
K
in
keyof
Required
<
TestItem
>
]:
K
extends
'
children
'
?
RequiredTestItem
[]
:
(
K
extends
'
description
'
|
'
location
'
?
TestItem
[
K
]
:
Required
<
TestItem
>
[
K
])
};
export
type
TestItem
=
vscode
.
TestItem
;
...
...
src/vs/workbench/test/browser/api/extHostTesting.test.ts
浏览文件 @
35aed337
...
...
@@ -9,12 +9,12 @@ import * as convert from 'vs/workbench/api/common/extHostTypeConverters';
import
{
TestDiffOpType
}
from
'
vs/workbench/contrib/testing/common/testCollection
'
;
import
{
stubTest
,
testStubs
}
from
'
vs/workbench/contrib/testing/common/testStubs
'
;
import
{
TestOwnedTestCollection
,
TestSingleUseCollection
}
from
'
vs/workbench/contrib/testing/test/common/ownedTestCollection
'
;
import
{
TestChangeEvent
,
TestItem
,
TextDocument
}
from
'
vscode
'
;
import
{
ObservedTestItem
,
TestChangeEvent
,
TestItem
,
TextDocument
}
from
'
vscode
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
Location
}
from
'
vs/editor/common/modes
'
;
import
{
Range
}
from
'
vs/editor/common/core/range
'
;
const
simplify
=
(
item
:
TestItem
)
=>
{
const
simplify
=
(
item
:
TestItem
|
ObservedTestItem
)
=>
{
if
(
'
toJSON
'
in
item
)
{
item
=
(
item
as
any
).
toJSON
();
delete
(
item
as
any
).
providerId
;
...
...
@@ -24,16 +24,16 @@ const simplify = (item: TestItem) => {
return
{
...
item
,
children
:
undefined
};
};
const
assertTreesEqual
=
(
a
:
Readonly
<
TestItem
>
,
b
:
Readonly
<
TestItem
>
)
=>
{
const
assertTreesEqual
=
(
a
:
TestItem
|
ObservedTestItem
,
b
:
TestItem
|
ObservedTestItem
)
=>
{
assert
.
deepStrictEqual
(
simplify
(
a
),
simplify
(
b
));
const
aChildren
=
(
a
.
children
??
[]).
sort
();
const
bChildren
=
(
b
.
children
??
[]).
sort
();
const
aChildren
=
(
a
.
children
??
[]).
s
lice
().
s
ort
();
const
bChildren
=
(
b
.
children
??
[]).
s
lice
().
s
ort
();
assert
.
strictEqual
(
aChildren
.
length
,
bChildren
.
length
,
`expected
${
a
.
label
}
.children.length ==
${
b
.
label
}
.children.length`
);
aChildren
.
forEach
((
_
,
i
)
=>
assertTreesEqual
(
aChildren
[
i
],
bChildren
[
i
]));
};
const
assertTreeListEqual
=
(
a
:
ReadonlyArray
<
Readonly
<
TestItem
>>
,
b
:
ReadonlyArray
<
Readonly
<
TestItem
>
>
)
=>
{
const
assertTreeListEqual
=
(
a
:
ReadonlyArray
<
TestItem
|
ObservedTestItem
>
,
b
:
ReadonlyArray
<
TestItem
|
ObservedTestItem
>
)
=>
{
assert
.
strictEqual
(
a
.
length
,
b
.
length
,
`expected a.length == n.length`
);
a
.
forEach
((
_
,
i
)
=>
assertTreesEqual
(
a
[
i
],
b
[
i
]));
};
...
...
@@ -187,7 +187,6 @@ suite('ExtHost Testing', () => {
});
test
(
'
creates change for root
'
,
()
=>
{
assert
.
deepStrictEqual
(
m
.
changeEvent
.
commonChangeAncestor
,
null
);
assertTreeListEqual
(
m
.
changeEvent
.
added
,
[
tests
,
tests
.
children
[
0
],
...
...
@@ -204,7 +203,6 @@ suite('ExtHost Testing', () => {
single
.
onItemChange
(
tests
,
'
pid
'
);
m
.
apply
(
single
.
collectDiff
());
assertTreesEqual
(
m
.
changeEvent
.
commonChangeAncestor
!
,
tests
);
assertTreeListEqual
(
m
.
changeEvent
.
added
,
[]);
assertTreeListEqual
(
m
.
changeEvent
.
removed
,
[
{
...
rm
,
children
:
[]
},
...
...
@@ -219,7 +217,6 @@ suite('ExtHost Testing', () => {
single
.
onItemChange
(
tests
,
'
pid
'
);
m
.
apply
(
single
.
collectDiff
());
assert
.
deepStrictEqual
(
m
.
changeEvent
.
commonChangeAncestor
?.
label
,
'
updated!
'
);
assertTreeListEqual
(
m
.
changeEvent
.
added
,
[]);
assertTreeListEqual
(
m
.
changeEvent
.
removed
,
[]);
assertTreeListEqual
(
m
.
changeEvent
.
updated
,
[
tests
.
children
[
0
]]);
...
...
@@ -244,7 +241,6 @@ suite('ExtHost Testing', () => {
single
.
onItemChange
(
tests
,
'
pid
'
);
m
.
apply
(
single
.
collectDiff
());
assert
.
strictEqual
(
m
.
changeEvent
.
commonChangeAncestor
?.
label
,
'
root
'
);
assertTreeListEqual
(
m
.
changeEvent
.
added
,
[
child
]);
assertTreeListEqual
(
m
.
changeEvent
.
removed
,
[]);
assertTreeListEqual
(
m
.
changeEvent
.
updated
,
[]);
...
...
@@ -256,7 +252,6 @@ suite('ExtHost Testing', () => {
single
.
onItemChange
(
tests
,
'
pid
'
);
m
.
apply
(
single
.
collectDiff
());
assert
.
strictEqual
(
m
.
changeEvent
.
commonChangeAncestor
?.
label
,
'
a
'
);
});
test
(
'
gets the common ancestor (2)
'
,
()
=>
{
...
...
@@ -264,8 +259,6 @@ suite('ExtHost Testing', () => {
tests
.
children
!
[
1
].
label
=
'
ab
'
;
single
.
onItemChange
(
tests
,
'
pid
'
);
m
.
apply
(
single
.
collectDiff
());
assert
.
strictEqual
(
m
.
changeEvent
.
commonChangeAncestor
?.
label
,
'
root
'
);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录