New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing infrastructure improvements #453
Merged
Merged
Changes from 20 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
08e1b3a
Update Jest and related packages to latest versions
martijnwalraven 1f470ad
Rename `ts-jest` `tsConfig` option to `tsconfig`
martijnwalraven 2e32c05
Remove use of `moduleNameMapper` for local imports
martijnwalraven 806b959
Update TypeScript to 4.1.3
martijnwalraven 7e86ef7
Clean up test projects and reference all tests from root tsconfig.tes…
martijnwalraven cf7368e
Add a TypeScript watch task to VS Code
martijnwalraven 879ddd0
Re-enable `strictNullChecks` for composition tests and fix using null…
martijnwalraven 22395b6
Rely on `queryPlanSerializer` instead of pretty printing the query pl…
martijnwalraven 68ef9d6
Move snapshot serializers and matchers to federaton-integration-tests…
martijnwalraven 2cb7276
Fix Jest snapshot indentation for `graphql-js` AST
martijnwalraven 417c79e
Add expected newlines in gateway snapshots
martijnwalraven 6d338b9
Update `ts-jest` to latest version
martijnwalraven 6304f18
Update `graphql-js` to v15
martijnwalraven 8d663f1
Fix references for per `__tests__` directory `tsconfig.json`
martijnwalraven 894cfed
Remove unnecessary declaration of `addSnapshotSerializer`
martijnwalraven 12ad3bf
Fix typings for `toHaveFetched` matchers
martijnwalraven d5c4e71
Clean up `toMatchAST` and add `toMatchQueryPlan`
martijnwalraven 912716d
Simplify Jest configs and ensure `testSetup.js` is included in every …
martijnwalraven 5192e3f
Use `tsconfig.test.json` from `ts-jest` instead of root `__tests__` one
martijnwalraven 9d75cb8
Avoid path mapping for mocks and fix typing issues
martijnwalraven 2b3af8a
Add `@apollo/query-planner` package
martijnwalraven d9bdbc6
Move `prettyFormatQueryPlan` and related serializers to `@apollo/quer…
martijnwalraven 50a37ac
Update package-lock.json for @apollo/query-planner
martijnwalraven 6ad7fe5
Import matchers from subdirectory instead of root
martijnwalraven e007c3c
Add more test typing fixes using null coalescing
martijnwalraven b7ac4d2
Remove unnecessary header iteration from toHaveFetched
martijnwalraven a359e23
Fix `toHaveFetched` typing to support JSON body
martijnwalraven 7859038
Update __tests__ tsconfig.json to include mocks
martijnwalraven ff0bfa6
Remove some unused imports from tests
martijnwalraven 2feb7a5
Import `QueryPlan` from `@apollo/query-planner` in test
martijnwalraven 0cb2a3d
Add `@types` packages for `deep-freeze` and `bunyan`
martijnwalraven 9ed379d
Remove more unused imports from tests
martijnwalraven 05dda1a
Temporarily ignore typing errors in tests for incomplete request cont…
martijnwalraven b8ba02e
Temporarily ignore typing errors in tests for buildService
martijnwalraven 07d848f
Fix type of Promise in test
martijnwalraven 2b774f9
Avoid stringifying variables in test because that breaks typing
martijnwalraven c0cb248
Add resolver map type to test
martijnwalraven b76f8c4
Cast to any to allow arbitrary property mutation in test
martijnwalraven 0bd250f
Fix `make-fetch-happen` types to allow `defaults()` chaining
martijnwalraven 646230d
Change unused parameter to _ to avoid type error
martijnwalraven 21dc682
Set `skipLibCheck` to true in `tsconfig` to avoid type errors from de…
martijnwalraven 9d21dd5
Fix typing for Logger mock
martijnwalraven 1b34ce5
Add non-null assertion for known schema types in test
martijnwalraven 68b27f3
Merge branch 'main' into mw/testing-improvements
martijnwalraven 042edda
Add non-null assertion to fix assignment from closure
martijnwalraven 729faad
Update `apollo-server-core` dependency in `@apollo/gateway`
martijnwalraven 58a88ef
Remove `skipLibCheck` and add workaround for typing issue in dependency
martijnwalraven File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "TypeScript watch", | ||
"type": "typescript", | ||
"tsconfig": "tsconfig.json", | ||
"option": "watch", | ||
"problemMatcher": ["$tsc-watch"], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"presentation": { | ||
"reveal": "never", | ||
"revealProblems": "onProblem", | ||
"panel": "shared", | ||
"clear": true | ||
}, | ||
"runOptions": { | ||
"runOn": "folderOpen" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from './matchers'; | ||
export * from './snapshotSerializers'; | ||
export * from './fixtures'; | ||
|
||
export { prettyFormatQueryPlan } from './prettyFormatQueryPlan'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import './toCallService'; | ||
import './toHaveBeenCalledBefore'; | ||
import './toHaveFetched'; | ||
import './toMatchAST'; |
9 changes: 4 additions & 5 deletions
9
...s/src/__tests__/matchers/toCallService.ts → ...estsuite-js/src/matchers/toCallService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
federation-integration-testsuite-js/src/matchers/toMatchAST.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ASTNode } from 'graphql'; | ||
import { MatcherHintOptions } from 'jest-matcher-utils'; | ||
import { diffFormatted, indentLines, printExpectedFormatted } from './utils'; | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toMatchAST(expected: ASTNode): R; | ||
} | ||
} | ||
} | ||
|
||
expect.extend({ | ||
toMatchAST(received: ASTNode, expected: ASTNode) { | ||
const matcherName = 'toMatchAST'; | ||
const options: MatcherHintOptions = { | ||
isNot: this.isNot, | ||
promise: this.promise, | ||
}; | ||
|
||
const pass = this.equals(received, expected); | ||
|
||
const message = pass | ||
? () => | ||
this.utils.matcherHint(matcherName, undefined, undefined, options) + | ||
'\n\n' + | ||
`Expected AST to not equal:\n` + | ||
indentLines(printExpectedFormatted(expected)) | ||
: () => | ||
this.utils.matcherHint(matcherName, undefined, undefined, options) + | ||
'\n\n' + | ||
diffFormatted(expected, received, { | ||
aAnnotation: 'Expected', | ||
bAnnotation: 'Received', | ||
expand: this.expand ?? true, | ||
includeChangeCounts: true, | ||
}); | ||
return { | ||
message, | ||
pass, | ||
}; | ||
}, | ||
}); |
43 changes: 43 additions & 0 deletions
43
federation-integration-testsuite-js/src/matchers/toMatchQueryPlan.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { QueryPlan } from '@apollo/gateway'; | ||
import { MatcherHintOptions } from 'jest-matcher-utils'; | ||
import { diffFormatted, indentLines, printExpectedFormatted } from './utils'; | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toMatchQueryPlan(expected: QueryPlan): R; | ||
} | ||
} | ||
} | ||
|
||
expect.extend({ | ||
toMatchQueryPlan(received: QueryPlan, expected: QueryPlan) { | ||
const matcherName = 'toMatchQueryPlan'; | ||
const options: MatcherHintOptions = { | ||
isNot: this.isNot, | ||
promise: this.promise, | ||
}; | ||
|
||
const pass = this.equals(received, expected); | ||
|
||
const message = pass | ||
? () => | ||
this.utils.matcherHint(matcherName, undefined, undefined, options) + | ||
'\n\n' + | ||
`Expected query plan to not equal:\n` + | ||
indentLines(printExpectedFormatted(expected)) | ||
: () => | ||
this.utils.matcherHint(matcherName, undefined, undefined, options) + | ||
'\n\n' + | ||
diffFormatted(expected, received, { | ||
aAnnotation: 'Expected', | ||
bAnnotation: 'Received', | ||
expand: this.expand ?? true, | ||
includeChangeCounts: true, | ||
}); | ||
return { | ||
message, | ||
pass, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import diff, { DiffOptions } from 'jest-diff'; | ||
import { EXPECTED_COLOR, RECEIVED_COLOR } from 'jest-matcher-utils'; | ||
import prettyFormat from 'pretty-format'; | ||
import { | ||
queryPlanSerializer, | ||
astSerializer, | ||
typeSerializer, | ||
} from '../snapshotSerializers'; | ||
|
||
const defaultFormatOptions: prettyFormat.OptionsReceived = { | ||
plugins: [queryPlanSerializer, astSerializer, typeSerializer], | ||
}; | ||
|
||
export function diffFormatted( | ||
expected: unknown, | ||
received: unknown, | ||
diffOptions?: DiffOptions, | ||
formatOptions: prettyFormat.OptionsReceived = defaultFormatOptions, | ||
) { | ||
const expectedString = prettyFormat(expected, formatOptions); | ||
const receivedString = prettyFormat(received, formatOptions); | ||
|
||
return diff(expectedString, receivedString, diffOptions); | ||
} | ||
|
||
export function indentLines( | ||
text: string, | ||
depth: number = 1, | ||
indent: string = ' ', | ||
) { | ||
const indentation = indent.repeat(depth); | ||
return text | ||
.split('\n') | ||
.map((line) => indentation + line) | ||
.join('\n'); | ||
} | ||
|
||
// The corresponding functions in `jest-matcher-utils` call their own `stringify` function, | ||
// and that doesn't allow passing in custom pretty-format plugins. | ||
|
||
export function printReceivedFormatted( | ||
value: unknown, | ||
formatOptions: prettyFormat.OptionsReceived = defaultFormatOptions, | ||
): string { | ||
return RECEIVED_COLOR(prettyFormat(value, formatOptions)); | ||
} | ||
|
||
export function printExpectedFormatted( | ||
value: unknown, | ||
formatOptions: prettyFormat.OptionsReceived = defaultFormatOptions, | ||
): string { | ||
return EXPECTED_COLOR(prettyFormat(value, formatOptions)); | ||
} |
9 changes: 9 additions & 0 deletions
9
federation-integration-testsuite-js/src/prettyFormatQueryPlan.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { QueryPlan } from '@apollo/gateway'; | ||
import prettyFormat from 'pretty-format'; | ||
import { astSerializer, queryPlanSerializer } from './snapshotSerializers'; | ||
|
||
export function prettyFormatQueryPlan(queryPlan: QueryPlan) { | ||
return prettyFormat(queryPlan, { | ||
plugins: [queryPlanSerializer, astSerializer], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so I'm understanding, this is necessary — rather than just
headers.entries()
to account for the fact thatheaders
might be a{ [name: string]: string }
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code hasn't changed in this PR, but I'm wondering why we can't directly initialize headers as
new Headers(requestOpts.headers)
. What is iterating over the passed in headers and adding them one by one adding?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the types of
toHaveFetched
are currently broken because the normalBodyInit
doesn't support arbitrary objects, but here it is always assumed an object is passed in and should be serialized as JSON.