File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1
- import fs from 'fs'
2
- import path from 'path'
3
1
import readJsonFile from '../../lib/read-json-file.js'
4
2
import {
5
3
schemaValidator ,
@@ -29,15 +27,21 @@ describe('graphql json files', () => {
29
27
} )
30
28
31
29
test ( 'schemas object validation' , ( ) => {
30
+ // The typeObj is repeated thousands of times in each .json file
31
+ // so use a cache of which we've already validated to speed this
32
+ // test up significantly.
33
+ const typeObjsTested = new Set ( )
32
34
graphqlVersions . forEach ( ( version ) => {
33
- const schemaJsonPerVersion = JSON . parse (
34
- fs . readFileSync ( path . join ( process . cwd ( ) , `lib/graphql/static/schema-${ version } .json` ) )
35
- )
35
+ const schemaJsonPerVersion = readJsonFile ( `lib/graphql/static/schema-${ version } .json` )
36
36
// all graphql types are arrays except for queries
37
37
graphqlTypes
38
38
. filter ( ( type ) => type !== 'queries' )
39
39
. forEach ( ( type ) => {
40
40
schemaJsonPerVersion [ type ] . forEach ( ( typeObj ) => {
41
+ const key = JSON . stringify ( typeObj ) + type
42
+ if ( typeObjsTested . has ( key ) ) return
43
+ typeObjsTested . add ( key )
44
+
41
45
const { valid, errors } = revalidator . validate ( typeObj , schemaValidator [ type ] )
42
46
const errorMessage = JSON . stringify ( errors , null , 2 )
43
47
expect ( valid , errorMessage ) . toBe ( true )
You can’t perform that action at this time.
0 commit comments