Skip to content

Commit

Permalink
Resolve testing setup issues / buildPlan.test.ts whitespacing (#2959)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-scheer authored Mar 15, 2024
1 parent 8c8c600 commit ea61342
Show file tree
Hide file tree
Showing 31 changed files with 132 additions and 311 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"editor.formatOnSave": false,
"editor.rulers": [80],
"editor.wordWrapColumn": 80,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
},
"typescript.tsdk": "./node_modules/typescript/lib",
Expand Down
1 change: 1 addition & 0 deletions composition-js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const baseConfig = require('../jest.config.base');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
setupFilesAfterEnv: ['./src/__tests__/testSetup.ts'],
displayName: {
name: '@apollo/composition',
color: 'gray'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
import { DirectiveLocation } from "graphql";
import gql from "graphql-tag";
import { assertCompositionSuccess, composeAsFed2Subgraphs } from "./testHelper";
import './matchers';
import {
registerKnownFeature,
unregisterKnownFeatures,
Expand Down
1 change: 0 additions & 1 deletion composition-js/src/__tests__/compose.external.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import gql from 'graphql-tag';
import './matchers';
import {
assertCompositionSuccess,
errors,
Expand Down
1 change: 0 additions & 1 deletion composition-js/src/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@apollo/federation-internals';
import { CompositionOptions, CompositionResult, composeServices } from '../compose';
import gql from 'graphql-tag';
import './matchers';
import { print } from 'graphql';
import {
assertCompositionSuccess,
Expand Down
1 change: 0 additions & 1 deletion composition-js/src/__tests__/composeFed1Subgraphs.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS, ObjectType, printSchema, Schema, SubgraphASTNode, Subgraphs, Supergraph } from '@apollo/federation-internals';
import { CompositionResult, composeServices, CompositionSuccess } from '../compose';
import gql from 'graphql-tag';
import './matchers';

function assertCompositionSuccess(r: CompositionResult): asserts r is CompositionSuccess {
if (r.errors) {
Expand Down
2 changes: 1 addition & 1 deletion composition-js/src/__tests__/hints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../hints';
import { MergeResult, mergeSubgraphs } from '../merging';
import { assertCompositionSuccess, composeAsFed2Subgraphs } from './testHelper';
import { formatExpectedToMatchReceived } from './matchers/toMatchString';
import { formatExpectedToMatchReceived } from 'apollo-federation-integration-testsuite/src/matchers/toMatchString';
import { composeServices } from '../compose';

function mergeDocuments(...documents: DocumentNode[]): MergeResult {
Expand Down
2 changes: 0 additions & 2 deletions composition-js/src/__tests__/matchers/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion composition-js/src/__tests__/override.compose.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { printSchema, printType } from "@apollo/federation-internals";
import gql from "graphql-tag";
import "./matchers";
import {
assertCompositionSuccess,
schemas,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assertCompositionSuccess, composeAsFed2Subgraphs } from "./testHelper";
import gql from 'graphql-tag';
import { asFed2SubgraphDocument, buildSubgraph, ServiceDefinition, Supergraph } from "@apollo/federation-internals";
import './matchers';

function composeAndTestReversibility(subgraphs: ServiceDefinition[]) {
const result = composeAsFed2Subgraphs(subgraphs);
Expand Down
1 change: 1 addition & 0 deletions composition-js/src/__tests__/testSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'apollo-federation-integration-testsuite/dist/matchers';
1 change: 0 additions & 1 deletion composition-js/src/__tests__/validation_errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CompositionResult } from '../compose';
import gql from 'graphql-tag';
import './matchers';
import { composeAsFed2Subgraphs } from './testHelper';

function errorMessages(r: CompositionResult): string[] {
Expand Down
2 changes: 2 additions & 0 deletions federation-integration-testsuite-js/src/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ import './toCallService';
import './toHaveBeenCalledBefore';
import './toMatchAST';
import './toMatchQueryPlan';
import './toMatchString';
import './toMatchSubgraph';
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Make this file a module (See: https://github.com/microsoft/TypeScript/issues/17736)
export {};
export { };

// TODO: this is the same than in definition.test.ts. Could we move those to a common place (but is it worth having
// a new module for that)? Maybe there is a better, more jest-native, way to do this.
// Note(Sylvain): I initially added those because I didn't figure out a way to make `toMatchSnapshotInline` work
// with strings cleanly: I always either ended up with indentation issuels, or the result looks very ugly in the
// tests. But it could be I just don't understand well enough how it work.
Expand Down Expand Up @@ -44,24 +42,24 @@ expect.extend({
const pass = this.equals(received, expected);
const message = pass
? () => this.utils.matcherHint('toMatchString', undefined, undefined)
+ '\n\n'
+ `Expected: not ${this.printExpected(received)}`
+ '\n\n'
+ `Expected: not ${this.printExpected(received)}`
: () => {
return (
this.utils.matcherHint('toMatchString', undefined, undefined,)
+ '\n\n'
+ this.utils.printDiffOrStringify(expected, received, 'Expected', 'Received', true));
};
return {received, expected, message, name: 'toMatchString', pass};
return { received, expected, message, name: 'toMatchString', pass };
},

toMatchStringArray(received: string[], expected: string[]) {
if (received.length !== expected.length) {
const message = () =>
const message = () =>
this.utils.matcherHint('toMatchStringArray', undefined, undefined,)
+ `\n\nExpected an array of size ${expected.length} but got one of size ${received.length}\n\n`
+ this.utils.printDiffOrStringify(expected, received, 'Expected', 'Received', true);
return {received, expected, message, name: 'toMatchStringArray', pass: false};
+ `\n\nExpected an array of size ${expected.length} but got one of size ${received.length}\n\n`
+ this.utils.printDiffOrStringify(expected, received, 'Expected', 'Received', true);
return { received, expected, message, name: 'toMatchStringArray', pass: false };
}

let pass = true;
Expand All @@ -77,12 +75,11 @@ expect.extend({
);
}
}
const message = () =>
this.utils.matcherHint('toMatchString', undefined, undefined)
+ '\n\n'
+ (pass ? `Expected: not ${this.printExpected(expected)}` : messages.join('\n\n'));
const message = () =>
this.utils.matcherHint('toMatchString', undefined, undefined)
+ '\n\n'
+ (pass ? `Expected: not ${this.printExpected(expected)}` : messages.join('\n\n'));

return {received, expected, message, name: 'toMatchStringArray', pass};
return { received, expected, message, name: 'toMatchStringArray', pass };
}
});

1 change: 1 addition & 0 deletions internals-js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const baseConfig = require('../jest.config.base');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
setupFilesAfterEnv: ['./src/__tests__/testSetup.ts'],
displayName: {
name: '@apollo/federation-internals',
color: 'magenta'
Expand Down
9 changes: 4 additions & 5 deletions internals-js/src/__tests__/definitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
SchemaElement,
UnionType,
InputObjectType,
} from '../../dist/definitions';
} from '../definitions';
import {
printSchema as printGraphQLjsSchema,
} from 'graphql';
import { defaultPrintOptions, printSchema } from '../../dist/print';
import { buildSchema } from '../../dist/buildSchema';
import { buildSubgraph, federationMetadata, newEmptyFederation2Schema } from '../../dist/federation';
import './matchers';
import { defaultPrintOptions, printSchema } from '../print';
import { buildSchema } from '../buildSchema';
import { buildSubgraph, federationMetadata, newEmptyFederation2Schema } from '../federation';

function parseSchema(schema: string): Schema {
try {
Expand Down
1 change: 0 additions & 1 deletion internals-js/src/__tests__/graphQLJSSchemaToAST.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
print
} from "graphql";
import { graphQLJSSchemaToAST } from "../graphQLJSSchemaToAST";
import './matchers';

function validateRoundtrip(schemaStr: string, expectedWithoutASTNodes: string | undefined = schemaStr) {
const schema = buildSchema(schemaStr);
Expand Down
1 change: 0 additions & 1 deletion internals-js/src/__tests__/matchers/index.ts

This file was deleted.

87 changes: 0 additions & 87 deletions internals-js/src/__tests__/matchers/toMatchString.ts

This file was deleted.

9 changes: 4 additions & 5 deletions internals-js/src/__tests__/operations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import {
isCompositeType,
Schema,
SchemaRootKind,
} from '../../dist/definitions';
import { buildSchema } from '../../dist/buildSchema';
import { FederationBlueprint } from '../../dist/federation';
import { FragmentRestrictionAtType, MutableSelectionSet, NamedFragmentDefinition, Operation, operationFromDocument, parseOperation } from '../../dist/operations';
import './matchers';
} from '../definitions';
import { buildSchema } from '../buildSchema';
import { FederationBlueprint } from '../federation';
import { FragmentRestrictionAtType, MutableSelectionSet, NamedFragmentDefinition, Operation, operationFromDocument, parseOperation } from '../operations';
import { DocumentNode, FieldNode, GraphQLError, Kind, OperationDefinitionNode, OperationTypeNode, parse, SelectionNode, SelectionSetNode, validate } from 'graphql';
import { assert } from '../utils';
import gql from 'graphql-tag';
Expand Down
1 change: 0 additions & 1 deletion internals-js/src/__tests__/schemaUpgrader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS_UPGRADED, printSchema } fro
import { ObjectType } from '../definitions';
import { buildSubgraph, Subgraphs } from '../federation';
import { UpgradeChangeID, UpgradeResult, upgradeSubgraphsIfNecessary } from '../schemaUpgrader';
import './matchers';

function changeMessages(res: UpgradeResult, subgraphName: string, id: UpgradeChangeID): string[] {
const changes = res.changes?.get(subgraphName)?.get(id);
Expand Down
1 change: 1 addition & 0 deletions internals-js/src/__tests__/testSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'apollo-federation-integration-testsuite/dist/matchers';
1 change: 0 additions & 1 deletion internals-js/src/__tests__/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DocumentNode } from "graphql";
import { asFed2SubgraphDocument, buildSubgraph, errorCauses } from "..";
import './matchers';

// Builds the provided subgraph (using name 'S' for the subgraph) and, if the
// subgraph is invalid/has errors, return those errors as a list of [code, message].
Expand Down
1 change: 1 addition & 0 deletions query-graphs-js/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const baseConfig = require('../jest.config.base');
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
setupFilesAfterEnv: ['./src/__tests__/testSetup.ts'],
displayName: {
name: "@apollo/query-graphs",
color: "yellow",
Expand Down
1 change: 1 addition & 0 deletions query-graphs-js/src/__tests__/testSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'apollo-federation-integration-testsuite/dist/matchers';
Loading

0 comments on commit ea61342

Please sign in to comment.