@@ -2,9 +2,14 @@ import { PrometheusTracingPluginConfig, usePrometheus, createHistogram, createCo
22import { makeExecutableSchema } from '@graphql-tools/schema' ;
33import { assertSingleExecutionValue , createTestkit } from '@envelop/testing' ;
44import { Registry , Histogram , Counter } from 'prom-client' ;
5- import { print } from 'graphql' ;
5+ import { ASTNode , print as graphQLPrint } from 'graphql' ;
66import { useExtendContext } from '@envelop/core' ;
77
8+ // Graphql.js 16 and 15 produce different results
9+ // Graphql.js 16 output has not trailing \n
10+ // In order to produce the same output we remove any trailing white-space
11+ const print = ( ast : ASTNode ) => graphQLPrint ( ast ) . replace ( / ^ \s + | \s + $ / g, '' ) ;
12+
813describe ( 'Prom Metrics plugin' , ( ) => {
914 const schema = makeExecutableSchema ( {
1015 typeDefs : /* GraphQL */ `
@@ -167,7 +172,7 @@ describe('Prom Metrics plugin', () => {
167172 expect ( result . errors ) . toBeUndefined ( ) ;
168173 expect ( await metricCount ( 'graphql_envelop_error_result' ) ) . toBe ( 0 ) ;
169174 expect ( await metricCount ( 'test_parse' , 'count' ) ) . toBe ( 1 ) ;
170- expect ( await metricString ( 'test_parse' ) ) . toContain ( `test_parse_count{opText=\"{\\n regularField\\n}\\n\ "} 1` ) ;
175+ expect ( await metricString ( 'test_parse' ) ) . toContain ( `test_parse_count{opText=\"{\\n regularField\\n}\"} 1` ) ;
171176 } ) ;
172177 } ) ;
173178
@@ -199,7 +204,7 @@ describe('Prom Metrics plugin', () => {
199204 expect ( result . errors ) . toBeUndefined ( ) ;
200205 expect ( await metricCount ( 'graphql_envelop_error_result' ) ) . toBe ( 0 ) ;
201206 expect ( await metricCount ( 'test_validate' , 'count' ) ) . toBe ( 1 ) ;
202- expect ( await metricString ( 'test_validate' ) ) . toContain ( `test_validate_count{opText=\"{\\n regularField\\n}\\n\ "} 1` ) ;
207+ expect ( await metricString ( 'test_validate' ) ) . toContain ( `test_validate_count{opText=\"{\\n regularField\\n}\"} 1` ) ;
203208 } ) ;
204209
205210 it ( 'should register to onValidate event when needed' , ( ) => {
@@ -271,7 +276,7 @@ describe('Prom Metrics plugin', () => {
271276 expect ( result . errors ) . toBeUndefined ( ) ;
272277 expect ( await metricCount ( 'graphql_envelop_error_result' ) ) . toBe ( 0 ) ;
273278 expect ( await metricCount ( 'test_context' , 'count' ) ) . toBe ( 1 ) ;
274- expect ( await metricString ( 'test_context' ) ) . toContain ( `test_context_count{opText=\"{\\n regularField\\n}\\n\ "} 1` ) ;
279+ expect ( await metricString ( 'test_context' ) ) . toContain ( `test_context_count{opText=\"{\\n regularField\\n}\"} 1` ) ;
275280 } ) ;
276281
277282 it ( 'Should trace contextBuilding timing' , async ( ) => {
@@ -320,7 +325,7 @@ describe('Prom Metrics plugin', () => {
320325 expect ( result . errors ) . toBeUndefined ( ) ;
321326 expect ( await metricCount ( 'graphql_envelop_error_result' ) ) . toBe ( 0 ) ;
322327 expect ( await metricCount ( 'test_execute' , 'count' ) ) . toBe ( 1 ) ;
323- expect ( await metricString ( 'test_execute' ) ) . toContain ( `test_execute_count{opText=\"{\\n regularField\\n}\\n\ "} 1` ) ;
328+ expect ( await metricString ( 'test_execute' ) ) . toContain ( `test_execute_count{opText=\"{\\n regularField\\n}\"} 1` ) ;
324329 } ) ;
325330
326331 it ( 'Should trace error during execute with a single error' , async ( ) => {
@@ -398,9 +403,7 @@ describe('Prom Metrics plugin', () => {
398403
399404 expect ( result . errors ?. length ) . toBe ( 1 ) ;
400405 expect ( await metricCount ( 'test_error' ) ) . toBe ( 1 ) ;
401- expect ( await metricString ( 'test_error' ) ) . toContain (
402- `test_error{opText=\"{\\n errorField\\n}\\n\",errorMessage=\"error\"} 1`
403- ) ;
406+ expect ( await metricString ( 'test_error' ) ) . toContain ( `test_error{opText=\"{\\n errorField\\n}\",errorMessage=\"error\"} 1` ) ;
404407 } ) ;
405408
406409 it ( 'Should not trace parse errors when not needed' , async ( ) => {
0 commit comments