Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting ERROR: Could not resolve "crypto" and ERROR: Could not resolve "fs" when running Test #51

Closed
ayingyong opened this issue Aug 25, 2022 · 7 comments

Comments

@ayingyong
Copy link

Hi. i followed every steps mentioned in here https://github.com/elaichenkov/cy-verify-downloads. However, when running my test. It keep on throwing me these errors. Which part that i'm doing wrong here ?
image

Cypress version: 10.4.0
cy-verify-downloads version: 0.1.8

@elaichenkov
Copy link
Owner

Hey,
Thanks for filling the issue! What's the node version you use? Have you added all the needed code in the cypress/support/e2e.js and in the cypress.config.js? Can you please attach screenshots of these files and the test?

@ayingyong
Copy link
Author

Hey! Sure. here are the information related:
Node version : 14.15.5
cypress/support/e2e.js
image
cypress.config.js
image
Test
image

@elaichenkov
Copy link
Owner

Would you mind sharing the repository that exhibits the issue?

@ayingyong
Copy link
Author

ayingyong commented Sep 5, 2022

@elaichenkov , hi,sorry for late reply. here's the repo for your reference https://github.com/ayingyong/sample-repo-verify-download

@elaichenkov
Copy link
Owner

@elaichenkov , hi,sorry for late reply. here's the repo for your reference https://github.com/ayingyong/sample-repo-verify-download

Thank you! I'll take a look at it today.

@elaichenkov
Copy link
Owner

elaichenkov commented Sep 6, 2022

Hey,
I had a chance to take a look at the repo. I've found the issue, the problem is in the esbuild. So, to solve the problem you have to install @esbuild-plugins/node-modules-polyfill package and then add it to your createBundler function.

Steps:

  1. Install the package
npm i -D @esbuild-plugins/node-modules-polyfill
  1. Update your support/e2e.js file by the following:
const { defineConfig } = require("cypress");
const createBundler = require("@bahmutov/cypress-esbuild-preprocessor");
const addCucumberPreprocessorPlugin =
  require("@badeball/cypress-cucumber-preprocessor").addCucumberPreprocessorPlugin;
const createEsbuildPlugin =
  require("@badeball/cypress-cucumber-preprocessor/esbuild").createEsbuildPlugin;

// import the polyfill
+ const { NodeModulesPolyfillPlugin } = require('@esbuild-plugins/node-modules-polyfill');

module.exports = defineConfig({
  e2e: {
    async setupNodeEvents(on, config) {
      const bundler = createBundler({
-        plugins: [createEsbuildPlugin(config)],
+        plugins: [NodeModulesPolyfillPlugin(), createEsbuildPlugin(config)],
      });

      on("file:preprocessor", bundler);
      await addCucumberPreprocessorPlugin(on, config);

      on('task', { isFileExist, findFiles });

      return config;
    },
    specPattern: "cypress/e2e/features/*.feature",
    baseUrl: "https://demoqa.com/upload-download",
    chromeWebSecurity: false,
  },
});

Hope it helps you. Don't forget to hit the star button for the project.

@ayingyong
Copy link
Author

Hi @elaichenkov , its worked perfectly! thank you so much! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants