@@ -6,9 +6,30 @@ import {describe, expect, test} from '@jest/globals'
6
6
import { findQueriesInPath } from '../findQueriesInPath'
7
7
8
8
describe ( 'findQueriesInPath' , ( ) => {
9
+ test ( 'Can find queries in path' , async ( ) => {
10
+ const stream = findQueriesInPath ( {
11
+ path : path . join ( '**' , 'typescript' , '__tests__' , 'fixtures' , 'source1.ts' ) ,
12
+ } )
13
+ const res = [ ]
14
+ for await ( const result of stream ) {
15
+ res . push ( result )
16
+ }
17
+ expect ( res . length ) . toBe ( 1 )
18
+ expect ( res [ 0 ] . type ) . toBe ( 'queries' )
19
+ assert ( res [ 0 ] . type === 'queries' ) // workaround for TS
20
+ expect ( res [ 0 ] . queries . length ) . toBe ( 1 )
21
+ // filename can be either of these two
22
+ // depending on whether the test is run from the monorepo root or from the package root
23
+ expect (
24
+ res [ 0 ] . filename === 'src/typescript/__tests__/fixtures/source1.ts' ||
25
+ res [ 0 ] . filename === 'packages/@sanity/codegen/src/typescript/__tests__/fixtures/source1.ts' ,
26
+ ) . toBe ( true )
27
+ expect ( res [ 0 ] . queries [ 0 ] . name ) . toBe ( 'postQuery' )
28
+ expect ( res [ 0 ] . queries [ 0 ] . result ) . toBe ( '*[_type == "author"]' )
29
+ } )
9
30
test ( 'should throw an error if the query name already exists' , async ( ) => {
10
31
const stream = findQueriesInPath ( {
11
- path : path . join ( __dirname , 'fixtures' , '{source1,source2}.ts' ) ,
32
+ path : path . join ( '**' , 'fixtures' , '{source1,source2}.ts' ) ,
12
33
} )
13
34
await stream . next ( )
14
35
const result = await stream . next ( )
0 commit comments