tgriesser / cypress-graphql-mock

Adds commands for executing a mocked GraphQL server using only the client
171 stars 43 forks source link

Examples using fs.readFileSync #5

Open zhammer opened 5 years ago

zhammer commented 5 years ago

Are there any examples of using this plugin with fs.readFileSync? I'd prefer to read in the graphql schema than import a json introspection query.

zhammer commented 5 years ago

Ah this was my confusion. Didn't realize this was being called in plugins/index.js. Here's my working setup:

// cypress/plugins.index.js
const cucumber = require('cypress-cucumber-preprocessor').default
const fs = require('fs');

const graphQlSchema = fs.readFileSync('schema.graphql', 'utf8');

module.exports = (on, config) => {
  on('file:preprocessor', cucumber())

  config.env.GRAPHQL_SCHEMA = graphQlSchema;
  return config;
}

then in my tests:

// cypress/.../steps.js
beforeEach(() => {
  cy.server();
  cy.mockGraphql({ schema: Cypress.env('GRAPHQL_SCHEMA') });
});
rodrigofd commented 5 years ago

@zhammer why are you using cucumber here for?

zhammer commented 5 years ago

just by chance on my project I'm using https://github.com/TheBrainFamily/cypress-cucumber-preprocessor. But not necessary for this example.