Skip to content

Commit

Permalink
Typecheck tests before running them (#727)
Browse files Browse the repository at this point in the history
Something like this was intended to be part of #453. Because we have
`diagnostics: false` in jest.config.base.js, typechecking failures in
ts-jest don't actually stop the tests from running successfully; this
change makes us typecheck the tests before we run them. (If you really
want to run tests that don't typecheck you can run `npx jest` directly.)

As part of this, fix a typechecking failure caused by the upgrade in
PR #716 and run `npm dedup` to fix another typechecking failure. The `npm dedup`
itself causes a snapshot to need to be updated (as the snapshot was created by
some code that was still running a nested apollo-server 2.23).

We may want to consider finding a way to be comfortable removing
`diagnostics: false` instead as in #661, but we'll need to fix #662 before
we can do that.
  • Loading branch information
glasser committed May 3, 2021
1 parent 67c56be commit e7f2d51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 370 deletions.
19 changes: 12 additions & 7 deletions gateway-js/src/__tests__/gateway/reporting.test.ts
Expand Up @@ -10,15 +10,15 @@ import { createHttpLink } from 'apollo-link-http';
import fetch from 'node-fetch';
import { ApolloGateway } from '../..';
import { Plugin, Config, Refs } from 'pretty-format';
import { Report } from 'apollo-reporting-protobuf';
import { Report, Trace } from 'apollo-reporting-protobuf';
import { fixtures } from 'apollo-federation-integration-testsuite';

// TODO: We should fix this another way, but for now adding this
// type declaration here to avoid a typing error in `apollo-link-http-common`
// due to us not dependeing on `dom` (or `webworker`) types.
declare global {
interface WindowOrWorkerGlobalScope {
fetch: typeof import('apollo-server-env')['fetch']
fetch: typeof import('apollo-server-env')['fetch'];
}
}

Expand Down Expand Up @@ -130,9 +130,11 @@ describe('reporting', () => {
key: 'service:foo:bar',
graphVariant: 'current',
},
plugins: [ApolloServerPluginUsageReporting({
sendReportsImmediately: true,
})],
plugins: [
ApolloServerPluginUsageReporting({
sendReportsImmediately: true,
}),
],
});
({ url: gatewayUrl } = await gatewayServer.listen({ port: 0 }));
});
Expand Down Expand Up @@ -206,7 +208,7 @@ describe('reporting', () => {
const statsReportKey = '# -\n{me{name{first last}}topProducts{name}}';
expect(Object.keys(report.tracesPerQuery)).toStrictEqual([statsReportKey]);
expect(report.tracesPerQuery[statsReportKey]!.trace!.length).toBe(1);
const trace = report.tracesPerQuery[statsReportKey]!.trace![0]!;
const trace = report.tracesPerQuery[statsReportKey]!.trace![0]! as Trace;
// In the gateway, the root trace is just an empty node (unless there are errors).
expect(trace.root!.child).toStrictEqual([]);
// The query plan has (among other things) a fetch against 'accounts' and a
Expand All @@ -230,7 +232,10 @@ describe('reporting', () => {

expect(report).toMatchInlineSnapshot(`
Object {
"endTime": null,
"endTime": Object {
"nanos": 123000000,
"seconds": "1562203363",
},
"header": "<HEADER>",
"tracesPerQuery": Object {
"# -
Expand Down

0 comments on commit e7f2d51

Please sign in to comment.