cypress icon indicating copy to clipboard operation
cypress copied to clipboard

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

Open dominikkurbiel opened this issue 9 months ago • 4 comments

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

dominikkurbiel avatar May 17 '24 16:05 dominikkurbiel

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

jennifer-shehane avatar May 20 '24 14:05 jennifer-shehane

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

dominikkurbiel avatar May 20 '24 16:05 dominikkurbiel