@@ -10,23 +10,22 @@ describe('graphql - query logging in development', () => {
1010
1111 const _format = e => util . formatWithOptions ( { colors : false , depth : null } , ...( Array . isArray ( e ) ? e : [ e ] ) )
1212
13- let _log
13+ let _info = [ ]
1414
15- beforeEach ( async ( ) => {
16- await data . reset ( )
17- _log = jest . spyOn ( console , 'info' )
15+ beforeEach ( ( ) => {
16+ console . info = ( ...s ) => _info . push ( s ) // eslint-disable-line no-console
1817 } )
1918
2019 afterEach ( ( ) => {
21- jest . clearAllMocks ( )
20+ _info = [ ]
2221 } )
2322
2423 describe ( 'POST requests' , ( ) => {
2524 test ( 'Do not log requests with undefined queries' , async ( ) => {
2625 const response = await POST ( '/graphql' )
2726 expect ( response . status ) . toEqual ( 400 )
2827 expect ( response . data . errors [ 0 ] ) . toEqual ( { message : 'Missing query' } )
29- expect ( _log . mock . calls . length ) . toEqual ( 0 )
28+ expect ( _info . length ) . toEqual ( 0 )
3029 } )
3130
3231 test ( 'Log should contain HTTP method' , async ( ) => {
@@ -42,7 +41,7 @@ describe('graphql - query logging in development', () => {
4241 }
4342 `
4443 await POST ( '/graphql' , { query } )
45- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( 'POST' )
44+ expect ( _format ( _info [ 0 ] ) ) . toContain ( 'POST' )
4645 } )
4746
4847 test ( 'Log should not contain operationName if none was provided' , async ( ) => {
@@ -58,7 +57,7 @@ describe('graphql - query logging in development', () => {
5857 }
5958 `
6059 await POST ( '/graphql' , { query } )
61- expect ( _format ( _log . mock . calls [ 0 ] ) ) . not . toContain ( 'operationName' )
60+ expect ( _format ( _info [ 0 ] ) ) . not . toContain ( 'operationName' )
6261 } )
6362
6463 test ( 'Log should not contain variables if none were provided' , async ( ) => {
@@ -74,7 +73,7 @@ describe('graphql - query logging in development', () => {
7473 }
7574 `
7675 await POST ( '/graphql' , { query } )
77- expect ( _format ( _log . mock . calls [ 0 ] ) ) . not . toContain ( 'variables' )
76+ expect ( _format ( _info [ 0 ] ) ) . not . toContain ( 'variables' )
7877 } )
7978
8079 test ( 'Log should contain operationName and its value' , async ( ) => {
@@ -100,7 +99,7 @@ describe('graphql - query logging in development', () => {
10099 }
101100 `
102101 await POST ( '/graphql' , { operationName, query } )
103- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( `operationName: '${ operationName } '` )
102+ expect ( _format ( _info [ 0 ] ) ) . toContain ( `operationName: '${ operationName } '` )
104103 } )
105104
106105 test ( 'Log should contain literal values' , async ( ) => {
@@ -117,7 +116,7 @@ describe('graphql - query logging in development', () => {
117116 }
118117 `
119118 await POST ( '/graphql' , { query } )
120- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( secretTitle )
119+ expect ( _format ( _info [ 0 ] ) ) . toContain ( secretTitle )
121120 } )
122121
123122 test ( 'Log should contain variables and their values' , async ( ) => {
@@ -134,7 +133,7 @@ describe('graphql - query logging in development', () => {
134133 `
135134 const variables = { filter : { ID : { ge : 250 } } }
136135 await POST ( '/graphql' , { query, variables } )
137- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( `variables: ${ _format ( variables ) } ` )
136+ expect ( _format ( _info [ 0 ] ) ) . toContain ( `variables: ${ _format ( variables ) } ` )
138137 } )
139138 } )
140139
@@ -143,7 +142,7 @@ describe('graphql - query logging in development', () => {
143142 const response = await GET ( '/graphql' )
144143 expect ( response . status ) . toEqual ( 200 )
145144 expect ( response . data ) . toMatch ( / h t m l / i) // GraphiQL is returned
146- expect ( _log . mock . calls . length ) . toEqual ( 0 )
145+ expect ( _info . length ) . toEqual ( 0 )
147146 } )
148147
149148 test ( 'Log should contain HTTP method' , async ( ) => {
@@ -159,7 +158,7 @@ describe('graphql - query logging in development', () => {
159158 }
160159 `
161160 await GET ( `/graphql?query=${ query } ` )
162- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( 'GET' )
161+ expect ( _format ( _info [ 0 ] ) ) . toContain ( 'GET' )
163162 } )
164163
165164 test ( 'Log should not contain operationName if none was provided' , async ( ) => {
@@ -175,7 +174,7 @@ describe('graphql - query logging in development', () => {
175174 }
176175 `
177176 await GET ( `/graphql?query=${ query } ` )
178- expect ( _format ( _log . mock . calls [ 0 ] ) ) . not . toContain ( 'operationName' )
177+ expect ( _format ( _info [ 0 ] ) ) . not . toContain ( 'operationName' )
179178 } )
180179
181180 test ( 'Log should not contain variables if none were provided' , async ( ) => {
@@ -191,7 +190,7 @@ describe('graphql - query logging in development', () => {
191190 }
192191 `
193192 await GET ( `/graphql?query=${ query } ` )
194- expect ( _format ( _log . mock . calls [ 0 ] ) ) . not . toContain ( 'variables' )
193+ expect ( _format ( _info [ 0 ] ) ) . not . toContain ( 'variables' )
195194 } )
196195
197196 test ( 'Log should contain operationName and its value' , async ( ) => {
@@ -217,7 +216,7 @@ describe('graphql - query logging in development', () => {
217216 }
218217 `
219218 await GET ( `/graphql?operationName=${ operationName } &query=${ query } ` )
220- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( `operationName: '${ operationName } '` )
219+ expect ( _format ( _info [ 0 ] ) ) . toContain ( `operationName: '${ operationName } '` )
221220 } )
222221
223222 test ( 'Log should contain literal values' , async ( ) => {
@@ -234,7 +233,7 @@ describe('graphql - query logging in development', () => {
234233 }
235234 `
236235 await GET ( `/graphql?query=${ query } ` )
237- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( secretTitle )
236+ expect ( _format ( _info [ 0 ] ) ) . toContain ( secretTitle )
238237 } )
239238
240239 test ( 'Log should contain variables and their values' , async ( ) => {
@@ -251,7 +250,7 @@ describe('graphql - query logging in development', () => {
251250 `
252251 const variables = { filter : { ID : { ge : 250 } } }
253252 await GET ( `/graphql?query=${ query } &variables=${ JSON . stringify ( variables ) } ` )
254- expect ( _format ( _log . mock . calls [ 0 ] ) ) . toContain ( `variables: ${ _format ( variables ) } ` )
253+ expect ( _format ( _info [ 0 ] ) ) . toContain ( `variables: ${ _format ( variables ) } ` )
255254 } )
256255 } )
257256} )
0 commit comments