@@ -15,6 +15,8 @@ module.exports = {
15
15
const astUtils = createAstUtils ( context . settings ) ;
16
16
let testNestingLevel = 0 ;
17
17
let hookCallNestingLevel = 0 ;
18
+ const isTestCase = astUtils . buildIsTestCaseAnswerer ( ) ;
19
+ const isDescribe = astUtils . buildIsDescribeAnswerer ( ) ;
18
20
19
21
function report ( callExpression , message ) {
20
22
context . report ( {
@@ -23,26 +25,26 @@ module.exports = {
23
25
} ) ;
24
26
}
25
27
26
- function isNestedTest ( isTestCase , isDescribe , nestingLevel ) {
28
+ function isNestedTest ( _isTestCase , _isDescribe , nestingLevel ) {
27
29
const isNested = nestingLevel > 0 ;
28
- const isTest = isTestCase || isDescribe ;
30
+ const isTest = _isTestCase || _isDescribe ;
29
31
30
32
return isNested && isTest ;
31
33
}
32
34
33
35
function checkForAndReportErrors (
34
36
node ,
35
- isTestCase ,
36
- isDescribe ,
37
+ _isTestCase ,
38
+ _isDescribe ,
37
39
isHookCall
38
40
) {
39
- if ( isNestedTest ( isTestCase , isDescribe , testNestingLevel ) ) {
40
- const message = isDescribe ?
41
+ if ( isNestedTest ( _isTestCase , _isDescribe , testNestingLevel ) ) {
42
+ const message = _isDescribe ?
41
43
'Unexpected suite nested within a test.' :
42
44
'Unexpected test nested within another test.' ;
43
45
report ( node , message ) ;
44
46
} else if (
45
- isNestedTest ( isTestCase , isHookCall , hookCallNestingLevel )
47
+ isNestedTest ( _isTestCase , isHookCall , hookCallNestingLevel )
46
48
) {
47
49
const message = isHookCall ?
48
50
'Unexpected test hook nested within a test hook.' :
@@ -53,26 +55,26 @@ module.exports = {
53
55
54
56
return {
55
57
CallExpression ( node ) {
56
- const isTestCase = astUtils . isTestCase ( node ) ;
58
+ const _isTestCase = isTestCase ( node ) ;
57
59
const isHookCall = astUtils . isHookCall ( node ) ;
58
- const isDescribe = astUtils . isDescribe ( node ) ;
60
+ const _isDescribe = isDescribe ( node ) ;
59
61
60
62
checkForAndReportErrors (
61
63
node ,
62
- isTestCase ,
63
- isDescribe ,
64
+ _isTestCase ,
65
+ _isDescribe ,
64
66
isHookCall
65
67
) ;
66
68
67
- if ( isTestCase ) {
69
+ if ( _isTestCase ) {
68
70
testNestingLevel += 1 ;
69
71
} else if ( isHookCall ) {
70
72
hookCallNestingLevel += 1 ;
71
73
}
72
74
} ,
73
75
74
76
'CallExpression:exit' ( node ) {
75
- if ( astUtils . isTestCase ( node ) ) {
77
+ if ( isTestCase ( node ) ) {
76
78
testNestingLevel -= 1 ;
77
79
} else if ( astUtils . isHookCall ( node ) ) {
78
80
hookCallNestingLevel -= 1 ;
0 commit comments