diff --git a/resources/benchmark.js b/resources/benchmark.js index 5692b35e59..ed6c06b3fc 100644 --- a/resources/benchmark.js +++ b/resources/benchmark.js @@ -56,6 +56,7 @@ function prepareRevision(revision) { for file in $(cd "${LOCAL_DIR}src"; find . -path '*/__tests__/*'); do cp "${LOCAL_DIR}src/$file" "${dir}/src/$file"; done && + cp -R "${LOCAL_DIR}/src/__fixtures__" "${dir}/src/__fixtures__" && (cd "${dir}" && yarn run ${BUILD_CMD}) `); } diff --git a/src/utilities/__tests__/github-schema.graphql b/src/__fixtures__/github-schema.graphql similarity index 100% rename from src/utilities/__tests__/github-schema.graphql rename to src/__fixtures__/github-schema.graphql diff --git a/src/utilities/__tests__/github-schema.json b/src/__fixtures__/github-schema.json similarity index 100% rename from src/utilities/__tests__/github-schema.json rename to src/__fixtures__/github-schema.json diff --git a/src/__fixtures__/index.js b/src/__fixtures__/index.js new file mode 100644 index 0000000000..04c101a697 --- /dev/null +++ b/src/__fixtures__/index.js @@ -0,0 +1,11 @@ +import { join } from 'path'; +import { readFileSync } from 'fs'; + +function readLocalFile(filename) { + return readFileSync(join(__dirname, filename), 'utf8'); +} + +export const bigSchemaSDL = readLocalFile('github-schema.graphql'); +export const bigSchemaIntrospectionResult = JSON.parse( + readLocalFile('github-schema.json'), +); diff --git a/src/utilities/__tests__/buildASTSchema-benchmark.js b/src/utilities/__tests__/buildASTSchema-benchmark.js index 663fd8cc06..3aad6a8900 100644 --- a/src/utilities/__tests__/buildASTSchema-benchmark.js +++ b/src/utilities/__tests__/buildASTSchema-benchmark.js @@ -5,14 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -import { join } from 'path'; -import { readFileSync } from 'fs'; +import { bigSchemaSDL } from '../../__fixtures__'; + import { parse } from '../../'; import { buildASTSchema } from '../buildASTSchema'; -const schemaAST = parse( - readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8'), -); +const schemaAST = parse(bigSchemaSDL); export const name = 'Build Schema from AST'; export function measure() { diff --git a/src/utilities/__tests__/buildClientSchema-benchmark.js b/src/utilities/__tests__/buildClientSchema-benchmark.js index 3b857920a6..c5003c44ed 100644 --- a/src/utilities/__tests__/buildClientSchema-benchmark.js +++ b/src/utilities/__tests__/buildClientSchema-benchmark.js @@ -5,15 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -import { join } from 'path'; -import { readFileSync } from 'fs'; -import { buildClientSchema } from '../buildClientSchema'; +import { bigSchemaIntrospectionResult } from '../../__fixtures__'; -const schemaJSON = JSON.parse( - readFileSync(join(__dirname, 'github-schema.json'), 'utf8'), -); +import { buildClientSchema } from '../buildClientSchema'; export const name = 'Build Schema from Introspection'; export function measure() { - buildClientSchema(schemaJSON.data); + buildClientSchema(bigSchemaIntrospectionResult.data); } diff --git a/src/utilities/__tests__/introspectionFromSchema-benchmark.js b/src/utilities/__tests__/introspectionFromSchema-benchmark.js index d59a5f7079..f7b42c136f 100644 --- a/src/utilities/__tests__/introspectionFromSchema-benchmark.js +++ b/src/utilities/__tests__/introspectionFromSchema-benchmark.js @@ -5,17 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -import { join } from 'path'; -import { readFileSync } from 'fs'; +import { bigSchemaSDL } from '../../__fixtures__'; + import { execute, parse } from '../../'; -import { buildASTSchema } from '../buildASTSchema'; +import { buildSchema } from '../buildASTSchema'; import { getIntrospectionQuery } from '../introspectionQuery'; const queryAST = parse(getIntrospectionQuery()); -const schema = buildASTSchema( - parse(readFileSync(join(__dirname, 'github-schema.graphql'), 'utf8')), - { assumeValid: true }, -); +const schema = buildSchema(bigSchemaSDL, { assumeValid: true }); export const name = 'Execute Introspection Query'; export function measure() { diff --git a/src/validation/__tests__/validateGQL-benchmark.js b/src/validation/__tests__/validateGQL-benchmark.js new file mode 100644 index 0000000000..bfca5c31c4 --- /dev/null +++ b/src/validation/__tests__/validateGQL-benchmark.js @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { bigSchemaSDL } from '../../__fixtures__'; + +import { parse, getIntrospectionQuery, buildSchema } from '../../'; +import { validate } from '../validate'; + +const schema = buildSchema(bigSchemaSDL, { assumeValid: true }); +const queryAST = parse(getIntrospectionQuery()); + +export const name = 'Validate Introspection Query'; +export function measure() { + validate(schema, queryAST); +} diff --git a/src/validation/__tests__/validateSDL-benchmark.js b/src/validation/__tests__/validateSDL-benchmark.js new file mode 100644 index 0000000000..8c79401450 --- /dev/null +++ b/src/validation/__tests__/validateSDL-benchmark.js @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import { bigSchemaSDL } from '../../__fixtures__'; + +import { parse } from '../../'; +import { validateSDL } from '../validate'; + +const sdlAST = parse(bigSchemaSDL); + +export const name = 'Validate SDL Document'; +export function measure() { + validateSDL(sdlAST); +}