@@ -4,14 +4,16 @@ import { createTenv, Service } from '@e2e/tenv';
4
4
const { fs, spawn, service, serve } = createTenv ( __dirname ) ;
5
5
6
6
let services ! : Service [ ] ;
7
- const supergraphConfig = { subgraphs : { } } ;
7
+ let supergraph ! : string ;
8
8
beforeAll ( async ( ) => {
9
9
services = [
10
10
await service ( 'accounts' ) ,
11
11
await service ( 'inventory' ) ,
12
12
await service ( 'products' ) ,
13
13
await service ( 'reviews' ) ,
14
14
] ;
15
+
16
+ const supergraphConfig = { subgraphs : { } } ;
15
17
for ( const service of services ) {
16
18
supergraphConfig . subgraphs [ service . name ] = {
17
19
routing_url : `http://0.0.0.0:${ service . port } /graphql` ,
@@ -20,11 +22,7 @@ beforeAll(async () => {
20
22
} ,
21
23
} ;
22
24
}
23
- } ) ;
24
25
25
- async function composeSupergraph (
26
- maskServicePorts ?: boolean ,
27
- ) : Promise < [ result : string , path : string ] > {
28
26
const supergraphConfigFile = await fs . tempfile ( 'supergraph.json' ) ;
29
27
await fs . write ( supergraphConfigFile , JSON . stringify ( supergraphConfig ) ) ;
30
28
@@ -33,22 +31,15 @@ async function composeSupergraph(
33
31
) ;
34
32
await waitForExit ;
35
33
36
- let result = proc . getStd ( 'out' ) ;
37
- if ( maskServicePorts ) {
38
- for ( const service of services ) {
39
- result = result . replaceAll ( service . port . toString ( ) , `<${ service . name } >` ) ;
40
- }
41
- }
42
-
43
- const supergraphFile = await fs . tempfile ( 'supergraph.graphql' ) ;
44
- await fs . write ( supergraphFile , result ) ;
45
-
46
- return [ result , supergraphFile ] ;
47
- }
34
+ supergraph = proc . getStd ( 'out' ) ;
35
+ } ) ;
48
36
49
37
it ( 'should compose supergraph with rover' , async ( ) => {
50
- const [ result ] = await composeSupergraph ( true ) ;
51
- expect ( result ) . toMatchSnapshot ( ) ;
38
+ let maskedSupergraph = supergraph ;
39
+ for ( const service of services ) {
40
+ maskedSupergraph = maskedSupergraph . replaceAll ( service . port . toString ( ) , `<${ service . name } >` ) ;
41
+ }
42
+ expect ( maskedSupergraph ) . toMatchSnapshot ( ) ;
52
43
} ) ;
53
44
54
45
it . concurrent . each ( [
@@ -116,7 +107,8 @@ it.concurrent.each([
116
107
` ,
117
108
} ,
118
109
] ) ( 'should execute $name' , async ( { query } ) => {
119
- const [ , supergraph ] = await composeSupergraph ( ) ;
120
- const { execute } = await serve ( { supergraph } ) ;
110
+ const supergraphFile = await fs . tempfile ( 'supergraph.graphql' ) ;
111
+ await fs . write ( supergraphFile , supergraph ) ;
112
+ const { execute } = await serve ( { supergraph : supergraphFile } ) ;
121
113
await expect ( execute ( { query } ) ) . resolves . toMatchSnapshot ( ) ;
122
114
} ) ;
0 commit comments