diff --git a/packages/apollo-engine-reporting/src/__tests__/plugin.test.ts b/packages/apollo-engine-reporting/src/__tests__/plugin.test.ts index c13cc31e814..b6f2b8c5294 100644 --- a/packages/apollo-engine-reporting/src/__tests__/plugin.test.ts +++ b/packages/apollo-engine-reporting/src/__tests__/plugin.test.ts @@ -58,10 +58,7 @@ it('trace construction', async () => { const schema = makeExecutableSchema({ typeDefs }); addMockFunctionsToSchema({ schema }); - const traces: Array = []; - async function addTrace(args: AddTraceArgs) { - traces.push(args); - } + const addTrace = jest.fn(); const pluginInstance = plugin({ /* no options!*/ }, addTrace); @@ -322,96 +319,91 @@ function makeTestHTTP(): Trace.HTTP { } describe("tests for the shouldReportQuery reporting option", () => { - it("report no traces", async () => { - const schema = makeExecutableSchema({ typeDefs }); - addMockFunctionsToSchema({ schema }); - - async function addTrace(_args: AddTraceArgs) { - throw new Error("Should not add any traces"); - } - - const pluginInstance = plugin({report: false}, addTrace); - - pluginTestHarness({ - pluginInstance, - schema, - graphqlRequest: { - query, - operationName: 'q', - extensions: { - clientName: 'testing suite', - }, - http: new Request('http://localhost:123/foo'), + it("report no traces", async () => { + const schema = makeExecutableSchema({ typeDefs }); + addMockFunctionsToSchema({ schema }); + + const addTrace = jest.fn(); + + const pluginInstance = plugin({ report: false }, addTrace); + + pluginTestHarness({ + pluginInstance, + schema, + graphqlRequest: { + query, + operationName: 'q', + extensions: { + clientName: 'testing suite', }, - executor: async ({ request: { query: source }}) => { - return await graphql({ - schema, - source, - }); - }, - }); + http: new Request('http://localhost:123/foo'), + }, + executor: async ({ request: { query: source } }) => { + return await graphql({ + schema, + source, + }); + }, }); + }); - it("report traces based on operation name", async () => { - const schema = makeExecutableSchema({ typeDefs }); - addMockFunctionsToSchema({ schema }); - - let tracesAdded = 0; - - async function addTrace(_args: AddTraceArgs) { - tracesAdded += 1; - } + it('report traces based on operation name', async () => { + const schema = makeExecutableSchema({ typeDefs }); + addMockFunctionsToSchema({ schema }); - const pluginInstance = plugin( - { - report: async (request) => { - return request.operationName === 'report' - } - }, addTrace); + const addTrace = jest.fn(); - pluginTestHarness({ - pluginInstance, - schema, - graphqlRequest: { - query: queryReport, - operationName: 'report', - extensions: { - clientName: 'testing suite', - }, - http: new Request('http://localhost:123/foo'), - }, - executor: async ({ request: { query: source }}) => { - return await graphql({ - schema, - source, - }); + const pluginInstance = plugin( + { + report: async (request) => { + return request.operationName === 'report' + } + }, addTrace); + + pluginTestHarness({ + pluginInstance, + schema, + graphqlRequest: { + query: queryReport, + operationName: 'report', + extensions: { + clientName: 'testing suite', }, - }); - expect(tracesAdded).toEqual(1); + http: new Request('http://localhost:123/foo'), + }, + executor: async ({ request: { query: source } }) => { + return await graphql({ + schema, + source, + }); + }, + }); - pluginTestHarness({ - pluginInstance, - schema, - graphqlRequest: { - query, - operationName: 'q', - extensions: { - clientName: 'testing suite', - }, - http: new Request('http://localhost:123/foo'), - }, - executor: async ({ request: { query: source }}) => { - return await graphql({ - schema, - source, - }); + expect(addTrace).toBeCalledTimes(1); + addTrace.mockReset() + + pluginTestHarness({ + pluginInstance, + schema, + graphqlRequest: { + query, + operationName: 'q', + extensions: { + clientName: 'testing suite', }, - }); - - expect(tracesAdded).toEqual(1); - + http: new Request('http://localhost:123/foo'), + }, + executor: async ({ request: { query: source } }) => { + return await graphql({ + schema, + source, + }); + }, }); + + expect(addTrace).not.toBeCalled(); }); +}); /** diff --git a/packages/apollo-engine-reporting/src/agent.ts b/packages/apollo-engine-reporting/src/agent.ts index a5adbca8122..f5edf085763 100644 --- a/packages/apollo-engine-reporting/src/agent.ts +++ b/packages/apollo-engine-reporting/src/agent.ts @@ -399,7 +399,7 @@ export class EngineReportingAgent { this.reportSizes[schemaHash] += encodedTrace.length + Buffer.byteLength(statsReportKey); - // If the buffer gets big (according to our estimate), send. + // If the buffer gets big (accordin to our estimate), send. if ( this.sendReportsImmediately || this.reportSizes[schemaHash] >=