Skip to content

Commit

Permalink
Cleaner snapshots for graphile-build tests
Browse files Browse the repository at this point in the history
  • Loading branch information
singingwolfboy committed Oct 8, 2019
1 parent b959d7d commit a324f26
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 72 deletions.
@@ -1,32 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generates empty schema (with no Mutation type) 1`] = `
"\\"\\"\\"An object with a globally unique \`ID\`.\\"\\"\\"
"""An object with a globally unique \`ID\`."""
interface Node {
\\"\\"\\"
"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
\\"\\"\\"
"""
id: ID!
}
\\"\\"\\"The root query type which gives access points into the data universe.\\"\\"\\"
"""The root query type which gives access points into the data universe."""
type Query implements Node {
\\"\\"\\"
"""
Exposes the root query type nested one level down. This is helpful for Relay 1
which can only query top level fields if they are in a particular form.
\\"\\"\\"
"""
query: Query!
\\"\\"\\"
"""
The root query type must be a \`Node\` to work well with Relay 1 mutations. This just resolves to \`query\`.
\\"\\"\\"
"""
id: ID!
\\"\\"\\"Fetches an object given its globally unique \`ID\`.\\"\\"\\"
"""Fetches an object given its globally unique \`ID\`."""
node(
\\"\\"\\"The globally unique \`ID\`.\\"\\"\\"
"""The globally unique \`ID\`."""
id: ID!
): Node
}
"
`;
30 changes: 15 additions & 15 deletions packages/graphile-build/__tests__/__snapshots__/enum.test.js.snap
@@ -1,40 +1,40 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generated schema 1`] = `
"enum MyEnum {
ONE @deprecated(reason: \\"We no longer support numbers smaller than PI\\")
TWO @deprecated(reason: \\"We no longer support numbers smaller than PI\\")
THREE @deprecated(reason: \\"We no longer support numbers smaller than PI\\")
enum MyEnum {
ONE @deprecated(reason: "We no longer support numbers smaller than PI")
TWO @deprecated(reason: "We no longer support numbers smaller than PI")
THREE @deprecated(reason: "We no longer support numbers smaller than PI")
FOUR
}
\\"\\"\\"An object with a globally unique \`ID\`.\\"\\"\\"
"""An object with a globally unique \`ID\`."""
interface Node {
\\"\\"\\"
"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
\\"\\"\\"
"""
id: ID!
}
\\"\\"\\"The root query type which gives access points into the data universe.\\"\\"\\"
"""The root query type which gives access points into the data universe."""
type Query implements Node {
\\"\\"\\"
"""
Exposes the root query type nested one level down. This is helpful for Relay 1
which can only query top level fields if they are in a particular form.
\\"\\"\\"
"""
query: Query!
\\"\\"\\"
"""
The root query type must be a \`Node\` to work well with Relay 1 mutations. This just resolves to \`query\`.
\\"\\"\\"
"""
id: ID!
\\"\\"\\"Fetches an object given its globally unique \`ID\`.\\"\\"\\"
"""Fetches an object given its globally unique \`ID\`."""
node(
\\"\\"\\"The globally unique \`ID\`.\\"\\"\\"
"""The globally unique \`ID\`."""
id: ID!
): Node
enum: MyEnum
}
"
`;
Expand Up @@ -36,7 +36,7 @@ Object {
`;

exports[`generated schema 1`] = `
"\\"\\"\\"A location in a connection that can be used for resuming pagination.\\"\\"\\"
"""A location in a connection that can be used for resuming pagination."""
scalar Cursor
type Dummy {
Expand All @@ -62,35 +62,35 @@ type DummyEdge {
node: Dummy
}
\\"\\"\\"An object with a globally unique \`ID\`.\\"\\"\\"
"""An object with a globally unique \`ID\`."""
interface Node {
\\"\\"\\"
"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
\\"\\"\\"
"""
id: ID!
}
\\"\\"\\"The root query type which gives access points into the data universe.\\"\\"\\"
"""The root query type which gives access points into the data universe."""
type Query implements Node {
\\"\\"\\"
"""
Exposes the root query type nested one level down. This is helpful for Relay 1
which can only query top level fields if they are in a particular form.
\\"\\"\\"
"""
query: Query!
\\"\\"\\"
"""
The root query type must be a \`Node\` to work well with Relay 1 mutations. This just resolves to \`query\`.
\\"\\"\\"
"""
id: ID!
\\"\\"\\"Fetches an object given its globally unique \`ID\`.\\"\\"\\"
"""Fetches an object given its globally unique \`ID\`."""
node(
\\"\\"\\"The globally unique \`ID\`.\\"\\"\\"
"""The globally unique \`ID\`."""
id: ID!
): Node
dummyConnection(first: Int, after: Cursor, sortBy: DummyConnectionSortBy): DummyConnection
}
"
`;

exports[`no arguments 1`] = `
Expand Down
48 changes: 24 additions & 24 deletions packages/graphile-build/__tests__/__snapshots__/watch.test.js.snap
@@ -1,73 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generated schema n = 0, n = 3 1`] = `
"type Dummy0 {
type Dummy0 {
n: Int!
}
\\"\\"\\"An object with a globally unique \`ID\`.\\"\\"\\"
"""An object with a globally unique \`ID\`."""
interface Node {
\\"\\"\\"
"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
\\"\\"\\"
"""
id: ID!
}
\\"\\"\\"The root query type which gives access points into the data universe.\\"\\"\\"
"""The root query type which gives access points into the data universe."""
type Query implements Node {
\\"\\"\\"
"""
Exposes the root query type nested one level down. This is helpful for Relay 1
which can only query top level fields if they are in a particular form.
\\"\\"\\"
"""
query: Query!
\\"\\"\\"
"""
The root query type must be a \`Node\` to work well with Relay 1 mutations. This just resolves to \`query\`.
\\"\\"\\"
"""
id: ID!
\\"\\"\\"Fetches an object given its globally unique \`ID\`.\\"\\"\\"
"""Fetches an object given its globally unique \`ID\`."""
node(
\\"\\"\\"The globally unique \`ID\`.\\"\\"\\"
"""The globally unique \`ID\`."""
id: ID!
): Node
dummy: Dummy0
}
"
`;

exports[`generated schema n = 0, n = 3 2`] = `
"type Dummy3 {
type Dummy3 {
n: Int!
}
\\"\\"\\"An object with a globally unique \`ID\`.\\"\\"\\"
"""An object with a globally unique \`ID\`."""
interface Node {
\\"\\"\\"
"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
\\"\\"\\"
"""
id: ID!
}
\\"\\"\\"The root query type which gives access points into the data universe.\\"\\"\\"
"""The root query type which gives access points into the data universe."""
type Query implements Node {
\\"\\"\\"
"""
Exposes the root query type nested one level down. This is helpful for Relay 1
which can only query top level fields if they are in a particular form.
\\"\\"\\"
"""
query: Query!
\\"\\"\\"
"""
The root query type must be a \`Node\` to work well with Relay 1 mutations. This just resolves to \`query\`.
\\"\\"\\"
"""
id: ID!
\\"\\"\\"Fetches an object given its globally unique \`ID\`.\\"\\"\\"
"""Fetches an object given its globally unique \`ID\`."""
node(
\\"\\"\\"The globally unique \`ID\`.\\"\\"\\"
"""The globally unique \`ID\`."""
id: ID!
): Node
dummy: Dummy3
}
"
`;
14 changes: 12 additions & 2 deletions packages/graphile-build/__tests__/emptyMutation.test.js
@@ -1,7 +1,17 @@
const { printSchema } = require("graphql/utilities");
const { isSchema, printSchema } = require("graphql");
const { buildSchema, defaultPlugins } = require("../");

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

test("generates empty schema (with no Mutation type)", async () => {
const schema = await buildSchema([...defaultPlugins]);
expect(printSchema(schema)).toMatchSnapshot();
expect(schema).toMatchSnapshot();
});
15 changes: 12 additions & 3 deletions packages/graphile-build/__tests__/enum.test.js
@@ -1,7 +1,16 @@
const { GraphQLEnumType } = require("graphql");
const { printSchema } = require("graphql/utilities");
const { GraphQLEnumType, isSchema, printSchema } = require("graphql");
const { buildSchema, defaultPlugins } = require("../");

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

function EnumPlugin(builder) {
builder.hook("GraphQLObjectType:fields", (fields, build, context) => {
const { extend, newWithHooks } = build;
Expand Down Expand Up @@ -60,5 +69,5 @@ function EnumPlugin(builder) {

test("generated schema", async () => {
const schema = await buildSchema([...defaultPlugins, EnumPlugin]);
expect(printSchema(schema)).toMatchSnapshot();
expect(schema).toMatchSnapshot();
});
15 changes: 13 additions & 2 deletions packages/graphile-build/__tests__/fieldData.test.js
Expand Up @@ -6,10 +6,21 @@ const {
GraphQLString,
GraphQLNonNull,
GraphQLList,
isSchema,
printSchema,
} = require("graphql");
const { printSchema } = require("graphql/utilities");
const { buildSchema, defaultPlugins } = require("../");

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

const base64 = str => Buffer.from(String(str)).toString("base64");
const base64Decode = str => Buffer.from(String(str), "base64").toString("utf8");

Expand Down Expand Up @@ -291,7 +302,7 @@ const DummyConnectionPlugin = async builder => {

test("generated schema", async () => {
const schema = await buildSchema([...defaultPlugins, DummyConnectionPlugin]);
expect(printSchema(schema)).toMatchSnapshot();
expect(schema).toMatchSnapshot();
});

test("no arguments", async () => {
Expand Down
17 changes: 14 additions & 3 deletions packages/graphile-build/__tests__/watch.test.js
Expand Up @@ -3,14 +3,25 @@ const {
GraphQLObjectType,
GraphQLInt,
GraphQLNonNull,
isSchema,
printSchema,
} = require("graphql");
const { printSchema } = require("graphql/utilities");
const {
getBuilder,
defaultPlugins: allDefaultPlugins,
MutationPlugin,
} = require("../");

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

const options = {};

const EventEmitter = require("events");
Expand Down Expand Up @@ -91,12 +102,12 @@ test("generated schema n = 0, n = 3", async () => {
...defaultPlugins,
makePluginEtc(0).plugin,
])).buildSchema();
expect(printSchema(schema0)).toMatchSnapshot();
expect(schema0).toMatchSnapshot();
const schema3 = (await getBuilder([
...defaultPlugins,
makePluginEtc(3).plugin,
])).buildSchema();
expect(printSchema(schema3)).toMatchSnapshot();
expect(schema3).toMatchSnapshot();
});

test("schema is cached if no watcher fires", async () => {
Expand Down

0 comments on commit a324f26

Please sign in to comment.