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

TypeError: generateLogin is not a function #5

Open
t6tv8e opened this issue Sep 25, 2023 · 9 comments
Open

TypeError: generateLogin is not a function #5

t6tv8e opened this issue Sep 25, 2023 · 9 comments

Comments

@t6tv8e
Copy link

t6tv8e commented Sep 25, 2023

When following the README, [email protected] throws a TypeError.

Your configFile is invalid: /Users/.../.../cypress.config.ts

My cypress.config.ts:

import generateLogin from "@intility/cypress-msal";

let publicClientConfig = {
  auth: {
    clientId: "***",
    authority: "https://login.microsoftonline.com/***",
  },
};

let requests = [
  {
    scopes: ["User.Read"],
  },
];

let login = generateLogin(publicClientConfig, requests);

export default defineConfig({
  reporter: "junit",

  reporterOptions: {
    mochaFile: "reports/cypress.xml",
    toConsole: true,
  },

  component: {
    devServer: {
      framework: "react",
      bundler: "vite",
    },
  },

  e2e: {
    baseUrl: "https://localhost:3000",
    setupNodeEvents(on, config) {
      // `on` is used to hook into various events Cypress emits
      on("task", {
        // register a task named login which calls the generated login from @intility/cypress-msal
        login,
      });
    },
  },
});
@t6tv8e
Copy link
Author

t6tv8e commented Oct 26, 2023

...

@h3rmanj
Copy link
Member

h3rmanj commented Oct 26, 2023

Hi! This fell through the cracks, sorry. We did some work back in February to ensure this package worked with cypress v10. I'm surprised seeing it at v13 already, and we haven't kept up internally. I will try to see if I can find some time to debug this, but I can't promise anything.

I'm also not sure if this works with the newest versions of @azure/msal-browser, as it relies on some internal stuff that might have changed.

In the meantime if you want to debug further yourself you could try to copy the two files from src/ into your project and see if you get some more info on why it doesn't work.

@h3rmanj
Copy link
Member

h3rmanj commented Nov 23, 2023

I just ran into this myself actually. Some weirdness going on with the modules/commonjs and import/require. I had to import it like this to resolve it:

import generateLoginRaw from '@intility/cypress-msal'
import keyVaultCacheRaw from '@intility/msal-keyvault-cache'

const generateLogin =
  'default' in generateLoginRaw &&
  typeof generateLoginRaw?.default === 'function'
    ? generateLoginRaw.default
    : generateLoginRaw

const keyVaultCache =
  'default' in keyVaultCacheRaw &&
  typeof keyVaultCacheRaw?.default === 'function'
    ? keyVaultCacheRaw.default
    : keyVaultCacheRaw

Next time I update this package, I think I will change it to output es modules instead of commonjs. Although that will be a breaking change and I'm not sure when I'll have time to do that.

@chriseugenerodriguez
Copy link

chriseugenerodriguez commented Feb 29, 2024

This doesn't work for me.

const login =
> 19 |   'default' in generateLoginRaw &&
     |             ^
  20 |   typeof generateLoginRaw?.default === 'function'
  21 |     ? generateLoginRaw.default
  22 |     : generateLoginRaw;
  23 |   

TypeError: Cannot use 'in' operator to search for 'default' in undefined

@dtvn-dung-nguyen
Copy link

This doesn't work for me.

const login =
> 19 |   'default' in generateLoginRaw &&
     |             ^
  20 |   typeof generateLoginRaw?.default === 'function'
  21 |     ? generateLoginRaw.default
  22 |     : generateLoginRaw;
  23 |   

TypeError: Cannot use 'in' operator to search for 'default' in undefined

I got same problem , help me pls . I'm gonna be lay-off

@chriseugenerodriguez
Copy link

chriseugenerodriguez commented Mar 7, 2024

I decided not to use the library but create a test user in AD, and follow the cypress doc about Azure login.

https://docs.cypress.io/guides/end-to-end-testing/azure-active-directory-authentication

create a test user in AD, and use that as credentials.

@dtvn-dung-nguyen
Copy link

dtvn-dung-nguyen commented Mar 7, 2024

I decided not to use library but create test user in AD, and just follow cypress doc about azure login.

Do you have solution yet ?

@dtvn-dung-nguyen
Copy link

i did this way but it not solve my problem in project

@h3rmanj
Copy link
Member

h3rmanj commented Mar 7, 2024

Since there is an official guide, I'm considering deprecating this package, as we've moved away from cypress. There might be cases with conditional access that wouldn't work though. Those would still would need ROPC flow, or then more preferably, Device Code flow, which this library has been aimed at.

Since I'm not actively in-the-loop of how the newest cypress works, I'd gladly take some help getting this to support the current version(s), if anyone is in need of this. The flow of the package itself is pretty straight forward:

  • Login in a node env with @azure/msal-node
  • Extract the cache
  • Inject the cache in the session or local storage

But how to do each step with cypress seem to change every other week.

They have a sample with ROPC flow and Playwright for reference in the msal repo https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/samples/msal-browser-samples/TestingSample/test/browser-test.spec.ts

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

4 participants