@@ -10,7 +10,11 @@ function newLayer() {
10
10
}
11
11
12
12
function isFirstArgLiteral ( node ) {
13
- return node . arguments && node . arguments [ 0 ] && node . arguments [ 0 ] . type === 'Literal' ;
13
+ return (
14
+ node . arguments &&
15
+ node . arguments [ 0 ] &&
16
+ node . arguments [ 0 ] . type === 'Literal'
17
+ ) ;
14
18
}
15
19
16
20
module . exports = {
@@ -22,22 +26,26 @@ module.exports = {
22
26
} ,
23
27
create ( context ) {
24
28
const astUtils = createAstUtils ( context . settings ) ;
29
+ const isTestCase = astUtils . buildIsTestCaseAnswerer ( ) ;
30
+ const isDescribe = astUtils . buildIsDescribeAnswerer ( ) ;
31
+
25
32
const titleLayers = [ newLayer ( ) ] ;
26
33
27
34
function handlTestCaseTitles ( titles , node , title ) {
28
- if ( astUtils . isTestCase ( node ) ) {
35
+ if ( isTestCase ( node ) ) {
29
36
if ( titles . includes ( title ) ) {
30
37
context . report ( {
31
38
node,
32
- message : 'Test title is used multiple times in the same test suite.'
39
+ message :
40
+ 'Test title is used multiple times in the same test suite.'
33
41
} ) ;
34
42
}
35
43
titles . push ( title ) ;
36
44
}
37
45
}
38
46
39
47
function handlTestSuiteTitles ( titles , node , title ) {
40
- if ( ! astUtils . isDescribe ( node ) ) {
48
+ if ( ! isDescribe ( node ) ) {
41
49
return ;
42
50
}
43
51
if ( titles . includes ( title ) ) {
@@ -53,7 +61,7 @@ module.exports = {
53
61
CallExpression ( node ) {
54
62
const currentLayer = titleLayers [ titleLayers . length - 1 ] ;
55
63
56
- if ( astUtils . isDescribe ( node ) ) {
64
+ if ( isDescribe ( node ) ) {
57
65
titleLayers . push ( newLayer ( ) ) ;
58
66
}
59
67
if ( ! isFirstArgLiteral ( node ) ) {
@@ -65,7 +73,7 @@ module.exports = {
65
73
handlTestSuiteTitles ( currentLayer . describeTitles , node , title ) ;
66
74
} ,
67
75
'CallExpression:exit' ( node ) {
68
- if ( astUtils . isDescribe ( node ) ) {
76
+ if ( isDescribe ( node ) ) {
69
77
titleLayers . pop ( ) ;
70
78
}
71
79
}
0 commit comments