@@ -4,65 +4,38 @@ import { assert } from "chai";
4
4
import { sleepWithBackoff } from "../../endToEndTestSetup" ;
5
5
import { isEqual } from "lodash" ;
6
6
7
- async function sleepAndCheck < T > (
7
+ export async function assertCalledWithScopeInfo < T extends ScopeTypeInfo > (
8
8
fake : sinon . SinonSpy < [ scopeInfos : T [ ] ] , void > ,
9
- check : ( ) => void ,
9
+ ... expectedScopeInfos : T [ ]
10
10
) {
11
11
await sleepWithBackoff ( 25 ) ;
12
12
sinon . assert . called ( fake ) ;
13
13
14
- check ( ) ;
15
-
16
- fake . resetHistory ( ) ;
17
- }
18
-
19
- export function assertCalled < T extends ScopeTypeInfo > (
20
- fake : sinon . SinonSpy < [ scopeInfos : T [ ] ] , void > ,
21
- expectedScopeInfos : T [ ] ,
22
- expectedNotToHaveScopeTypes : ScopeType [ ] ,
23
- ) {
24
- return sleepAndCheck ( fake , ( ) => {
25
- assertCalledWith ( expectedScopeInfos , fake ) ;
26
- assertCalledWithout ( expectedNotToHaveScopeTypes , fake ) ;
27
- } ) ;
28
- }
29
-
30
- export function assertCalledWithScopeInfo < T extends ScopeTypeInfo > (
31
- fake : sinon . SinonSpy < [ scopeInfos : T [ ] ] , void > ,
32
- ...expectedScopeInfos : T [ ]
33
- ) {
34
- return sleepAndCheck ( fake , ( ) => assertCalledWith ( expectedScopeInfos , fake ) ) ;
35
- }
36
-
37
- export async function assertCalledWithoutScopeType < T extends ScopeTypeInfo > (
38
- fake : sinon . SinonSpy < [ scopeInfos : T [ ] ] , void > ,
39
- ...scopeTypes : ScopeType [ ]
40
- ) {
41
- return sleepAndCheck ( fake , ( ) => assertCalledWithout ( scopeTypes , fake ) ) ;
42
- }
43
-
44
- function assertCalledWith < T extends ScopeTypeInfo > (
45
- expectedScopeInfos : T [ ] ,
46
- fake : sinon . SinonSpy < [ scopeInfos : T [ ] ] , void > ,
47
- ) {
48
14
for ( const expectedScopeInfo of expectedScopeInfos ) {
49
15
const actualScopeInfo = fake . lastCall . args [ 0 ] . find ( ( scopeInfo ) =>
50
16
isEqual ( scopeInfo . scopeType , expectedScopeInfo . scopeType ) ,
51
17
) ;
52
18
assert . isDefined ( actualScopeInfo ) ;
53
19
assert . deepEqual ( actualScopeInfo , expectedScopeInfo ) ;
54
20
}
21
+
22
+ fake . resetHistory ( ) ;
55
23
}
56
24
57
- function assertCalledWithout < T extends ScopeTypeInfo > (
58
- scopeTypes : ScopeType [ ] ,
25
+ export async function assertCalledWithoutScopeInfo < T extends ScopeTypeInfo > (
59
26
fake : sinon . SinonSpy < [ scopeInfos : T [ ] ] , void > ,
27
+ ...scopeTypes : ScopeType [ ]
60
28
) {
29
+ await sleepWithBackoff ( 25 ) ;
30
+ sinon . assert . called ( fake ) ;
31
+
61
32
for ( const scopeType of scopeTypes ) {
62
33
assert . isUndefined (
63
34
fake . lastCall . args [ 0 ] . find ( ( scopeInfo ) =>
64
35
isEqual ( scopeInfo . scopeType , scopeType ) ,
65
36
) ,
66
37
) ;
67
38
}
39
+
40
+ fake . resetHistory ( ) ;
68
41
}
0 commit comments