-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from apollographql/mw/testing-improvements
Testing infrastructure improvements
- Loading branch information
Showing
120 changed files
with
1,651 additions
and
4,081 deletions.
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,2 @@ | ||
export * from './snapshotSerializers'; | ||
export * from './fixtures'; |
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'; |
8 changes: 3 additions & 5 deletions
8
...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/query-planner'; | ||
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)); | ||
} |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
federation-integration-testsuite-js/src/snapshotSerializers/index.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,6 @@ | ||
export { astSerializer } from '@apollo/query-planner'; | ||
export { queryPlanSerializer } from '@apollo/query-planner'; | ||
export { default as selectionSetSerializer } from './selectionSetSerializer'; | ||
export { default as typeSerializer } from './typeSerializer'; | ||
export { default as graphqlErrorSerializer } from './graphqlErrorSerializer'; | ||
|
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
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,5 +1,8 @@ | ||
const config = require('../jest.config.base'); | ||
const baseConfig = require('../jest.config.base'); | ||
|
||
const additionalConfig = {}; | ||
|
||
module.exports = Object.assign(Object.create(null), config, additionalConfig); | ||
/** @typedef {import('ts-jest/dist/types')} */ | ||
/** @type {import('@jest/types').Config.InitialOptions} */ | ||
module.exports = { | ||
...baseConfig, | ||
setupFilesAfterEnv: ['./src/__tests__/testSetup.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 @@ | ||
import 'apollo-federation-integration-testsuite/dist/matchers'; |
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,7 +1,8 @@ | ||
{ | ||
"extends": "../../../tsconfig.test.base", | ||
"extends": "../../tsconfig.test", | ||
"include": ["**/*"], | ||
"references": [ | ||
{ "path": "../../" }, | ||
{ "path": "../.." }, | ||
{ "path": "../../../federation-integration-testsuite-js" }, | ||
] | ||
} |
Oops, something went wrong.