@@ -19,6 +19,8 @@ const testRegex = path.sep + '__testtests__' + path.sep;
19
19
const testMatch = [ '**/__testtests__/**/*' ] ;
20
20
const maxWorkers = 1 ;
21
21
22
+ const toPaths = tests => tests . map ( ( { path} ) => path ) ;
23
+
22
24
let findMatchingTests ;
23
25
let normalizeConfig ;
24
26
@@ -106,7 +108,7 @@ describe('SearchSource', () => {
106
108
testRegex : 'not-really-a-test' ,
107
109
} ) ;
108
110
return findMatchingTests ( config ) . then ( data => {
109
- const relPaths = data . paths
111
+ const relPaths = toPaths ( data . tests )
110
112
. map ( absPath => path . relative ( rootDir , absPath ) )
111
113
. sort ( ) ;
112
114
expect ( relPaths ) . toEqual (
@@ -127,7 +129,7 @@ describe('SearchSource', () => {
127
129
testRegex : '' ,
128
130
} ) ;
129
131
return findMatchingTests ( config ) . then ( data => {
130
- const relPaths = data . paths
132
+ const relPaths = toPaths ( data . tests )
131
133
. map ( absPath => path . relative ( rootDir , absPath ) )
132
134
. sort ( ) ;
133
135
expect ( relPaths ) . toEqual (
@@ -148,7 +150,7 @@ describe('SearchSource', () => {
148
150
testRegex : 'test\.jsx?' ,
149
151
} ) ;
150
152
return findMatchingTests ( config ) . then ( data => {
151
- const relPaths = data . paths . map ( absPath =>
153
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
152
154
path . relative ( rootDir , absPath ) ) ;
153
155
expect ( relPaths . sort ( ) ) . toEqual ( [
154
156
path . normalize ( '__testtests__/test.js' ) ,
@@ -166,7 +168,7 @@ describe('SearchSource', () => {
166
168
testRegex : '' ,
167
169
} ) ;
168
170
return findMatchingTests ( config ) . then ( data => {
169
- const relPaths = data . paths . map ( absPath =>
171
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
170
172
path . relative ( rootDir , absPath ) ) ;
171
173
expect ( relPaths . sort ( ) ) . toEqual ( [
172
174
path . normalize ( '__testtests__/test.js' ) ,
@@ -183,7 +185,7 @@ describe('SearchSource', () => {
183
185
testRegex,
184
186
} ) ;
185
187
return findMatchingTests ( config ) . then ( data => {
186
- const relPaths = data . paths . map ( absPath =>
188
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
187
189
path . relative ( rootDir , absPath ) ) ;
188
190
expect ( relPaths . sort ( ) ) . toEqual ( [
189
191
path . normalize ( '__testtests__/test.js' ) ,
@@ -200,7 +202,7 @@ describe('SearchSource', () => {
200
202
testRegex : '' ,
201
203
} ) ;
202
204
return findMatchingTests ( config ) . then ( data => {
203
- const relPaths = data . paths . map ( absPath =>
205
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
204
206
path . relative ( rootDir , absPath ) ) ;
205
207
expect ( relPaths . sort ( ) ) . toEqual ( [
206
208
path . normalize ( '__testtests__/test.js' ) ,
@@ -217,7 +219,7 @@ describe('SearchSource', () => {
217
219
testMatch,
218
220
} ) ;
219
221
return findMatchingTests ( config ) . then ( data => {
220
- const relPaths = data . paths . map ( absPath =>
222
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
221
223
path . relative ( rootDir , absPath ) ) ;
222
224
expect ( relPaths ) . toEqual ( [ path . normalize ( '__testtests__/test.jsx' ) ] ) ;
223
225
} ) ;
@@ -231,7 +233,7 @@ describe('SearchSource', () => {
231
233
testMatch,
232
234
} ) ;
233
235
return findMatchingTests ( config ) . then ( data => {
234
- const relPaths = data . paths . map ( absPath =>
236
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
235
237
path . relative ( rootDir , absPath ) ) ;
236
238
expect ( relPaths ) . toEqual ( [ path . normalize ( '__testtests__/test.foobar' ) ] ) ;
237
239
} ) ;
@@ -245,7 +247,7 @@ describe('SearchSource', () => {
245
247
testMatch,
246
248
} ) ;
247
249
return findMatchingTests ( config ) . then ( data => {
248
- const relPaths = data . paths . map ( absPath =>
250
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
249
251
path . relative ( rootDir , absPath ) ) ;
250
252
expect ( relPaths . sort ( ) ) . toEqual ( [
251
253
path . normalize ( '__testtests__/test.js' ) ,
@@ -262,7 +264,7 @@ describe('SearchSource', () => {
262
264
testRegex,
263
265
} ) ;
264
266
return findMatchingTests ( config ) . then ( data => {
265
- const relPaths = data . paths . map ( absPath =>
267
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
266
268
path . relative ( rootDir , absPath ) ) ;
267
269
expect ( relPaths . sort ( ) ) . toEqual ( [
268
270
path . normalize ( '__testtests__/test.js' ) ,
@@ -279,7 +281,7 @@ describe('SearchSource', () => {
279
281
testRegex : '' ,
280
282
} ) ;
281
283
return findMatchingTests ( config ) . then ( data => {
282
- const relPaths = data . paths . map ( absPath =>
284
+ const relPaths = toPaths ( data . tests ) . map ( absPath =>
283
285
path . relative ( rootDir , absPath ) ) ;
284
286
expect ( relPaths . sort ( ) ) . toEqual ( [
285
287
path . normalize ( '__testtests__/test.js' ) ,
@@ -315,15 +317,15 @@ describe('SearchSource', () => {
315
317
316
318
it ( 'makes sure a file is related to itself' , ( ) => {
317
319
const data = searchSource . findRelatedTests ( new Set ( [ rootPath ] ) ) ;
318
- expect ( data . paths ) . toEqual ( [ rootPath ] ) ;
320
+ expect ( toPaths ( data . tests ) ) . toEqual ( [ rootPath ] ) ;
319
321
} ) ;
320
322
321
323
it ( 'finds tests that depend directly on the path' , ( ) => {
322
324
const filePath = path . join ( rootDir , 'RegularModule.js' ) ;
323
325
const loggingDep = path . join ( rootDir , 'logging.js' ) ;
324
326
const parentDep = path . join ( rootDir , 'ModuleWithSideEffects.js' ) ;
325
327
const data = searchSource . findRelatedTests ( new Set ( [ filePath ] ) ) ;
326
- expect ( data . paths . sort ( ) ) . toEqual ( [
328
+ expect ( toPaths ( data . tests ) . sort ( ) ) . toEqual ( [
327
329
parentDep ,
328
330
filePath ,
329
331
loggingDep ,
@@ -349,25 +351,25 @@ describe('SearchSource', () => {
349
351
it ( 'returns empty search result for empty input' , ( ) => {
350
352
const input = [ ] ;
351
353
const data = searchSource . findRelatedTestsFromPattern ( input ) ;
352
- expect ( data . paths ) . toEqual ( [ ] ) ;
354
+ expect ( data . tests ) . toEqual ( [ ] ) ;
353
355
} ) ;
354
356
355
357
it ( 'returns empty search result for invalid input' , ( ) => {
356
358
const input = [ 'non-existend.js' ] ;
357
359
const data = searchSource . findRelatedTestsFromPattern ( input ) ;
358
- expect ( data . paths ) . toEqual ( [ ] ) ;
360
+ expect ( data . tests ) . toEqual ( [ ] ) ;
359
361
} ) ;
360
362
361
363
it ( 'returns empty search result if no related tests were found' , ( ) => {
362
364
const input = [ 'no tests.js' ] ;
363
365
const data = searchSource . findRelatedTestsFromPattern ( input ) ;
364
- expect ( data . paths ) . toEqual ( [ ] ) ;
366
+ expect ( data . tests ) . toEqual ( [ ] ) ;
365
367
} ) ;
366
368
367
369
it ( 'finds tests for a single file' , ( ) => {
368
370
const input = [ 'packages/jest-cli/src/__tests__/test_root/module.jsx' ] ;
369
371
const data = searchSource . findRelatedTestsFromPattern ( input ) ;
370
- expect ( data . paths . sort ( ) ) . toEqual ( [
372
+ expect ( toPaths ( data . tests ) . sort ( ) ) . toEqual ( [
371
373
path . join ( rootDir , '__testtests__' , 'test.js' ) ,
372
374
path . join ( rootDir , '__testtests__' , 'test.jsx' ) ,
373
375
] ) ;
@@ -379,7 +381,7 @@ describe('SearchSource', () => {
379
381
'packages/jest-cli/src/__tests__/test_root/module.foobar' ,
380
382
] ;
381
383
const data = searchSource . findRelatedTestsFromPattern ( input ) ;
382
- expect ( data . paths . sort ( ) ) . toEqual ( [
384
+ expect ( toPaths ( data . tests ) . sort ( ) ) . toEqual ( [
383
385
path . join ( rootDir , '__testtests__' , 'test.foobar' ) ,
384
386
path . join ( rootDir , '__testtests__' , 'test.js' ) ,
385
387
path . join ( rootDir , '__testtests__' , 'test.jsx' ) ,
0 commit comments