Examples using fs.readFileSync
zhammer opened this issue · 3 comments
zhammer commented
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
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') });
});
zhammer commented
just by chance on my project I'm using https://github.com/TheBrainFamily/cypress-cucumber-preprocessor. But not necessary for this example.