1- " use strict" ;
1+ ' use strict'
22
3- const mocker = require ( " easygraphql-mock" ) ;
4- const schemaParser = require ( " easygraphql-parser" ) ;
5- const assert = require ( " assert" ) ;
6- const isObject = require ( " lodash.isobject" ) ;
7- const { graphql, print } = require ( " graphql" ) ;
8- const { makeExecutableSchema } = require ( " graphql-tools" ) ;
3+ const mocker = require ( ' easygraphql-mock' )
4+ const schemaParser = require ( ' easygraphql-parser' )
5+ const assert = require ( ' assert' )
6+ const isObject = require ( ' lodash.isobject' )
7+ const { graphql, print } = require ( ' graphql' )
8+ const { makeExecutableSchema } = require ( ' graphql-tools' )
99
10- const buildGraphQLSchema = require ( " ../utils/buildGraphQLSchema" ) ;
10+ const buildGraphQLSchema = require ( ' ../utils/buildGraphQLSchema' )
1111
12- const mock = require ( " ../utils/mock" ) ;
12+ const mock = require ( ' ../utils/mock' )
1313
1414class Tester {
1515 constructor ( schema , resolvers ) {
1616 if ( ! schema ) {
17- throw new Error ( " The schema is require" ) ;
17+ throw new Error ( ' The schema is require' )
1818 }
1919
20- let buildedSchema = schema ;
20+ let buildedSchema = schema
2121 if ( resolvers ) {
22- buildedSchema = buildGraphQLSchema ( schema ) ;
22+ buildedSchema = buildGraphQLSchema ( schema )
2323 buildedSchema = makeExecutableSchema ( {
2424 typeDefs : buildedSchema ,
25- resolvers
26- } ) ;
25+ resolvers,
26+ } )
2727 }
2828
29- this . schema = buildedSchema ;
30- this . gqlSchema = buildGraphQLSchema ( schema , true ) ;
31- this . parsedSchema = schemaParser ( schema ) ;
32- this . mockedSchema = mocker ( schema ) ;
33- this . fixture = null ;
34- this . opts = { } ;
29+ this . schema = buildedSchema
30+ this . gqlSchema = buildGraphQLSchema ( schema , true )
31+ this . parsedSchema = schemaParser ( schema )
32+ this . mockedSchema = mocker ( schema )
33+ this . fixture = null
34+ this . opts = { }
3535 }
3636
3737 mock ( opts , args = { } ) {
3838 if ( ! opts || ( isObject ( opts ) && ! opts . query && ! opts . kind ) ) {
39- throw new Error ( " The Query/Mutation to test is require" ) ;
39+ throw new Error ( ' The Query/Mutation to test is require' )
4040 }
4141
42- const operationOptions = { ...this . opts , ...opts } ;
42+ const operationOptions = { ...this . opts , ...opts }
4343
44- let { query, variables, fixture } = operationOptions ;
44+ let { query, variables, fixture } = operationOptions
4545 if ( ! fixture && this . fixture ) {
46- operationOptions . fixture = this . fixture ;
46+ operationOptions . fixture = this . fixture
4747 }
4848
49- query = query || opts ;
50- args = variables || args ;
49+ query = query || opts
50+ args = variables || args
5151
5252 return mock (
5353 this . gqlSchema ,
@@ -56,7 +56,7 @@ class Tester {
5656 this . mockedSchema ,
5757 operationOptions ,
5858 this . parsedSchema
59- ) ;
59+ )
6060 }
6161
6262 /**
@@ -66,50 +66,50 @@ class Tester {
6666 * @param args - In case it is a mutation, it will the input type.
6767 */
6868 test ( isValid , query , args ) {
69- if ( typeof isValid !== " boolean" ) {
70- throw new Error ( " isValid argument must be a boolean" ) ;
69+ if ( typeof isValid !== ' boolean' ) {
70+ throw new Error ( ' isValid argument must be a boolean' )
7171 }
7272
7373 if ( isValid ) {
74- this . mock ( query , args ) ;
75- return assert . strictEqual ( isValid , true ) ;
74+ this . mock ( query , args )
75+ return assert . strictEqual ( isValid , true )
7676 } else {
77- let error ;
77+ let error
7878 try {
79- this . mock ( query , args ) ;
79+ this . mock ( query , args )
8080 } catch ( err ) {
81- error = err ;
81+ error = err
8282 }
8383
8484 if ( ! error ) {
8585 throw new Error (
8686 `Failed, there should be an error and the passed query/mutation is valid`
87- ) ;
87+ )
8888 }
8989
90- return assert . strictEqual ( isValid , false ) ;
90+ return assert . strictEqual ( isValid , false )
9191 }
9292 }
9393
9494 graphql ( query , rootValue , contextValue , variableValues ) {
9595 if ( isObject ( query ) ) {
96- query = print ( query ) ;
96+ query = print ( query )
9797 }
9898
99- return graphql ( this . schema , query , rootValue , contextValue , variableValues ) ;
99+ return graphql ( this . schema , query , rootValue , contextValue , variableValues )
100100 }
101101
102102 setFixture ( fixture , opts = { } ) {
103103 this . opts = {
104- autoMock : opts . autoMock
105- } ;
106- this . fixture = fixture ;
104+ autoMock : opts . autoMock ,
105+ }
106+ this . fixture = fixture
107107 }
108108
109109 clearFixture ( ) {
110- this . opts = { } ;
111- this . fixture = null ;
110+ this . opts = { }
111+ this . fixture = null
112112 }
113113}
114114
115- module . exports = Tester ;
115+ module . exports = Tester
0 commit comments