meinaart / cypress-plugin-snapshots

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

(bug) cypress-plugin-snapshots errors out in component testing #197

Open rhobot opened 2 years ago

rhobot commented 2 years ago

Describe the bug

Once cypress-plugin-snapshots/commands is imported in cypress/support/index.js, running component tests (i.e. npx cypress open-ct errors out with Cannot find module 'crypto'.

Note that I'm not trying to run cypress-plugin-snapshots in component testing. It just happens to error out.

To Reproduce Steps to reproduce the behavior:

  1. Set up Cypress component testing
  2. Add some example component tests
  3. Run npx cypress open-ct
  4. Click a spec file
  5. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots

nebula

Desktop (please complete the following information):

Additional context

I've attempted to fix the error by adding fallbacks in webpack. I eventually had to add fallbacks of crypto, path, and stream. After that it still complains that process is not defined.

I also searched for disabling cypress-plugin-snapshots only in component testing but I couldn't find a way. The commands are always executed in both integration testing and component testing.

alikirec commented 2 years ago

That's a problem that I ran into when I tried to use webpack (v5) dev configuration. I added buffer package to dev dependencies, then added buffer package in webpack config like following

  plugins: [
    ....
    new webpack.ProvidePlugin({
      process: 'process/browser',
      Buffer: ['buffer', 'Buffer'],
    }),
    ...
  ],
  ...
  node: {
    global: true,
  }

if you don't want to change your dev config, you can use env variables and run component tests like IS_CT=true npx cypress open-ct

talcodota commented 2 years ago

nothing worked for me (running on vite.js), so I've overridden the supportFile location path only for component tests, where I did not import cypress-plugin-snapshots/commands