Skip to content

Commit 5acd50d

Browse files
committed
Typecheck tests before running them
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 one. We may want to consider finding a way to be comfortable removing `diagnostics: false` instead.
1 parent 67c56be commit 5acd50d

File tree

3 files changed

+16
-370
lines changed

3 files changed

+16
-370
lines changed

gateway-js/src/__tests__/gateway/reporting.test.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { createHttpLink } from 'apollo-link-http';
1010
import fetch from 'node-fetch';
1111
import { ApolloGateway } from '../..';
1212
import { Plugin, Config, Refs } from 'pretty-format';
13-
import { Report } from 'apollo-reporting-protobuf';
13+
import { Report, Trace } from 'apollo-reporting-protobuf';
1414
import { fixtures } from 'apollo-federation-integration-testsuite';
1515

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

@@ -130,9 +130,11 @@ describe('reporting', () => {
130130
key: 'service:foo:bar',
131131
graphVariant: 'current',
132132
},
133-
plugins: [ApolloServerPluginUsageReporting({
134-
sendReportsImmediately: true,
135-
})],
133+
plugins: [
134+
ApolloServerPluginUsageReporting({
135+
sendReportsImmediately: true,
136+
}),
137+
],
136138
});
137139
({ url: gatewayUrl } = await gatewayServer.listen({ port: 0 }));
138140
});
@@ -206,7 +208,7 @@ describe('reporting', () => {
206208
const statsReportKey = '# -\n{me{name{first last}}topProducts{name}}';
207209
expect(Object.keys(report.tracesPerQuery)).toStrictEqual([statsReportKey]);
208210
expect(report.tracesPerQuery[statsReportKey]!.trace!.length).toBe(1);
209-
const trace = report.tracesPerQuery[statsReportKey]!.trace![0]!;
211+
const trace = report.tracesPerQuery[statsReportKey]!.trace![0]! as Trace;
210212
// In the gateway, the root trace is just an empty node (unless there are errors).
211213
expect(trace.root!.child).toStrictEqual([]);
212214
// The query plan has (among other things) a fetch against 'accounts' and a
@@ -230,7 +232,10 @@ describe('reporting', () => {
230232

231233
expect(report).toMatchInlineSnapshot(`
232234
Object {
233-
"endTime": null,
235+
"endTime": Object {
236+
"nanos": 123000000,
237+
"seconds": "1562203363",
238+
},
234239
"header": "<HEADER>",
235240
"tracesPerQuery": Object {
236241
"# -

0 commit comments

Comments
 (0)