meinaart / cypress-plugin-snapshots

Plugin for snapshot tests in Cypress.io
MIT License
498 stars 117 forks source link

Issue when used with cypress-cucumber-preprocessor #106

Closed wawagit closed 4 years ago

wawagit commented 4 years ago

We are writing our specs using cucumber/gherkin syntax (w/h cypress-cucumber-preprocessor plugin). Everything works fine.

When I tried to init the cypress-plugin-snapshots plugin and running my tests I get the following error:

fs.readFileSync is not a function

fs readFileSync is not a function

To Reproduce

Steps to reproduce the behavior:

  1. Add cucumber and snapshots plugins to cypress/plugins/index.js file
  2. Open cypress w/h cypress open command
  3. Run a test feature

My cypress/plugins.index.js file:

const cucumber = require("cypress-cucumber-preprocessor").default;
const { initPlugin } = require("cypress-plugin-snapshots/plugin");

module.exports = (on, config) => {
  on("before:browser:launch", (browser = {}, launchOptions) => {
    if (browser.name === "chrome") {
      launchOptions.args = launchOptions.args.filter(arg => {
        return arg !== "--disable-blink-features=RootLayerScrolling";
      });
      launchOptions.args.push("--disable-gpu");
      launchOptions.args.push(
        "--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process"
      );
      launchOptions.args.push(
        "--load-extension=cypress/extensions/Ignore-X-Frame-headers_v1.1"
      );
      return launchOptions;
    }
  });

  // cypress-cucumber-preprocessor
  on("file:preprocessor", cucumber());

  // cypress-plugin-snapshots
  initPlugin(on, config);

  return config;
};

Expected behavior Be able to write cucumber like specs with working visual regression tests.

Did i set something wrong in my config?

Let me know if i can help to identify the problem. Thanks :)

wawagit commented 4 years ago

I solved the problem by replacing lower case letters with upper case letters for given, when, then as Given, When and Then...

with: import { Given, When, Then } from "cypress-cucumber-preprocessor/steps";

instead of: const {given, when, then} = require('cypress-cucumber-preprocessor');

The lower case version was working well before installing cypress-plugin-snapshots so it's a bit strange but it works fine now.

hope this help someone ;)