diff --git a/config/helpers/check_frontend_integration_env.js b/config/helpers/check_frontend_integration_env.js new file mode 100644 index 0000000000000000000000000000000000000000..38393c89445fb0da6c005d9fc00c9a6b1050c0c5 --- /dev/null +++ b/config/helpers/check_frontend_integration_env.js @@ -0,0 +1,37 @@ +const fs = require('fs'); +const isESLint = require('./is_eslint'); + +const GRAPHQL_SCHEMA_PATH = 'tmp/tests/graphql/gitlab_schema.graphql'; +const GRAPHQL_SCHEMA_JOB = 'bundle exec rake gitlab:graphql:schema:dump'; + +const shouldIgnoreWarnings = JSON.parse(process.env.GL_IGNORE_WARNINGS || '0'); + +const failCheck = (message) => { + console.error(message); + + if (!shouldIgnoreWarnings) { + process.exit(1); + } +}; + +const checkGraphqlSchema = () => { + if (!fs.existsSync(GRAPHQL_SCHEMA_PATH)) { + const message = ` +ERROR: Expected to find "${GRAPHQL_SCHEMA_PATH}" but file does not exist. Try running: + + ${GRAPHQL_SCHEMA_JOB} +`; + + failCheck(message); + } +}; + +const check = () => { + if (isESLint(module)) { + return; + } + + checkGraphqlSchema(); +}; + +module.exports = check; diff --git a/jest.config.integration.js b/jest.config.integration.js index d85e14fe218d7bc06303a45c002ef83361c23bd5..92296fb751e19676ff3c1c7e785e01c6f51b6e77 100644 --- a/jest.config.integration.js +++ b/jest.config.integration.js @@ -1,5 +1,8 @@ +const checkEnvironment = require('./config/helpers/check_frontend_integration_env'); const baseConfig = require('./jest.config.base'); +checkEnvironment(); + module.exports = { ...baseConfig('spec/frontend_integration', { moduleNameMapper: { diff --git a/spec/frontend_integration/test_helpers/mock_server/graphql.js b/spec/frontend_integration/test_helpers/mock_server/graphql.js index e265885259974d53b5f65e9852d60a95700261af..27396842523e529be5842d98725b8786c153acc1 100644 --- a/spec/frontend_integration/test_helpers/mock_server/graphql.js +++ b/spec/frontend_integration/test_helpers/mock_server/graphql.js @@ -1,13 +1,11 @@ import { buildSchema, graphql } from 'graphql'; +import { memoize } from 'lodash'; -/* eslint-disable import/no-unresolved */ -// This rule is disabled for the following line. // The graphql schema is dynamically generated in CI // during the `graphql-schema-dump` job. -import gitlabSchemaStr from '../../../../tmp/tests/graphql/gitlab_schema.graphql'; -/* eslint-enable import/no-unresolved */ +// eslint-disable-next-line global-require, import/no-unresolved +const getGraphqlSchema = () => require('../../../../tmp/tests/graphql/gitlab_schema.graphql'); -const graphqlSchema = buildSchema(gitlabSchemaStr.loc.source.body); const graphqlResolvers = { project({ fullPath }, schema) { const result = schema.projects.findBy({ path_with_namespace: fullPath }); @@ -21,6 +19,7 @@ const graphqlResolvers = { }; }, }; +const buildGraphqlSchema = memoize(() => buildSchema(getGraphqlSchema().loc.source.body)); export const graphqlQuery = (query, variables, schema) => - graphql(graphqlSchema, query, graphqlResolvers, schema, variables); + graphql(buildGraphqlSchema(), query, graphqlResolvers, schema, variables);