Skip to content

Commit 67b6d9a

Browse files
authored
don't test graphql type object validation repeatedly (github#26197)
1 parent 31acea6 commit 67b6d9a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/content/graphql.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fs from 'fs'
2-
import path from 'path'
31
import readJsonFile from '../../lib/read-json-file.js'
42
import {
53
schemaValidator,
@@ -29,15 +27,21 @@ describe('graphql json files', () => {
2927
})
3028

3129
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()
3234
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`)
3636
// all graphql types are arrays except for queries
3737
graphqlTypes
3838
.filter((type) => type !== 'queries')
3939
.forEach((type) => {
4040
schemaJsonPerVersion[type].forEach((typeObj) => {
41+
const key = JSON.stringify(typeObj) + type
42+
if (typeObjsTested.has(key)) return
43+
typeObjsTested.add(key)
44+
4145
const { valid, errors } = revalidator.validate(typeObj, schemaValidator[type])
4246
const errorMessage = JSON.stringify(errors, null, 2)
4347
expect(valid, errorMessage).toBe(true)

0 commit comments

Comments
 (0)