Skip to content

Commit

Permalink
Cleaner snapshots for graphile-utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
singingwolfboy committed Oct 8, 2019
1 parent 2016fe1 commit fd75dc3
Show file tree
Hide file tree
Showing 4 changed files with 882 additions and 882 deletions.
39 changes: 20 additions & 19 deletions packages/graphile-utils/__tests__/ExtendSchemaPlugin-pg.test.js
@@ -1,8 +1,18 @@
import pg from "pg";
import { graphql, printSchema } from "graphql";
import { graphql, isSchema, printSchema } from "graphql";
import { createPostGraphileSchema } from "postgraphile-core";
import { makeExtendSchemaPlugin, gql, embed } from "../";

const GraphQLSchemaSerializer = {
test(val) {
return isSchema(val);
},
serialize(schema) {
return printSchema(schema);
},
};
expect.addSnapshotSerializer(GraphQLSchemaSerializer);

const clean = data => {
if (Array.isArray(data)) {
return data.map(clean);
Expand Down Expand Up @@ -71,8 +81,7 @@ it("allows adding a custom single field to PG schema", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -134,8 +143,7 @@ it("allows adding a custom field returning a list to PG schema", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -235,8 +243,7 @@ it("allows adding a simple mutation field to PG schema", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
await pgClient.query("begin");
try {
Expand Down Expand Up @@ -313,8 +320,7 @@ it("allows adding a field to an existing table, and requesting necessary data al
})),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -373,8 +379,7 @@ it("allows adding a custom connection", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -451,8 +456,7 @@ it("allows adding a custom connection without requiring directives", async () =>
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -527,8 +531,7 @@ it("allows adding a custom connection to a nested type", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -625,8 +628,7 @@ it("allows adding a custom list to a nested type", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down Expand Up @@ -684,8 +686,7 @@ it("allows adding a single table entry to a nested type", async () => {
}),
],
});
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const pgClient = await pgPool.connect();
try {
const { data, errors } = await graphql(
Expand Down
45 changes: 22 additions & 23 deletions packages/graphile-utils/__tests__/ExtendSchemaPlugin.test.js
Expand Up @@ -13,9 +13,19 @@ import {
SubscriptionPlugin,
MutationPayloadQueryPlugin,
} from "graphile-build";
import { graphql, subscribe, parse, printSchema } from "graphql";
import { graphql, subscribe, parse, isSchema, printSchema } from "graphql";
import { $$asyncIterator } from "iterall";

const GraphQLSchemaSerializer = {
test(val) {
return isSchema(val);
},
serialize(schema) {
return printSchema(schema);
},
};
expect.addSnapshotSerializer(GraphQLSchemaSerializer);

function TestUtils_ExtractScopePlugin(
hook,
objectTypeName,
Expand Down Expand Up @@ -157,8 +167,7 @@ it("allows adding a simple type", async () => {
resolvers,
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data } = await graphql(
schema,
`
Expand All @@ -185,8 +194,7 @@ it("allows adding a non-null type", async () => {
resolvers,
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data } = await graphql(
schema,
`
Expand All @@ -213,8 +221,7 @@ it("allows adding a non-null list of non-null type", async () => {
resolvers,
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data } = await graphql(
schema,
`
Expand All @@ -241,8 +248,7 @@ it("allows adding a field with arguments", async () => {
resolvers,
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data } = await graphql(
schema,
`
Expand Down Expand Up @@ -280,8 +286,7 @@ it("allows adding a field with arguments named using a custom inflector", async
},
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data, errors } = await graphql(
schema,
`
Expand Down Expand Up @@ -336,8 +341,7 @@ it("supports @scope directive with simple values", async () => {
expect(scope.floatTest).toEqual(3.141592);
expect(scope.nullTest).toEqual(null);
expect(scope).toMatchSnapshot();
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data, errors } = await graphql(
schema,
`
Expand Down Expand Up @@ -400,8 +404,7 @@ it("supports @scope directive with variable value", async () => {
expect(scope.embedTest[secret]).toEqual("Fred");
expect(scope.embedTest.sub[1][1]).toEqual(44);
expect(scope).toMatchSnapshot();
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data, errors } = await graphql(
schema,
`
Expand Down Expand Up @@ -476,8 +479,7 @@ it("supports defining new types", async () => {
},
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data, errors } = await graphql(
schema,
`
Expand Down Expand Up @@ -536,8 +538,7 @@ it("supports defining a simple mutation", async () => {
resolvers,
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data, errors } = await graphql(
schema,
`
Expand Down Expand Up @@ -587,8 +588,7 @@ it("supports defining a more complex mutation", async () => {
},
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();
const { data, errors } = await graphql(
schema,
`
Expand Down Expand Up @@ -637,8 +637,7 @@ it("supports defining a simple subscription", async () => {
resolvers,
})),
]);
const printedSchema = printSchema(schema);
expect(printedSchema).toMatchSnapshot();
expect(schema).toMatchSnapshot();

// Let's do a standard resolve:
let before = Date.now();
Expand Down

0 comments on commit fd75dc3

Please sign in to comment.