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

Cypress.require() fails to load modules without default export in cy.origin() context since version 12.17.4 #29535

Open
dominikkurbiel opened this issue May 17, 2024 · 2 comments
Labels
stage: needs investigating Someone from Cypress needs to look at this v 12.17.4 🐛

Comments

@dominikkurbiel
Copy link

dominikkurbiel commented May 17, 2024

Current behavior

Since Cypress version 12.17.4, I have encountered issues using Cypress.require() in tests that previously worked correctly in version 12.17.3. These issues relate to importing modules that do not have a default export.

In my project, I use Cypress to test an application that requires Steam login. To generate authentication codes, I use the steam-totp library.

In my tests, I use cy.origin() to handle logging into the external Steam site, and within this context, I use Cypress.require() to load the steam-totp library.
After updating to version 12.17.4, the tests began to throw an error. This issue only occurs for modules that do not have a default export.
image

Below are two simplified examples that illustrate the difference:

Code Example That Does Not Work:

Cypress.Commands.add('steamLogin', () => {
  cy.origin(
    'https://steamcommunity.com',
    () => {
      const SteamTotp = Cypress.require('steam-totp');
    }
  );
});

Code Example That Works:

Cypress.Commands.add('steamLogin', () => {
  cy.origin(
    'https://steamcommunity.com',
    () => {
      const dateFns = Cypress.require('date-fns');
    }
  );
});

This is my cypress.config.ts

export default defineConfig({
  chromeWebSecurity: false,
  fixturesFolder: './tests/cypress/fixtures',
  downloadsFolder: './tests/cypress/downloads',
  supportFolder: './tests/cypress/support',
  experimentalMemoryManagement: true,
  numTestsKeptInMemory: 50,
  e2e: {
    supportFile: './tests/cypress/support/e2e.ts',
    specPattern: './tests/cypress/e2e/**/*.cy.{jx,jx,ts,tsx}',
    defaultCommandTimeout: 30000,
    experimentalOriginDependencies: true,
    experimentalRunAllSpecs: true,
    experimentalMemoryManagement: true,
    experimentalWebKitSupport: true,
    watchForFileChanges: false,
    numTestsKeptInMemory: 2,
    scrollBehavior: 'center',
    viewportHeight: 1080,
    viewportWidth: 1700,
  },
  component: {
    devServer: {
      framework: 'next',
      bundler: 'webpack',
    },
  },
})

Desired behavior

No response

Test code to reproduce

Code Example That Does Not Work:

Cypress.Commands.add('steamLogin', () => {
  cy.origin(
    'https://steamcommunity.com',
    () => {
      const SteamTotp = Cypress.require('steam-totp');
    }
  );
});

Code Example That Works:

Cypress.Commands.add('steamLogin', () => {
  cy.origin(
    'https://steamcommunity.com',
    () => {
      const dateFns = Cypress.require('date-fns');
    }
  );
});

Cypress Version

12.17.4

Node version

18.17.0

Operating System

macos 14.3

Debug Logs

No response

Other

No response

@jennifer-shehane
Copy link
Member

@dominikkurbiel Have you also tried the latest Cypress release? To ensure this hasn't been fixed since then?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label May 20, 2024
@dominikkurbiel
Copy link
Author

Yes, I started with the newest version and downgrading it version by version and ended up on 12.17.3 where is started working. So 12.17.4 is the first version with the problem and all above behave the same

@jennifer-shehane jennifer-shehane added v 12.17.4 🐛 stage: needs investigating Someone from Cypress needs to look at this and removed stage: needs information Not enough info to reproduce the issue labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this v 12.17.4 🐛
Projects
None yet
Development

No branches or pull requests

2 participants