diff --git a/client/cypress.e2e.ts b/client/cypress.e2e.ts index 0025205b..8bb23982 100644 --- a/client/cypress.e2e.ts +++ b/client/cypress.e2e.ts @@ -1,9 +1,21 @@ import {defineConfig} from 'cypress'; +import {readFileSync} from "fs"; +import {resolve} from "path"; export default defineConfig( { e2e: { "baseUrl": "http://localhost:8000", specPattern: 'cypress/e2e/e2e/**/*.{spec,cy}.{js,ts}', supportFile: 'cypress/support/e2e.ts', + setupNodeEvents(on, config) { + on('task', { + getSchema() { + return readFileSync( + resolve(__dirname, '../server/schema.graphql'), + 'utf8' + ); + } + }); + }, }, "videoUploadOnPasses": false, "reporter": "junit", diff --git a/client/cypress/support/commands.ts b/client/cypress/support/commands.ts index 64dac230..e4c08859 100644 --- a/client/cypress/support/commands.ts +++ b/client/cypress/support/commands.ts @@ -67,7 +67,7 @@ declare global { // import 'cypress-graphql-mock'; import mocks from '../fixtures/mocks'; import {addMocksToSchema} from "@graphql-tools/mock"; -import {graphql} from "graphql"; +import {graphql, GraphQLError} from "graphql"; Cypress.Commands.add('apolloLogin', (username, password) => { const payload = { @@ -150,6 +150,29 @@ Cypress.Commands.add('mockGraphql', (options?: any) => { const {operationName, query, variables} = req.body; const rootValue = getRootValue(currentOperations, operationName, variables); + if (!rootValue) { + return req; + } + + if ( + // Additional checks here because of transpilation. + // We will lose instanceof if we are not using specific babel plugin, or using pure TS to compile front-end + rootValue instanceof GraphQLError || + rootValue.constructor === GraphQLError || + rootValue.constructor.name === "GraphQLError" + ) { + return Promise.resolve() + .then( + () => + new Response( + JSON.stringify({ + data: {}, + errors: [rootValue] + }) + ) + ); + } + graphql({ schema: schemaWithMocks, source: query,