meinaart / cypress-plugin-snapshots

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

(bug) The 'task' event has not been registered in the plugins file. You must register it before using cy.task() #123

Open CyrilKrylatov opened 4 years ago

CyrilKrylatov commented 4 years ago

Describe the bug Hi @meinaart,

I have the following error when I'm trying to use cypress-plugin-snapshots:

cy.task('cypress-plugin-snapshot:getFile') failed with the following error:

The 'task' event has not been registered in the plugins file. You must register it before using cy.task()

Fix this in your plugins file here:
false

https://on.cypress.io/api/task

Because this error occurred during a before all hook we are skipping all of the remaining tests.

To Reproduce Steps to reproduce the behavior:

  1. Install cypress-plugin-snapshots
  2. Add to one of my test (show.spec.js):
    it('Compare screenshots', () => {
    cy.get(`[data-cy="screenshot-offers"]`)
      .toMatchImageSnapshot()
    })

Expected behavior I'm expecting to not have this error I guess

Screenshots image

Desktop (please complete the following information):

Additional context Thank you for your support!

adesko commented 4 years ago

@CyrilKrylatov Don't know if you've figured this out already, but i had this issue and looks like the reason was that i had 2 module.exports statements in the plugins/index.js file. So i moved everything to one module.exports statement. This was before:

const { initPlugin } = require('cypress-plugin-snapshots/plugin');

module.exports = (on, config) => {
  initPlugin(on, config);
  return config;
};

module.exports = (on, config) => {
    on('before:browser:launch', (browser = {}, launchOptions) => {
      if (browser.family === 'chromium' && browser.name !== 'electron') {
        launchOptions.args.push('--disable-dev-shm-usage');
      };
      return launchOptions
    });
  };

And this is after:

const { initPlugin } = require('cypress-plugin-snapshots/plugin');

module.exports = (on, config) => {
    on('before:browser:launch', (browser = {}, launchOptions) => {
      if (browser.family === 'chromium' && browser.name !== 'electron') {
        launchOptions.args.push('--disable-dev-shm-usage');
      };
      return launchOptions
    });

    initPlugin(on, config);
    return config;
  };

After doing that, the issue disappeared.

mshamshaddin1 commented 2 years ago

@adesko - Thank you so much, that also worked for me!