@@ -4,7 +4,7 @@ const enhance = require('enhance-visitors');
4
4
const deepStrictEqual = require ( 'deep-strict-equal' ) ;
5
5
const util = require ( './util' ) ;
6
6
7
- const avaImportDeclarationAst = {
7
+ const avaImportDeclarationAsts = [ {
8
8
type : 'ImportDeclaration' ,
9
9
specifiers : [
10
10
{
@@ -19,9 +19,66 @@ const avaImportDeclarationAst = {
19
19
type : 'Literal' ,
20
20
value : 'ava'
21
21
}
22
- } ;
22
+ } , {
23
+ type : 'ImportDeclaration' ,
24
+ specifiers : [
25
+ {
26
+ type : 'ImportSpecifier' ,
27
+ imported : {
28
+ type : 'Identifier' ,
29
+ name : 'serial'
30
+ } ,
31
+ local : {
32
+ type : 'Identifier' ,
33
+ name : 'test'
34
+ }
35
+ }
36
+ ] ,
37
+ source : {
38
+ type : 'Literal' ,
39
+ value : 'ava'
40
+ }
41
+ } , {
42
+ type : 'ImportDeclaration' ,
43
+ specifiers : [
44
+ {
45
+ type : 'ImportSpecifier' ,
46
+ imported : {
47
+ type : 'Identifier' ,
48
+ name : 'serial'
49
+ } ,
50
+ local : {
51
+ type : 'Identifier' ,
52
+ name : 'test'
53
+ }
54
+ }
55
+ ] ,
56
+ source : {
57
+ type : 'Literal' ,
58
+ value : 'ava'
59
+ }
60
+ } , {
61
+ type : 'ImportDeclaration' ,
62
+ specifiers : [
63
+ {
64
+ type : 'ImportSpecifier' ,
65
+ imported : {
66
+ type : 'Identifier' ,
67
+ name : 'serial'
68
+ } ,
69
+ local : {
70
+ type : 'Identifier' ,
71
+ name : 'serial'
72
+ }
73
+ }
74
+ ] ,
75
+ source : {
76
+ type : 'Literal' ,
77
+ value : 'ava'
78
+ }
79
+ } ] ;
23
80
24
- const avaVariableDeclaratorAst = {
81
+ const avaVariableDeclaratorAsts = [ {
25
82
type : 'VariableDeclarator' ,
26
83
id : {
27
84
type : 'Identifier' ,
@@ -40,7 +97,73 @@ const avaVariableDeclaratorAst = {
40
97
}
41
98
]
42
99
}
43
- } ;
100
+ } , {
101
+ type : 'VariableDeclarator' ,
102
+ id : {
103
+ type : 'ObjectPattern' ,
104
+ properties : [ {
105
+ type : 'Property' ,
106
+ key : {
107
+ type : 'Identifier' ,
108
+ name : 'serial'
109
+ } ,
110
+ value : {
111
+ type : 'Identifier' ,
112
+ name : 'serial'
113
+ } ,
114
+ kind : 'init' ,
115
+ method : false ,
116
+ shorthand : true ,
117
+ computed : false
118
+ } ]
119
+ } ,
120
+ init : {
121
+ type : 'CallExpression' ,
122
+ callee : {
123
+ type : 'Identifier' ,
124
+ name : 'require'
125
+ } ,
126
+ arguments : [
127
+ {
128
+ type : 'Literal' ,
129
+ value : 'ava'
130
+ }
131
+ ]
132
+ }
133
+ } , {
134
+ type : 'VariableDeclarator' ,
135
+ id : {
136
+ type : 'ObjectPattern' ,
137
+ properties : [ {
138
+ type : 'Property' ,
139
+ key : {
140
+ type : 'Identifier' ,
141
+ name : 'serial'
142
+ } ,
143
+ value : {
144
+ type : 'Identifier' ,
145
+ name : 'test'
146
+ } ,
147
+ kind : 'init' ,
148
+ method : false ,
149
+ shorthand : false ,
150
+ computed : false
151
+ } ]
152
+ } ,
153
+ init : {
154
+ type : 'CallExpression' ,
155
+ callee : {
156
+ type : 'Identifier' ,
157
+ name : 'require'
158
+ } ,
159
+ arguments : [
160
+ {
161
+ type : 'Literal' ,
162
+ value : 'ava'
163
+ }
164
+ ]
165
+ }
166
+ } ] ;
44
167
45
168
function isTestFunctionCall ( node ) {
46
169
if ( node . type === 'Identifier' ) {
@@ -65,12 +188,12 @@ module.exports = () => {
65
188
/* eslint quote-props: [2, "as-needed"] */
66
189
const predefinedRules = {
67
190
ImportDeclaration : node => {
68
- if ( ! isTestFile && deepStrictEqual ( espurify ( node ) , avaImportDeclarationAst ) ) {
191
+ if ( ! isTestFile && avaImportDeclarationAsts . some ( ast => deepStrictEqual ( espurify ( node ) , ast ) ) ) {
69
192
isTestFile = true ;
70
193
}
71
194
} ,
72
195
VariableDeclarator : node => {
73
- if ( ! isTestFile && deepStrictEqual ( espurify ( node ) , avaVariableDeclaratorAst ) ) {
196
+ if ( ! isTestFile && avaVariableDeclaratorAsts . some ( ast => deepStrictEqual ( espurify ( node ) , ast ) ) ) {
74
197
isTestFile = true ;
75
198
}
76
199
} ,
0 commit comments