@@ -23,12 +23,15 @@ test('ignores relativeness in patterns', t => {
23
23
} ) ;
24
24
25
25
test ( 'isTest' , t => {
26
- const options = globs . normalizeGlobs (
27
- [ '**/foo*.js' , '**/foo*/**/*.js' , '!**/fixtures' , '!**/helpers' ] ,
28
- undefined ,
29
- undefined ,
30
- [ 'js' ]
31
- ) ;
26
+ const options = {
27
+ ...globs . normalizeGlobs (
28
+ [ '**/foo*.js' , '**/foo*/**/*.js' , '!**/fixtures' , '!**/helpers' ] ,
29
+ undefined ,
30
+ undefined ,
31
+ [ 'js' ]
32
+ ) ,
33
+ cwd : fixture ( )
34
+ } ;
32
35
33
36
function isTest ( file ) {
34
37
t . true ( globs . classify ( fixture ( file ) , options ) . isTest , `${ file } should be a test` ) ;
@@ -55,15 +58,54 @@ test('isTest', t => {
55
58
t . end ( ) ;
56
59
} ) ;
57
60
61
+ test ( 'isTest (pattern starts with directory)' , t => {
62
+ const options = {
63
+ ...globs . normalizeGlobs (
64
+ [ 'bar/**/*' ] ,
65
+ undefined ,
66
+ undefined ,
67
+ [ 'js' ]
68
+ ) ,
69
+ cwd : fixture ( )
70
+ } ;
71
+
72
+ function isTest ( file ) {
73
+ t . true ( globs . classify ( fixture ( file ) , options ) . isTest , `${ file } should be a test` ) ;
74
+ }
75
+
76
+ function notTest ( file ) {
77
+ t . false ( globs . classify ( fixture ( file ) , options ) . isTest , `${ file } should not be a test` ) ;
78
+ }
79
+
80
+ notTest ( 'foo-bar.js' ) ;
81
+ notTest ( 'foo.js' ) ;
82
+ notTest ( 'foo/blah.js' ) ;
83
+ isTest ( 'bar/foo.js' ) ;
84
+ isTest ( 'bar/foo-bar/baz/buz.js' ) ;
85
+ isTest ( 'bar/baz/buz.js' ) ;
86
+ notTest ( 'bar.js' ) ;
87
+ isTest ( 'bar/bar.js' ) ;
88
+ notTest ( 'bar/_foo-bar.js' ) ;
89
+ notTest ( 'foo/_foo-bar.js' ) ;
90
+ notTest ( 'foo-bar.txt' ) ;
91
+ notTest ( 'node_modules/foo.js' ) ;
92
+ notTest ( 'fixtures/foo.js' ) ;
93
+ notTest ( 'helpers/foo.js' ) ;
94
+ t . end ( ) ;
95
+ } ) ;
96
+
58
97
test ( 'isSource with defaults' , t => {
59
- const options = globs . normalizeGlobs ( undefined , undefined , undefined , [ 'js' ] ) ;
98
+ const options = {
99
+ ...globs . normalizeGlobs ( undefined , undefined , undefined , [ 'js' ] ) ,
100
+ cwd : fixture ( )
101
+ } ;
60
102
61
103
function isSource ( file ) {
62
- t . true ( globs . classify ( file , options ) . isSource , `${ file } should be a source` ) ;
104
+ t . true ( globs . classify ( fixture ( file ) , options ) . isSource , `${ file } should be a source` ) ;
63
105
}
64
106
65
107
function notSource ( file ) {
66
- t . false ( globs . classify ( file , options ) . isSource , `${ file } should not be a source` ) ;
108
+ t . false ( globs . classify ( fixture ( file ) , options ) . isSource , `${ file } should not be a source` ) ;
67
109
}
68
110
69
111
isSource ( 'foo-bar.js' ) ;
@@ -91,28 +133,51 @@ test('isSource with defaults', t => {
91
133
} ) ;
92
134
93
135
test ( 'isSource with negation negation patterns' , t => {
94
- const options = globs . normalizeGlobs (
95
- [ '**/foo*' ] ,
96
- undefined ,
97
- [ '!**/bar*' ] ,
98
- [ 'js' ]
99
- ) ;
100
-
101
- t . false ( globs . classify ( 'node_modules/foo/foo.js' , options ) . isSource ) ;
102
- t . false ( globs . classify ( 'bar.js' , options ) . isSource ) ;
103
- t . false ( globs . classify ( 'foo/bar.js' , options ) . isSource ) ;
136
+ const options = {
137
+ ...globs . normalizeGlobs (
138
+ [ '**/foo*' ] ,
139
+ undefined ,
140
+ [ '!**/bar*' ] ,
141
+ [ 'js' ]
142
+ ) ,
143
+ cwd : fixture ( )
144
+ } ;
145
+
146
+ t . false ( globs . classify ( fixture ( 'node_modules/foo/foo.js' ) , options ) . isSource ) ;
147
+ t . false ( globs . classify ( fixture ( 'bar.js' ) , options ) . isSource ) ;
148
+ t . false ( globs . classify ( fixture ( 'foo/bar.js' ) , options ) . isSource ) ;
149
+ t . end ( ) ;
150
+ } ) ;
151
+
152
+ test ( 'isSource (pattern starts with directory)' , t => {
153
+ const options = {
154
+ ...globs . normalizeGlobs (
155
+ [ '**/foo*' ] ,
156
+ undefined ,
157
+ [ 'foo/**/*' ] ,
158
+ [ 'js' ]
159
+ ) ,
160
+ cwd : fixture ( )
161
+ } ;
162
+
163
+ t . false ( globs . classify ( fixture ( 'node_modules/foo/foo.js' ) , options ) . isSource ) ;
164
+ t . false ( globs . classify ( fixture ( 'bar.js' ) , options ) . isSource ) ;
165
+ t . true ( globs . classify ( fixture ( 'foo/bar.js' ) , options ) . isSource ) ;
104
166
t . end ( ) ;
105
167
} ) ;
106
168
107
169
test ( 'isHelper (prefixed only)' , t => {
108
- const options = globs . normalizeGlobs ( undefined , undefined , undefined , [ 'js' ] ) ;
170
+ const options = {
171
+ ...globs . normalizeGlobs ( undefined , undefined , undefined , [ 'js' ] ) ,
172
+ cwd : fixture ( )
173
+ } ;
109
174
110
175
function isHelper ( file ) {
111
- t . true ( globs . classify ( file , options ) . isHelper , `${ file } should be a helper` ) ;
176
+ t . true ( globs . classify ( fixture ( file ) , options ) . isHelper , `${ file } should be a helper` ) ;
112
177
}
113
178
114
179
function notHelper ( file ) {
115
- t . false ( globs . classify ( file , options ) . isHelper , `${ file } should not be a helper` ) ;
180
+ t . false ( globs . classify ( fixture ( file ) , options ) . isHelper , `${ file } should not be a helper` ) ;
116
181
}
117
182
118
183
notHelper ( 'foo.js' ) ;
@@ -133,14 +198,17 @@ test('isHelper (prefixed only)', t => {
133
198
} ) ;
134
199
135
200
test ( 'isHelper (with patterns)' , t => {
136
- const options = globs . normalizeGlobs ( undefined , [ '**/f*.*' ] , undefined , [ 'js' ] ) ;
201
+ const options = {
202
+ ...globs . normalizeGlobs ( undefined , [ '**/f*.*' ] , undefined , [ 'js' ] ) ,
203
+ cwd : fixture ( )
204
+ } ;
137
205
138
206
function isHelper ( file ) {
139
- t . true ( globs . classify ( file , options ) . isHelper , `${ file } should be a helper` ) ;
207
+ t . true ( globs . classify ( fixture ( file ) , options ) . isHelper , `${ file } should be a helper` ) ;
140
208
}
141
209
142
210
function notHelper ( file ) {
143
- t . false ( globs . classify ( file , options ) . isHelper , `${ file } should not be a helper` ) ;
211
+ t . false ( globs . classify ( fixture ( file ) , options ) . isHelper , `${ file } should not be a helper` ) ;
144
212
}
145
213
146
214
isHelper ( 'foo.js' ) ;
@@ -160,6 +228,37 @@ test('isHelper (with patterns)', t => {
160
228
t . end ( ) ;
161
229
} ) ;
162
230
231
+ test ( 'isHelper (pattern stars with directory)' , t => {
232
+ const options = {
233
+ ...globs . normalizeGlobs ( undefined , [ 'foo/**/*' ] , undefined , [ 'js' ] ) ,
234
+ cwd : fixture ( )
235
+ } ;
236
+
237
+ function isHelper ( file ) {
238
+ t . true ( globs . classify ( fixture ( file ) , options ) . isHelper , `${ file } should be a helper` ) ;
239
+ }
240
+
241
+ function notHelper ( file ) {
242
+ t . false ( globs . classify ( fixture ( file ) , options ) . isHelper , `${ file } should not be a helper` ) ;
243
+ }
244
+
245
+ notHelper ( 'foo.js' ) ;
246
+ isHelper ( 'foo/bar.js' ) ;
247
+ notHelper ( 'bar/foo.js' ) ;
248
+
249
+ isHelper ( '_foo.js' ) ;
250
+ isHelper ( 'foo/_foo.js' ) ;
251
+ notHelper ( 'fixtures/foo.js' ) ;
252
+ notHelper ( 'helpers/foo.js' ) ;
253
+
254
+ notHelper ( 'snapshots/foo.js.snap' ) ;
255
+
256
+ notHelper ( 'foo.json' ) ;
257
+ notHelper ( 'foo.coffee' ) ;
258
+ notHelper ( 'node_modules/foo.js' ) ;
259
+ t . end ( ) ;
260
+ } ) ;
261
+
163
262
test ( 'findHelpersAndTests finds tests (just .js)' , async t => {
164
263
const fixtureDir = fixture ( 'default-patterns' ) ;
165
264
process . chdir ( fixtureDir ) ;
@@ -276,3 +375,21 @@ test('findTests finds tests (.js, .jsx)', async t => {
276
375
actual . sort ( ) ;
277
376
t . deepEqual ( actual , expected ) ;
278
377
} ) ;
378
+
379
+ test ( 'findTests excludes helpers' , async t => {
380
+ const fixtureDir = fixture ( 'custom-extension' ) ;
381
+ process . chdir ( fixtureDir ) ;
382
+
383
+ const expected = [
384
+ 'test/do-not-compile.js' ,
385
+ 'test/foo.jsx' ,
386
+ 'test/sub/bar.jsx'
387
+ ] . sort ( ) . map ( file => path . join ( fixtureDir , file ) ) ;
388
+
389
+ const { tests : actual } = await globs . findTests ( {
390
+ cwd : fixtureDir ,
391
+ ...globs . normalizeGlobs ( [ '!**/fixtures/*' ] , [ 'test/helpers/**/*' ] , undefined , [ 'js' , 'jsx' ] )
392
+ } ) ;
393
+ actual . sort ( ) ;
394
+ t . deepEqual ( actual , expected ) ;
395
+ } ) ;
0 commit comments