4
4
ITestPlugin ,
5
5
ITestConfigItem ,
6
6
ITestPluginConfigItem ,
7
+ ITestPluginReturn ,
7
8
} from './type' ;
8
9
9
10
import defaultTestPlugin from './default-plugin' ;
@@ -20,30 +21,54 @@ export const startTest:IStartTest = ({
20
21
const onTestProcess = createTestProcess ( onTestSingle , onTestComplete ) ;
21
22
const length = cases . length ;
22
23
let testedNum = 0 ;
23
- cases . forEach ( async ( item , index ) => {
24
- if ( item . disabled ) return ;
25
- const mergedArgs = mergeArgs ( args , item . args ) ;
26
- if ( typeof item . test !== 'function' ) {
27
- item . test = ( ) => item . test ; // 支持test传入非函数
28
- } else {
29
- item . test = item . test . bind ( item ) ;
30
- }
31
- if ( typeof item . expect === 'function' ) { // 支持expect传入函数
32
- item . expect = item . expect . call ( item , mergedArgs ) ;
33
- }
34
- const startTime = new Date ( ) . getTime ( ) ;
35
- let result = pickPlugin ( item , plugin ) ( item as ITestPluginConfigItem , mergedArgs ) ;
36
- if ( result instanceof Promise ) { // 兼容 async plugin
37
- result = await result ;
38
- }
24
+
25
+ const trigTestProcess = ( {
26
+ index, time, result, name = ''
27
+ } : {
28
+ index : number , time : number , result : ITestPluginReturn , name ?: string ,
29
+ } ) => {
39
30
testedNum ++ ;
40
31
const singleOption : IOnTestSingleOption = {
41
32
...result ,
42
33
index,
43
- time : countTime ( startTime ) ,
34
+ time,
44
35
} ;
45
- if ( item . name ) { singleOption . name = item . name ; }
36
+ if ( name ) singleOption . name = name ;
46
37
onTestProcess ( singleOption , testedNum === length ) ;
38
+ } ;
39
+
40
+ cases . forEach ( async ( item , index ) => {
41
+ let time : number , result : ITestPluginReturn | Promise < ITestPluginReturn > ;
42
+ if ( item . disabled ) {
43
+ time = 0 ;
44
+ result = {
45
+ passed : true ,
46
+ disabled : true ,
47
+ result : '' ,
48
+ } ;
49
+ } else {
50
+ const startTime = Date . now ( ) ;
51
+ const mergedArgs = mergeArgs ( args , item . args ) ;
52
+ if ( typeof item . test !== 'function' ) {
53
+ item . test = ( ) => item . test ; // 支持test传入非函数
54
+ } else {
55
+ item . test = item . test . bind ( item ) ;
56
+ }
57
+ if ( typeof item . expect === 'function' ) { // 支持expect传入函数
58
+ item . expect = item . expect . call ( item , mergedArgs ) ;
59
+ }
60
+ result = pickPlugin ( item , plugin ) ( item as ITestPluginConfigItem , mergedArgs ) ;
61
+ if ( result instanceof Promise ) { // 兼容 async plugin
62
+ result = await result ;
63
+ }
64
+ time = countTime ( startTime ) ;
65
+ }
66
+ trigTestProcess ( {
67
+ name : item . name ,
68
+ index,
69
+ time,
70
+ result,
71
+ } ) ;
47
72
} ) ;
48
73
} ;
49
74
0 commit comments